2017-08-04 4 views
0

私のアプリは実行状態ではありません私は公開されているホームページをタップしていますが、特定のページを開いていますが、アプリケーションがフォアグラウンドとバックグラウンドのときに動作しますが、ビューはすべての状態を表示しています。アプリが実行状態でないときに通知をタップすると、特定のobjectivecページにナビゲートする方法は?

- (void)userNotificationCenter:(UNUserNotificationCenter *)center 
didReceiveNotificationResponse:(UNNotificationResponse *)response 
     withCompletionHandler:(void (^)())completionHandler 
     { 

      NSDictionary *userInfo = response.notification.request.content.userInfo; 
      NSDictionary *dict = userInfo[kAps]; 
      NSString *str = [NSString stringWithFormat:@"%@",[dict valueForKey:kAlert]]; 
      UINavigationController *navController = (UINavigationController *)self.window.rootViewController; 
      MyOrderDetailVC *view = [[UIStoryboard storyboardWithName:kMainStoryboard bundle:nil] instantiateViewControllerWithIdentifier:@"MyOrderDetailVC"]; 

      NSString *orderstatus = userInfo[kgcmnotificationorderstatus]; 
      NSString *ordertype = userInfo[kgcmnotificationordertype]; 
      view.isFromSideMenu = YES; 
      view.isfromViewOrders = YES; 
      view.status = orderstatus; //[NSString stringWithFormat:@"%@",[dictOrderDetails valueForKey:korderstatus]]; 
      view.isProduct =ordertype; 
      view.strOrderStatus = orderstatus; 
      view.strProgramId = @"-1"; 
      if([ordertype isEqualToString: @"0"]) 
      { 
      view.isBookedOrders = NO; 
      } 
      if([ordertype isEqualToString: @"1"]) 
      { 
      view.isBookedOrders =YES; 
      } 
      if([orderstatus isEqualToString:@"0"]) 
      { 
      view.strOrderStatus = kPending; 
      } 
      else if([orderstatus isEqualToString:@"1"]) 
      { 
      view.strOrderStatus = kConfirmed; 
      } 
      else if ([orderstatus isEqualToString:@"2"]) 
      { 
      view.strOrderStatus = kCompleted; 
      } 
      [navController.visibleViewController.navigationController pushViewController:view animated:YES]; 

    [[Shared sharedInstance] showAlertViewInViewController:kAppName message:str buttonTitles:@[OK] viewC:self.window.rootViewController handler:nil]; 

} 

答えて

0

アプリケーションが実行されていない、あなたはdidFinishLaunchingWithOptionsで

-(BOOL)application:(UIApplication*)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions 
{  
    UILocalNotification *localNotif = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];  
    if (localNotif) { 
    // Notification detect here 
    // Put your code here so it will be call when your App will not running state and tapped on Notification. 
    }  
} 
+0

の点に注意してください。しかし、それはしようとして確認してください - (void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse :(UNNotificationResponse *)応答 withCompletionHandler :(void(^)())completionHandler "このメソッドはこのメソッドの側で呼び出されるアラートビューを表示しますが、このメソッドでのみ書き込んでいる他のページには移動しないためです。 –

+0

if(application.applicationState == UIApplicationStateInactive) { //アプリがバックグラウンドのときにプッシュ通知から開く } – iPatel

0

以下のようなあなたのNotificationdidFinishLaunchingWithOptionsのメソッドを検出したい通知が」あるか

NSDictionary *notification = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey]; 
if (notification) 
{ 
    NSLog(@"app recieved notification %@",notification); 
    // open your particular controller 


}else{ 
    NSLog(@"app did not recieve notification"); 
} 
+0

私はこれを試しましたが、通知をタップしたときにホームに戻るアラートビューを表示するが、特定のページには移動しない。 –

+0

このUIStoryboardとしてpartilcaurビューコントローラーを開くことができます* storyboard = [UIStoryboard storyboardWithName:@ "MainStoryboard_iPhone" bundle:nil]; YourController * myVC =(Yourcontroller *)[ストーリーボードinstantiateViewControllerWithIdentifier:@ "YourcontrollerId"]; [self.navigationController pushViewController:myVC animated:YES]; –

関連する問題