0
從我的應用程序中,即使應用程序處於非活動狀態或終止狀態,它也可以收到通知。但是,當我點擊通知打開它時,它將打開主頁面,而不是像我希望的那樣進入「雜誌頁面」。打開通知即使應用程序不活動或終止
這隻有在應用程序處於活動狀態或在後臺時纔有效。有誰能告訴我關於這個問題的一些事嗎?我嘗試將所有三個(Active,Inactive,Background)的UIApplicationState置於didReceiveRemoteNotification方法中,但即使我在應用程序處於活動狀態或在後臺時打開通知,每個通知都將通過後臺狀態。
任何人都可以給我任何想法來解決這個問題嗎?
這是遠程通知方法:
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
if([userInfo valueForKey:@"app"]) {
NSString *action_app = [userInfo valueForKey:@"app"];
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setObject:action_app forKey:@"app"];
NSLog(@"detect app value from UA ====> %@",action_app);
SampleViewController *sample=[[SampleViewController alloc]init];
[sample viewDidAppear:YES];
}else if([userInfo valueForKey:@"url"]){
NSString *action_url = [userInfo valueForKey:@"url"];
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setObject:action_url forKey:@"url"];
NSLog(@"detect url value from UA ====> %@",action_url);
SampleViewController *sample=[[SampleViewController alloc]init];
[sample viewDidAppear:YES];
}else{
NSLog(@"---nothing to read---");
}
// Send the alert to UA so that it can be handled and tracked as a direct response. This call
// is required.
[[UAPush shared] handleNotification:userInfo applicationState:application.applicationState];
// Reset the badge after a push received (optional)
[[UAPush shared] resetBadge];
// Open inboxData when receive notification
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
self.blankviewController = [[SampleViewController alloc] initWithNibName:@"SampleViewController" bundle:nil];
self.navigationController = [[UINavigationController alloc] initWithRootViewController:self.blankviewController];
self.window.rootViewController = self.navigationController;
[self.window makeKeyAndVisible];
}
那麼,我該如何傳遞通知鍵才能通過'didReceiveRemoteNotification'方法? – user2767343
@ user2767343你不行。你可以做的是編寫一個通用的方法,它將被'didReceiveRemoteNotification'和'didFinishLaunchingWithOptions'調用,並執行所有處理通知數據的邏輯。您可以將通知數據傳遞給它。 – Eran