打开通知甚至应用程序不活动或终止

时间:2013-10-23 04:21:23

标签: xcode push-notification

从我的应用程序中,即使应用程序处于非活动状态或终止,它也可以收到通知。但是,当我点击通知打开它时,它将打开主页而不是按照我的意愿去“期刊页面”。

这仅在应用处于活动状态或后台时才有效。谁能告诉我一些关于这个问题的事情?我尝试在didReceiveRemoteNotification方法中为所有三个(Active,Inactive,Background)设置UIApplicationState,但是即使我在应用程序处于活动状态或后台时打开通知,每个通知都将处于后台状态。

有人能给我任何解决这个问题的想法吗?

这是远程通知的方法:

- (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];

}

1 个答案:

答案 0 :(得分:0)

didReceiveRemoteNotification:仅在应用处于后台时触发通知,或者应用已在运行时才会调用。

如果应用程序在通知到达时未运行,那么当您点击通知时,将调用application:didFinishLaunchingWithOptions:方法并将通知有效内容传递给它。

相关问题