【问题标题】:UrbanAirship Push with URL on IOSUrbanAirship 在 IOS 上使用 URL 推送
【发布时间】:2012-07-30 13:54:57
【问题描述】:

我正在使用 UrbanAirship 向我的应用程序发送推送消息。我的设置适用于开发和生产。 我需要将网页网址作为推送消息发送。当用户打开消息时,我希望它重定向到我添加的 url。 我将此代码添加到我的 appdelegate 中。

`- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo{
      NSLog(@"userInfo:%@",[userInfo description]);
      NSLog(@"alert:%@",[[userInfo objectForKey:@"aps"] objectForKey:@"alert"]);
      NSLog(@"alert:%@",[[userInfo objectForKey:@"aps"] objectForKey:@"url"]);
}

并尝试像发送推送一样

{
    "aps": 
    {
        "alert": "take a look at this site ",
        "url": "www.mysite.com"
    }
}

我收到了警报消息,但它再次打开了应用程序而不是 URL。 您能建议我如何发送带有 url 的推送消息并打开该 url 吗?

【问题讨论】:

标签: ios push message urbanairship.com


【解决方案1】:

有两种方法可以做到这一点

用 safari 打开网址(未经测试的代码):

     - (void)application:(UIApplication *)application didReceiveRemoteNotification: (NSDictionary *)userInfo
    { 
     NSLog(@"userInfo:%@",[userInfo description]); 
     NSLog(@"alert:%@",[[userInfo objectForKey:@"aps"] objectForKey:@"alert"]);
     NSLog(@"url:%@",[[userInfo objectForKey:@"aps"] objectForKey:@"url"]); 
     webViewController.url = [NSURL URLWithString:[[userInfo objectForKey:@"aps"] objectForKey:@"url"]];
     [[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSURL URLWithString:[[userInfo objectForKey:@"aps"] objectForKey:@"url"]];
    }

或者你必须在你的应用上处理它:

- (void)application:(UIApplication *)application didReceiveRemoteNotification: (NSDictionary *)userInfo{ 
     NSLog(@"userInfo:%@",[userInfo description]); 
     NSLog(@"alert:%@",[[userInfo objectForKey:@"aps"] objectForKey:@"alert"]);
     NSLog(@"url:%@",[[userInfo objectForKey:@"aps"] objectForKey:@"url"]); 
     webViewController.url = [NSURL URLWithString:[[userInfo objectForKey:@"aps"] objectForKey:@"url"]];

}

例如,在您的 WebViewController 中需要以下方法

    - (void)viewWillAppear:(BOOL)animated { 
    [super viewWillAppear:animated];
    NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
    [webView loadRequest:requestObj];
    }

当然,你的WebViewController.h上必须是一个

    IBOutlet UIWebView *webView;

全屏,或者你想要的......

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-01-24
    • 2011-09-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多