4

我正在向我的用户发送推送有效负载,其中包含以下内容:

{"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];    
  }

需要一些帮助。

4

1 回答 1

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;
}
于 2012-06-11T11:49:00.467 回答