About the response issues with iOS Push notification

Source: Internet
Author: User

Recently in the push message encountered a problem, that is, when the program is running in the background, when the push message received, click on the app icon can not get this message, has not been resolved, if there is a way to solve the friend, forget the generous enlighten.a brief summary of the corresponding situation of the push message1. When a push message is received when the program is turned off, clicking on the icon calls-(BOOL) Application: (UIApplication *) application didfinishlaunchingwithoptions: ( Nsdictionary *) Launchoptions This method, then the message is obtained by launchoptions this parameter.

2. When the program is in the foreground, when the message is pushed, it will be called-(void) Application: (UIApplication *) application

Didreceiveremotenotification: (nsdictionary *) UserInfo This method

3. When the program is running in the background, if you receive a message push, if you click on the message or click on the message icon, you will also be called-(void) application: (uiapplication*) application

Didreceiveremotenotification: (nsdictionary *) UserInfo This method

4. When the program is running in the background, if you receive a message push, if you click on the Desktop app icon, the Didfinishlaunchingwithoptions and Didreceiveremotenotification methods will not be called, so you cannot get the message

Here are the responses for the above 4 scenarios:

First case:

if (launchoptions) {

nsdictionary* Pushnotificationkey = [Launchoptionsobjectforkey:uiapplicationlaunchoptionsremotenotificationkey];

if (Pushnotificationkey) {

Define your own way of handling this.

}

}

Second to third case:

if (application.applicationstate = = uiapplicationstateactive) {

The second case

if ([[UserInfo objectforkey:@ "APS"] objectforkey:@ "alert"]!=null) {

[Wlhelper showalert:@ "push message" Msg:[[userinfo objectforkey:@ "APS"] objectforkey:@ "alert"];

}

} else {

The third case

define your own way of handling this.

}

Fourth case:

You're not going to get it.

Because if the app goes backstage when the push comes in, it's already in the callback.

-(void) Application: (UIApplication *) application
Didreceiveremotenotification: (nsdictionary *) userInfo

You can directly in this callback to deal with the effect you want, or you get a variable, push the data saved, in the background of the program to enter the foreground to add a judge to do the effect you want

Of course it's best to use the first one, because when you push it, you push it over (and you haven't verified the fourth method, friends are working on it)

About the response issues with iOS Push notification

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.