Objective c 如何在iOS中的applaunchwithoption中读取有效负载?

Objective c 如何在iOS中的applaunchwithoption中读取有效负载?,objective-c,apple-push-notifications,appdelegate,payload,ios8.3,Objective C,Apple Push Notifications,Appdelegate,Payload,Ios8.3,我已经为我的iOS应用程序实现了远程推送通知。它有一个定制的有效载荷。像这个 "aps": { "alert": "joetheman", "sound": "default" }, "message": "Some custom message for your app", "id": 1234 当点击锁屏上的通知时,根据id我想加载不同的应用程序屏幕(当应用程序未运行时,如果我收到通知且id为2,应用程序应在BookingViewController打开的情况下打开)。因

我已经为我的iOS应用程序实现了远程推送通知。它有一个定制的有效载荷。像这个

 "aps": {
    "alert": "joetheman",
    "sound": "default"
},
"message": "Some custom message for your app",
"id": 1234
当点击锁屏上的通知时,根据id我想加载不同的应用程序屏幕(当应用程序未运行时,如果我收到通知且id为2,应用程序应在BookingViewController打开的情况下打开)。因此,如何在
AppDelegate
中的
applaunchwithOption
以及
notificationdireceived
委托中读取自定义负载


请帮帮我。谢谢

您可以使用以下方法处理推送通知:——


您可以使用以下方法处理推送通知:——


然后,如果应用程序没有在后台运行,并且如果用户仍然收到一个通知,我应该在哪个代理下处理它。(用户在第一次打开应用程序之前收到通知,在这种情况下,据我所知ApplicationDidLaunchWithOption将在此委托下激发如何执行此操作?)是,在这种情况下,您是对的,您需要通过ApplicationIDLaunchWithOption来处理您的应用程序。我如何在ApplicationIDLaunchWithOption中访问我的有效负载?ApplicationIDLaunchWithOption的启动选项为launchOptions[UIApplicationLaunchOptions sRemoteNotificationKey];然后,如果应用程序没有在后台运行,并且如果用户仍然收到一个通知,我应该在哪个代理下处理它。(用户在第一次打开应用程序之前收到通知,在这种情况下,据我所知ApplicationDidLaunchWithOption将在此委托下激发如何执行此操作?)是,在这种情况下,您是对的,您需要通过ApplicationIDLaunchWithOption来处理您的应用程序。我如何在ApplicationIDLaunchWithOption中访问我的有效负载?ApplicationIDLaunchWithOption的启动选项为launchOptions[UIApplicationLaunchOptions sRemoteNotificationKey];
-(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo

{
    NSLog(@"%@",userInfo);
    NSString *msg=[userInfo objectForKey:@"message"];
    //Application is Running
    if ( application.applicationState == UIApplicationStateActive ){

        if ([[userInfo objectForKey:@"id"]isEqualToString:@"1"]) {

        self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
        YourViewController *obj = [[YourViewController alloc]initWithNibName:@"YourViewController" bundle:nil];

        nav = [[UINavigationController alloc]initWithRootViewController:obj];
        [self.nav setNavigationBarHidden:YES];
        self.window.rootViewController = nav;
        [self.window makeKeyAndVisible];

        }
        else if ([[userInfo objectForKey:@"id"]isEqualToString:@"2"]) {                 
        self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
        YourViewController *obj = [[YourViewController alloc]initWithNibName:@"YourViewController" bundle:nil];

        nav = [[UINavigationController alloc]initWithRootViewController:obj];
        [self.nav setNavigationBarHidden:YES];
        self.window.rootViewController = nav;
        [self.window makeKeyAndVisible];

       }
   }
//when Application in Background
   else{
       if ([[userInfo objectForKey:@"id"]isEqualToString:@"1"]) {

        self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
        YourViewController *obj = [[YourViewController alloc]initWithNibName:@"YourViewController" bundle:nil];

        nav = [[UINavigationController alloc]initWithRootViewController:obj];
        [self.nav setNavigationBarHidden:YES];
        self.window.rootViewController = nav;
        [self.window makeKeyAndVisible];

       }

       else if ([[userInfo objectForKey:@"id"]isEqualToString:@"2"]) {
        self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
        YourViewController *obj = [[YourViewController alloc]initWithNibName:@"YourViewController" bundle:nil];

        nav = [[UINavigationController alloc]initWithRootViewController:obj];
        [self.nav setNavigationBarHidden:YES];
        self.window.rootViewController = nav;
        [self.window makeKeyAndVisible];

       }               
    }
}