Push notification get device token

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.