uilocalnotification
There are times when we need to deal with some local push and small details.
//judged that he was not active in the foreground before sending the push if ([UIApplication sharedapplication].applicationstate,!= uiapplicationstateactive) {//local push uilocalnotification *localnotification = [[Uilo
Calnotification alloc] init]; Localnotification.alertbody = @ "You just finished a trip, go and see the score."
"; Localnotification.alertaction = @ "You just finished a trip, go and see the score."
";
Localnotification.applicationiconbadgenumber = 1;
Localnotification.soundname = Uilocalnotificationdefaultsoundname;
NSString * Tripid = [nsstring stringwithformat:@ '%ld ', (long) ((Trip *) extras). Starttimestamp];
Localnotification.userinfo = @{@ "Tripid": Tripid};
[[UIApplication sharedapplication] presentlocalnotificationnow:localnotification];
NSLog (@ "T_trip_finished has sent push success%@-" userinfo%@ ", extras,localnotification.userinfo); }
Please do not forget to set the notification type and voice number prompts, as well as authorization. And do not forget when the click is not pushed to the null situation to exclude
Uiusernotificationsettings *setting = [Uiusernotificationsettings Settingsfortypes:uiusernotificationtypebadge | Uiusernotificationtypesound | Uiusernotificationtypealert Categories:nil];
Authorization Notice
[[uiapplication sharedapplication] registerusernotificationsettings:setting];
Notice jump, app by clicking on the top push to start app, get push, if not NULL, execute push method
uilocalnotification* localnotification = [launchoptions Objectforkey:uiapplicationlaunchoptionslocalnotificationkey];
if (localnotification) {//If the notification is not empty, click the Push startup app
[self checkNotification:localNotification.userInfo islaunch:yes] ;
}
-(void) Checknotification: (nsdictionary *) userInfo islaunch: (BOOL) islaunch{
//judge whether the data carried by the notification exists if
(tripid && tripid.length > 0) {
if (islaunch) {
//Click Notification Launch app, jump to the interface corresponding to the notification
}else{
//Click Notice to reactivate the app, Jump to the corresponding interface
}
And of course we need to change the number of red dots. Display and hide don't forget.
-(void) Applicationdidenterbackground: (uiapplication *) application {
[[uiapplication sharedapplication] SETAPPLICATIONICONBADGENUMBER:0];
}
-(void) Applicationwillenterforeground: (uiapplication *) application {
//Set the number in the upper-right corner of the application picture (if you want to cancel the number in the upper right corner, Direct the value of this parameter to 0
[[uiapplication sharedapplication] setapplicationiconbadgenumber:0];
}