iOS8 above remote Push demo

Source: Internet
Author: User


-(BOOL) Application: (uiapplication *) application didfinishlaunchingwithoptions: ( Nsdictionary *) launchoptions

{

self. Window = [[uiwindow alloc] initwithframe: [[uiscreen mainscreen] bounds]];

//Override point for customization after application launch.

// sign up for push notifications

[[UIApplication sharedapplication]registerforremotenotificationtypes: (Uiremotenotificationtypealert | Uiremotenotificationtypebadge | Uiremotenotificationtypesound)];

//

if ([[[[ uidevice currentdevice] systemversion] floatvalue ] >= 8.0) {

[ [uiapplication sharedapplication] registerusernotificationsettings: [ Uiusernotificationsettings

settingsfortypes:(uiusernotificationtypesound |

Uiusernotificationtypealert |

Uiusernotificationtypebadge)

categories:nil]];

[[uiapplication sharedapplication] registerforremotenotifications];

}

Else {

[[uiapplication sharedapplication]registerforremotenotificationtypes: Uiremotenotificationtypealert|

Uiremotenotificationtypebadge|

Uiremotenotificationtypesound];

}


if (launchoptions) {

//Uiapplicationlaunchoptionsremotenotificationkey This key value is the message of the push

nsdictionary *dic = [launchoptions objectforkey:uiapplicationlaunchoptionsremotenotific Ationkey];

//in order to reuse the code, unify to the following processing method Handlepushnotify:

[ self handlepushnotify:d ic frombuld:_          ispushfromclosed]; // If the program does not start, click the push message into the program, you need to do some processing according to the push message , such as: view switch.

}


// registered remote Push, successful proxy method

-(void) Application: (uiapplication *) application Didregisterforremotenotificationswithdevicetoken: (nsdata *) devicetoken{

// The token returned by the Apple server (the unique number used by the Apple server to identify the phone)

// can be handed to the backstage, and then the backend needs to send this to the remote push when the token is used directly

nsstring *tokenstr = [devicetoken description];

NSLog (@ "token:%@", TOKENSTR);

}


// registered remote push failed

-(void) Application: (uiapplication *) application Didfailtoregisterforremotenotificationswitherror: (nserror *) error

{

NSLog (@ " registration push failed %@", error);

}


// when the program is running, click on the method that pushes the message.

-(void) Application: (uiapplication *) application didreceiveremotenotification: ( Nsdictionary *) userInfo

{

// Here you can do some actions based on push information

[ self handlepushnotify: userInfo frombuld:_ispushfromopen ];

}


-(void) Handlepushnotify: (nsdictionary *) dic frombuld: (nsstring *) buld

{

Judging by the buld where the value came from

/*

DIC = {

APS = {

Alert = "\u627e\u5927\u592b\u63d0\u793a\uff1ahdf21\u7528\u6237\u7533\u8bf7\u52a0\u5165\u60a8\u7684\u5c0f\u680b\ U5708\u5708\u5b50 ";

Sound = default;

target = {

"Param_list" = (

{

"Param_name" = "circle_id";

"Param_value" = 2204;

},

{

"Param_name" = "circle_name";

"Param_value" = "\u5c0f\u680b\u5708";

},

{

"Param_name" = type;

"Param_value" = 1;

}

);

ToPage = "/gooddoc/server/index.php/circle/getcirclemembersnews";

};

};

*/

}


This article is from the "8594233" blog, please be sure to keep this source http://8604233.blog.51cto.com/8594233/1576178

iOS8 above remote Push demo

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.