收到推送通知或重定向到另一个视图控制器时,打开视图控制器

时间:2015-09-28 06:24:40

标签: ios objective-c ios8 push-notification

我的问题是,当我重定向到另一个视图控制器时,数据不会到来。所以请帮帮我..

AppDelegate.m

我已经宣布了这样的

    - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
    {

    NSDictionary *segueDictionary = [userInfo valueForKey:@"aps"];

    NSString *segueName=[[NSString alloc]initWithFormat:@"%@",[segueDictionary valueForKey:@"vendor_data"]];


    if ([[UIApplication sharedApplication] applicationState] == UIApplicationStateActive)
    {

        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@" Offers"
                                                        message:[NSString stringWithFormat:@"%@",[[userInfo objectForKey:@"aps"] objectForKey:@"alert"]]
                                                       delegate:self
                                              cancelButtonTitle:@"OK"
                                              otherButtonTitles:nil];
        [alert show];

    }

    else if ([[UIApplication sharedApplication] applicationState] == UIApplicationStateInactive || [[UIApplication sharedApplication] applicationState] == UIApplicationStateBackground)
    {





    MessageViewController * referObject = [[MessageViewController alloc]init];
    //[self.navigationController pushViewController:referObject animated:YES];

  UINavigationController *navController = (UINavigationController *)self.window.rootViewController;

    [navController.visibleViewController.navigationController pushViewController:referObject animated:YES];


    }

    }

UIApplicationStateInactive应用程序刚刚打开,但事实并非如此 重定向到MessageViewControllerUIApplicationStateBackground该应用重定向到MessageViewController

我想访问MessageViewController& 这里MessageViewController是一个Xib

请帮助我....

谢谢

1 个答案:

答案 0 :(得分:0)

对于iOS 8.x使用

- (void)application:(UIApplication *)application handleActionWithIdentifier:(nullable NSString *)identifier forRemoteNotification:(NSDictionary *)userInfo completionHandler:(void(^)())completionHandler {
}

对于iOS 9+使用

- (void)application:(UIApplication *)application handleActionWithIdentifier:(nullable NSString *)identifier forRemoteNotification:(NSDictionary *)userInfo withResponseInfo:(NSDictionary *)responseInfo completionHandler:(void(^)())completionHandler {
}