Several steps to create and invoke local notifications
1, create a local notification
2, set processing time
3, set the notification body
4, you can set the passed parameters UserInfo
5, call notification
-(BOOL) Application: (UIApplication *) application didfinishlaunchingwithoptions: (Nsdictionary *) launchOptions {
Self.window = [[UIWindow alloc]initwithframe:[uiscreen mainscreen].bounds];
Self.window.backgroundColor = [Uicolor colorwithred:249/255.0 green:249/255.0 blue:249/255.0 alpha:1];
[[Uinavigationbar appearance] Setbartintcolor:[uicolor colorwithred:23/255.0 green:180/255.0 blue:237/255.0 alpha:1] ];
[[Uinavigationbar appearance] setbarstyle:uibarstyleblack];
Viewcontroller *viewcontroller = [[Viewcontroller alloc]init];
Self.window.rootViewController = Viewcontroller;
[Self.window makekeyandvisible];
if ([[uiapplication sharedapplication]currentusernotificationsettings].types! = Uiusernotificationtypenone) {
[Self addlocalnotification];
}else{
[[UIApplication sharedapplication]registerusernotificationsettings:[uiusernotificationsettings SettingsForTypes: Uiusernotificationtypealert| uiusernotificationtypebadge| Uiusernotificationtypesound Categories:nil]];
}
Override point for customization after application launch.
return YES;
}
-(void) Application: (UIApplication *) application didregisterusernotificationsettings: (Uiusernotificationsettings * ) notificationsettings
{
if (notificationsettings! = Uiusernotificationtypenone) {
[Self addlocalnotification];
}
}
-(void) addlocalnotification{
Uilocalnotification *notification = [[Uilocalnotification alloc]init];
Notification.firedate = [NSDate datewithtimeintervalsincenow:2.0];
Notification.repeatinterval = 2;
Notification.alertbody = @ "It's time to go to bed Oh!" ~~";
Notification.applicationiconbadgenumber = 2;
Notification.alertaction = @ "Open app";
Notification.alertlaunchimage = @ "Default";
Notification.soundname = @ "MSG.CAF";
Notification.userinfo = @{@ "id": @1,@ "name": @ "DSN"};
[[UIApplication sharedapplication]schedulelocalnotification:notification];
}
-(void) Applicationwillenterforeground: (uiapplication *) Application {
[[UIApplication sharedapplication]setapplicationiconbadgenumber:0];
Called as part of the transition from the background to the inactive state; Here's can undo many of the changes made on entering the background.
}
iOS Learning note 31-local notifications