1 How to generate a local push
Uilocalnotification *localnotification = [[Uilocalnotification alloc]init];
//When receiving notification, the audio file played
Localnotification.soundname = @ "Shake.wav";
//Notification send time
Localnotification.firedate = [NSDate datewithtimeintervalsincenow:5];
//preferably with a time zone for the supplement to Firedate
Localnotification.timezone = [Nstimezone defaulttimezone];
//content of the notification
Localnotification.alertbody = @ "Content of the notification";
//Lock screen display of notification content, gray fine print
Localnotification.alertaction = @ "Notification content 2 (on lock screen)";
//Click Notifications to open the app, load the boot picture, only the app's boot picture
Localnotification.alertlaunchimage = @ "Default";
//The number displayed in the upper-right corner of the icon after receiving notification
Localnotification.applicationiconbadgenumber = 20;
additional information for the//notification, dictionary type
Localnotification.userinfo = @{
@ "Dictkey": @ "userinfo Details",
@ "DictKey2": @ "userinfo details 2"
};
//Enable notifications, follow the settings above, send a notification 5 seconds after the above setting, that is, code execution to this line, and then 5 seconds to send the notification
[[UIApplication sharedapplication] schedulelocalnotification:localnotification];
//Send notifications immediately, which means that firedate and timezone above are not useful.
The meaning of the following code is that when the program is running in the background, the notification is sent immediately
//[[UIApplication sharedapplication] presentlocalnotificationnow:localnotification];
2 Notification callback method, 2 methods in APPDELEGATE.M
-(void) Application: (UIApplication *) application didreceivelocalnotification: (uilocalnotification *) notification;
-(BOOL) Application: (UIApplication *) application didfinishlaunchingwithoptions: (Nsdictionary *) launchOptions;
2.1 The 1th callback method is called when the program is not killed when it receives a notification:
If the program is in the foreground, the method will callback, there will be no banner hint;
/*
If you want the program to be in the foreground, do not prompt the user, you can add the program running state judgment application.applicationstate = = uiapplicationstateactive),
The state changes from the background to the foreground are the following, if the foreground is to the background, the reverse:
Uiapplicationstatebackground (Backstage)-uiapplicationstateinactive (not activated, all UI interfaces cannot receive user clicks at this time) Uiapplicationstateactive (Active)
*/
If the program is in the background, the method will callback with a banner hint.
1 -(void) Application: (UIApplication *) application didreceivelocalnotification: ( Uilocalnotification *) notification2{3 ifreturn; 4 @" when the notification is received, the program is still alive (foreground \ Background is counted), will callback this method " ; 5 }
2.2 The 2nd callback method is called when a notification is received, the program has been killed, in fact, this method inClick the app icon to startWhen, orClick Banner NotificationsWhen.
So in the process of notification, you need to determine whether the program is clicked on the application icon to start , or click on the banner notification started
1-(BOOL) Application: (UIApplication *) application didfinishlaunchingwithoptions: (Nsdictionary *) Launchoptions2 {3Uilocalnotification *note =Launchoptions[uiapplicationlaunchoptionslocalnotificationkey];4 5 if(note) {6Self.label.text =@"Click on the banner notification to launch the program";7}Else{8Self.label.text =@"Click the app icon to start the program";9 }Ten One returnYES; A}
IOS Local push