-1
我希望我的應用程序在用戶點擊接收到的推送通知時推送NewsViewController。在didFinishLaunching我:推送通知點擊視圖控制器不會在應用程序完全關閉時工作
UIUserNotificationType userNotificationTypes = (UIUserNotificationTypeAlert |
UIUserNotificationTypeBadge |
UIUserNotificationTypeSound);
UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:userNotificationTypes
categories:nil];
[[UIApplication sharedApplication]
registerUserNotificationSettings:settings];
[application registerUserNotificationSettings:settings];
[application registerForRemoteNotifications];
然後,還在AppDelegate中,我有:
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
[PFPush handlePush:userInfo];
UINavigationController *nav = (UINavigationController *) self.tabBarController.selectedViewController;
NewsViewController *dvController8 = [[NewsViewController alloc] initWithNibName:@"NewsViewController" bundle:[NSBundle mainBundle]];
[nav pushViewController:dvController8 animated:YES];
if (application.applicationState == UIApplicationStateInactive) {
UIAlertView *test = [[UIAlertView alloc] initWithTitle:@"INACTIVE" message:@"INACTIVE" delegate:self cancelButtonTitle:@"OK" otherButtonTitles: nil];
[test show];
[self handleRemoteNotificationWithPayload:userInfo];
}
}
-(void)handleRemoteNotificationWithPayload:(NSDictionary *)payload {
UINavigationController *nav = (UINavigationController *) self.tabBarController.selectedViewController;
NewsViewController *dvController8 = [[NewsViewController alloc] initWithNibName:@"NewsViewController" bundle:[NSBundle mainBundle]];
[nav pushViewController:dvController8 animated:YES];
}
如果用戶得到一個推而應用程序是開放的,它進入NewsViewController。如果應用程序在點擊推送通知時在後臺運行,則會轉到NewsViewController。但是,如果用戶已完全從應用程序切換器關閉應用程序,然後點擊收到的通知,它將打開應用程序,而不會轉到NewsViewController。我該如何解決?
,如果你看了我前面提供的例子,它規定你需要它,以及調用'應用didFinishLaunchingWithOptions',我想你忽略它。這是一個新手失禮,文檔將幫助你。我建議你開始與它交朋友 – soulshined
@soulshined你從未回答過。當把它放在'didFinishLaunchingWithOptions'中時,它會在應用程序首次啓動時推送該視圖控制器,而不僅僅是在收到推送時。 – user717452
然後你把它設置錯了。你必須做一個有條件的檢查來查看一個app是由userInfo打開還是剛剛打開。你可以通過說'if(userInfo)'這樣做有什麼意義嗎? – soulshined