我正在向我的用户发送推送有效负载,其中包含以下内容:
{"aps": {"alert": "Go To Google", "sound": "Default","url":"http://www.google.com"}}
当pp正在运行但在后台时,一切顺利。
如果我收到推送并且应用程序已关闭,我打开它并且没有任何反应。
我正在尝试重定向到有效负载中的此URL。
当应用程序从后台运行时它再次运行良好。
这是到目前为止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];
}
需要一些帮助。
答案 0 :(得分:10)
此外,将以下内容添加到您的代码中:
- (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;
}