有两种方法可以做到这一点
使用 safari(未经测试的代码)打开 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"]];
[[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;
全屏,或者你想要的......