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:[NSString stringWithFormat:@ "devicetoken:%@", Devicetoken]Delegate: Self Cancelbuttontitle:Nil Otherbuttontitles:@"Determine", Nil];
[Alert show];
}
// 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 =
[[uialertview alloc] initwithtitle:@ " warm tips "
message:@ " push success!" "
delegate:Nil
cancelbuttontitle:@ " OK "
otherbuttontitles:nil];
[Alert show];
}
IOS push to get mobile device Devicetoken