
有人遇到过推送的通知测试版可以在通知栏点开到具体页面,但是 appstore 版本点开就停在首页的问题吗? 我的跳转代码是这样的
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler { if (application.applicatiOnState== UIApplicationStateActive) { [self gotoUrl:userInfo]; }else{ [self showPushArticle:userInfo]; } completionHandler(UIBackgroundFetchResultNewData); } showPushArticle 函数
- (void)showPushArticle:(NSDictionary *)userInfo { if (userInfo == NULL) { return; } NSDictionary *article = [userInfo objectForKey:@"ext"]; if(article) { NSString *url = [article objectForKey:@"l"]; if(![url hasPrefix:@"https://"]){ return; } PTWebViewController *viewcOntroller= [[PTWebViewController alloc] init]; viewcontroller.webURL = url; [viewcontroller setNavigationTitle:@"推送新闻"]; [self.drawerController.centerNavigationController pushViewController:viewcontroller animated:YES]; } } push 的 json 格式是:
{"aps":{"alert":"title","badge":1,"sound": "default"},"ext":{"l":"https://example.com"}} 不知道哪位遇到过同样的问题,麻烦指教一下
1 q409195961 2017-06-29 12:54:14 +08:00 你先确定第二种情况(App Store 版本),App 是没在后台运行的,还是在后台运行的? 如果没后台运行的,你需要从- application: didFinishLaunchingWithOptions: 中取出推送的内容 ``` NSDictionary * remoteNotification = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey]; ``` 另: if(![url hasPrefix:@"https://"]){ 建议改成 if(![url hasPrefix:@"http"]){ 这样 url 是 http 也可以调起 WebView 控制器 |
2 mxm145 OP application: didFinishLaunchingWithOptions:中也是写了的,代码如下: ``` NSDictionary *userInfo = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey]; if (userInfo) { [self showPushArticle:userInfo]; } ``` 无论 app 在后台运行还是在前台都不会跳转,但是接收没有问题 |
3 showme1121 2017-09-30 22:30:46 +08:00 via iPhone 确定两种版本都是通过 api 或者网页发送的数据么 |
4 mxm145 OP @showme1121 肯定是一样的,都是使用同样的数据 |