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