Open Specific View when Opening App from Notification

前端 未结 3 1119
梦如初夏
梦如初夏 2020-12-04 12:28

I have just added push notifications to my app. I\'m wanting to have so that when a user opens the app from a notification, it will open a specific view controller and not

3条回答
  •  孤城傲影
    2020-12-04 13:33

    You can do some thing like this

      - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    {
    
    self.window.rootViewController = self.tabBarController;
    [self.window makeKeyAndVisible];
    
       // If application is launched due to  notification,present another view controller.
    UILocalNotification *notification = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];
    
    if (notification)
    {
        NotificationViewController *viewController = [[NotificationViewController alloc]initWithNibName:NSStringFromClass([NotificationViewController class]) bundle:nil];
        [self.window.rootViewController presentModalViewController:viewController animated:NO];
        [viewController release];
    }
    
    return YES;
    }
    
     -(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
     {
    
    NotificationViewController *viewController = [[NotificationViewController alloc]initWithNibName:NSStringFromClass([NotificationViewController class]) bundle:nil];
    
    
    [self.window.rootViewController presentModalViewController:viewController animated:NO];
    [viewController release];
    }
    

提交回复
热议问题