The premise is that the PUSH Service has been started for the certificate during debugging or publishing.
1. register the remote Notification Type
Uiremotenotificationtype apn_type = (uiremotenotificationtype) (uiremotenotificationtypealert | uiremotenotiftypetypesound |Uiremotenotificationtypebadge); [[uiapplication sharedapplication] registerforremotenotificationtypes: apn_type];
2. Delegation method for implementing appdelegate
-( Void ) Application :( uiapplication *) Application didregisterforremotenotificationswithdevicetoken :( nsdata * ) Devicetoken {nsstring * Token = [[devicetoken description] stringbytrimmingcharactersinset: [nscharacterset charactersetwithcharactersinstring: @" <> " ]; Self. devicetoken = [Token stringbyreplacingoccurrencesofstring: @" " Withstring: @"" ]; Nslog ( @" Devicetoken: % @ " , Self. devicetoken ); // You can send the devicetoken to your server. }
Callback for failed Retrieval
-(Void) Application :( uiapplication *) Application didfailtoregisterforremotenotificationswitherror :( nserror *) Error {nslog (@"Didfailtoregisterforremotenotificationswitherror: % @", [Error localizeddescription]);}
Receive remote notification
-(Void) Application :( uiapplication *) Application didreceiveremotenotification :( nsdictionary *) Userinfo {nslog (@"Receive remote notification: % @", Userinfo );}