#import "AppDelegate.h"
@interface appdelegate ()
@end
@implementation appdelegate
This method is called whenever a notification is received, regardless of whether the program is running in the front background
-(void) Application: (uiapplication *) application didreceivelocalnotification: ( Uilocalnotification *) notification
{
NSLog(@ "%@", notification);
// Add a control to receive the displayed information
UILabel *label=[[UILabel alloc]initwithframe:cgrectmake( (+- )];
Label. backgroundcolor=[uicolor graycolor];
Label. text=[nsstring stringwithformat:@ "%@", notification];
[self. Window. Rootviewcontroller. View addsubview: label];
}
-(BOOL) Application: (uiapplication *) application didfinishlaunchingwithoptions: (nsdictionary *) launchoptions {
//Override point for customization after application launch.
uilocalnotification *info=launchoptions[uiapplicationlaunchoptionslocalnotificationkey];
if (info) {
UILabel *label = [[UILabel alloc]initwithframe:cgrectmake(0, 0, + )];
Label. backgroundcolor = [uicolor orangecolor];
[self. Window. Rootviewcontroller. View addsubview: label];
// Remove carrying information
Label. numberoflines = 0;
//nsdictionary *dict = info[@ "Uiconcretelocalnotification"];
//Nsarray *keys = [info AllKeys];
//for (NSString *str in keys) {
//Label.text = [NSString stringwithformat:@ "%@", str];
//}
//nsdictionary *dict1 = dict[@ "user info"];
Label. text = [nsstring stringwithformat:@ "%@", info. UserInfo];
// jump to the corresponding interface
}
return YES;
}
@end
#import "ViewController.h"
@interface viewcontroller ()
@end
@implementation Viewcontroller
-(void) viewdidload {
[Super viewdidload];
What you need to register a notification type after//ios8 ( sound , icon text , text ) information
/*
Uiusernotificationtypenone = 0,
Uiusernotificationtypebadge = 1 << 0, including icon text 0001
Uiusernotificationtypesound = 1 << 1,// sound 0010
Uiusernotificationtypealert = 1 << 2,// subject Content 0100
*/
uiusernotificationsettings *setting=[uiusernotificationsettings settingsfortypes: Uiusernotificationtypebadge| Uiusernotificationtypesound Categories:nil];
// registration Notice
[[uiapplication sharedapplication]registerusernotificationsettings: setting];
}
-(void) Touchesbegan: (nsset *) touches withevent: (uievent *) event
{
// Create local notifications
uilocalnotification *local=[[uilocalnotification alloc]init];
Local. alertbody=@ " old Yi : Why are you so angry ?" ;
Local. firedate=[nsdate datewithtimeintervalsincenow:3];
Local. soundname=uilocalnotificationdefaultsoundname;
Local. alertaction=@ " approx ";
Local. applicationiconbadgenumber=5;
Local. userInfo=@{@ "name":@ " Big Easy "@ "age":@ "@"};
// custom notifications
[[uiapplication sharedapplication]schedulelocalnotification: local];
Send Notifications now
[[UIApplication sharedapplication]presentlocalnotificationnow:local];
Cancel all local notifications
[[UIApplication sharedapplication]cancelalllocalnotifications];
/*
timer-based scheduling Custom specific time to issue notifications
@property (nonatomic,copy) nsdate *firedate; Trigger time
@property (nonatomic,copy) Nstimezone *timezone; Time Zone
@property (nonatomic) Nscalendarunit repeatinterval; repeat interval //0 means don ' t repeat
@property (nonatomic,copy) Nscalendar *repeatcalendar; Repeat Interval
@property (nonatomic,copy) clregion *region Ns_available_ios (8_0);// area
@property (nonatomic,assign) BOOL regiontriggersonce Ns_available_ios (8_0); determines a bool value for a zone
Alerts
@property (nonatomic,copy) NSString *alertbody; Topics for Reminders
@property (nonatomic) BOOL hasaction; No does not show sliding unlocked button instead of display
@property (nonatomic,copy) NSString *alertaction; Slide the unlocked text
@property (nonatomic,copy) NSString *alertlaunchimage; Click the Start program's boot image for the notification banner
@property (nonatomic,copy) nsstring title text for *alerttitle tips
Sound default : Uilocalnotificationdefaultsoundname
@property (nonatomic,copy) NSString *soundname;
Badge
@property (nonatomic) Nsinteger applicationiconbadgenumber; icon Text
User Info
@property (nonatomic,copy) nsdictionary *userinfo; user-specified carrying parameters
[Uiusernotificationsettings settingsforusernotificationtypes:usernotificationactionsettings:]
@property (nonatomic, copy) NSString *category Ns_available_ios (8_0); category
*/
}
@end
iOS local push