如何处理推载荷当应用程序关闭?(how to handle push payload when th

2019-09-18 00:58发布

我发送有效载荷推到我的用户与后续的内容:

{"aps": {"alert": "Go To Google", "sound": "Default","url":"http://www.google.com"}}

一切顺利的话,当PP正在运行,但在后台。 如果我收到的推动和应用程序被关闭我打开它,并没有发生。 我试图重定向到该网址的有效载荷。 再次,当应用程序从后台运行一切顺利。

这是实施至今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];    
  }

需要一些帮助,请。

Answer 1:

此外,添加以下代码:

- (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;
}


文章来源: how to handle push payload when the app closed?