IOS10 pushes the new usernotifications Framework, which is actually very simple to use.
Just click on the notification bar on the iOS10 above system, the callback method will not go the original two methods
-(void) Application: (UIApplication *) application didreceiveremotenotification: (Nsdictionary *) UserInfo {}-(void) Application: (UIApplication *) application didreceiveremotenotification: ( Nsdictionary *) UserInfo Fetchcompletionhandler: (void (^) (Uibackgroundfetchresult)) Completionhandler { }
But the callback at the front desk.
-(void) Usernotificationcenter: (unusernotificationcenter *) Center willpresentnotification: ( Unnotification *) Notification Withcompletionhandler: (void (^) (unnotificationpresentationoptions)) Completionhandler
callback when entering from the background
-(void) Usernotificationcenter: (unusernotificationcenter *) Center Didreceivenotificationresponse: ( Unnotificationresponse *) Response Withcompletionhandler: (void (^) ()) Completionhandler
Just say how to use it:
1, Import header file
#import <UserNotifications/UserNotifications.h>
2, Registration notice
#define IOS8 ([[Uidevice currentdevice].systemversion Doublevalue] >= 8.0 && [[Uidevice Currentdevice]. Systemversion Doublevalue] < 9.0)#define ios8_10 ([[[[Uidevice Currentdevice] systemversion] floatvalue] >= 8.0 && [[Uidevice currentdevice].systemversion Doublevalue] < 10.0)#define IOS10 ([[[Uidevice] Currentdevice] systemversion] floatvalue] >= 10.0)
-(BOOL) Application: (UIApplication *) application didfinishlaunchingwithoptions: (Nsdictionary *) LaunchOptions method
If(IOS10) {Unusernotificationcenter *center =[Unusernotificationcenter Currentnotificationcenter]; Center.Delegate =Self [Center requestauthorizationwithoptions: (Unauthorizationoptionbadge | Unauthorizationoptionsound | Unauthorizationoptionalert) completionhandler:^ (BOOL Granted, Nserror *_nullable error) {if (!error) {NSLog (@ "succeeded!") ); } }]; } Else if (ios8_10) {//ios8-ios10 uiusernotificationsettings *settings = [uiusernotificationsettings Settingsfortypes: (Uiusernotificationtypebadge | Uiusernotificationtypealert | uiusernotificationtypesound) Categories:nil]; [Application registerusernotificationsettings:settings]; [Application registerforremotenotifications]; } Else {//IOS8 below [application Registerforremotenotificationtypes:uiremotenotificationtypebadge | Uiremotenotificationtypealert | Uiremotenotificationtypesound]; }
3, callback method, get notification data (the foreground is similar to do not do description)
-(void) Usernotificationcenter: (unusernotificationcenter *) Center Didreceivenotificationresponse: ( Unnotificationresponse *) Response Withcompletionhandler: (void (^) ()) Completionhandler { * UserInfo = Response.notification.request.content.userInfo; Message processing}
4, no changes to local notifications will still be callback
-(void) Application: (UIApplication *) application didreceivelocalnotification: (Uilocalnotification *) Notification
IOS10 Push Notification adaptation