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
[[uiapplicationsharedapplication]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 = [[UialertviewAlloc]Initwithtitle:NilMessage:[NSStringstringWithFormat:@ "devicetoken:%@", Devicetoken]Delegate: SelfCancelbuttontitle:NilOtherbuttontitles:@"Determine",Nil];
[Alertshow];
}
// registered 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 =
[[uialertviewalloc] initwithtitle:@ " warm tips "
message:@ " push success!" "
delegate:Nil
cancelbuttontitle:@ " OK "
otherbuttontitles:nil];
[Alertshow];
}