应用关闭时如何处理推送有效载荷? [英] how to handle push payload when the app closed?
本文介绍了应用关闭时如何处理推送有效载荷?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在通过以下内容将推送有效载荷发送给我的用户:
i am sending push payload to my users with the follow content :
{"aps": {"alert": "Go To Google", "sound": "Default","url":"http://www.google.com"}}
当pp运行但在后台运行时,一切都很好.如果我收到推送,但应用程序已关闭,则我将其打开,没有任何反应.我正在尝试重定向到有效负载中的此URL.再次从后台运行应用程序时,效果很好.
everything goes well when the pp is running but in the background. if i am receiving the push and the app is closed i am open it and nothing happen. i am trying to redirect to this url in the payload. again when the app is running from the background it goes well.
到目前为止,这是AppDelegate.m的实现:
this is the implementation so far AppDelegate.m:
-(void)Redirect:(NSString*)url{
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:url]];
NSLog(@"%@",url);
}
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
RedirectedUri = [[userInfo objectForKey:@"aps"] objectForKey:@"url"];
NSLog(@"%@",RedirectedUri);
[self Redirect:RedirectedUri];
}
请需要一些帮助.
推荐答案
此外,将以下内容添加到您的代码中:
Additionally, add the following to your code:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[self applicationDidFinishLaunching:application];
if (launchOptions != nil)
{
NSDictionary* dictionary = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];
if (dictionary != nil)
{
RedirectedUri = [[dictionary objectForKey:@"aps"] objectForKey:@"url"];
[self Redirect:RedirectedUri];
}
}
return YES;
}
这篇关于应用关闭时如何处理推送有效载荷?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文