First step: Apply for a certificate:
The second step: Apply for App IDs, the application name must be consistent. Then go to edit to make it enable, green.
Step three: Apply provisioning profile, generate. mobileprovision, double-click the certificate to import the phone device correctly, not to drag.
Fourth step: Create the app so that it has the same name.
Fifth Step: Write code
-(BOOL) Application: (UIApplication *) application didfinishlaunchingwithoptions: (nsdictionary *) launchOptions
{
Override point for customization after application launch.
return YES;
Uiremotenotificationtype types =
(Uiremotenotificationtypebadge
| Uiremotenotificationtypesound
| Uiremotenotificationtypealert);
Register message push
[[UIApplication sharedapplication]registerforremotenotificationtypes:types];
return YES;
}
Get Devicetoken Success
-(void) Application: (UIApplication *) application
Didregisterforremotenotificationswithdevicetoken: (NSData *) Devicetoken
{
NSLog (@ "Devicetoken: {%@}", Devicetoken);
The operation here is to send device token to the server
Uialertview * alert = [[Uialertview alloc]initwithtitle:nil message:[nsstringstringwithformat:@ "DeviceToken:%@", Devicetoken] delegate:self cancelbuttontitle:nil otherbuttontitles:@ "OK", nil];
[Alert show];
}
Registration Message Push failed
-(void) Application: (UIApplication *) application
Didfailtoregisterforremotenotificationswitherror: (Nserror *) error
{
NSLog (@ "Register Remote notifications error:{%@}", error);
NSLog (@ "Register Remote notifications error:{%@}", error.localizeddescription);
}
Handling received message pushes
-(void) Application: (UIApplication *) application
Didreceiveremotenotification: (nsdictionary *) userInfo
{
NSLog (@ "Receive Remote notification:%@", userInfo);
Uialertview *alert =
[[Uialertview alloc] initwithtitle:@ "Warm Tips"
message:@ "Push success! "
Delegate:nil
cancelbuttontitle:@ "OK"
Otherbuttontitles:nil];
[Alert show];
}
Push notification get device token