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