给大家讲一点常识,友盟推送分生产环境和开发环境。用手机刷上去的就是开发环境, 发布到苹果商店就是生产环境,没发布前怎么模拟呢, 用普通账号打的ad hoc 包, 用企业账号打的ad hoc 包或者enterprise包都可以测试生产环境。

  开发环境下, 你把APP删掉,重新调试上来,就会生成一个新的device_token了!

  

  收到通知的时候APP的状态可能是未启动、前台活跃(任何界面)、后台等三种。

  • 未启动时,点击通知栏启动App, 会在didFinishLaunchingWithOptions方法里收到通知内容。
  • 剩下两种会在didReceiveRemoteNotification方法里收到通内容。

  

当App在前台或后台的时候的处理逻辑

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

{

    self.notifyDic = userInfo;

     [UMessage setAutoAlert:NO];

    [UMessage didReceiveRemoteNotification:userInfo];

 

    for (NSString *key in userInfo) {

        NSLog(@"%@---%@-----%@",key,[userInfo objectForKey:key],userInfo);

    }

    

    

 

    

/*

    CHTabBarViewController *tabbarUm = (CHTabBarViewController *)self.window.rootViewController;

    CHMyInsurancePolicyViewController *twoNav = [[CHMyInsurancePolicyViewController alloc]init];

    twoNav.tuisong = @"song";

    UINavigationController * nav1 = tabbarUm.viewControllers[0];

    

    [nav1 pushViewController:twoNav animated:YES];

*/

    

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

    {

        

        CHTabBarViewController *tabbarUm = (CHTabBarViewController *)self.window.rootViewController;

        CHMyInsurancePolicyViewController *twoNav = [[CHMyInsurancePolicyViewController alloc]init];

        twoNav.tuisong = @"song";

        UINavigationController * nav1 = tabbarUm.viewControllers[0];

        

        UIAlertController *alertCon = [UIAlertController alertControllerWithTitle:@"车易" message:[userInfo[@"aps"] objectForKey:@"alert"] preferredStyle:UIAlertControllerStyleAlert];

        

        UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"确定" style:(UIAlertActionStyleDefault) handler:^(UIAlertAction *action) {

            // 点击按钮后的方法直接在这里面写

            

            if ([[userInfo objectForKey:@"keyWord"]isEqualToString:@"order"]) {

                [nav1 pushViewController:twoNav animated:YES];

            }else{

                

                CHHealthyMeViewController *chC = [[CHHealthyMeViewController alloc]init];

                

                [nav1 pushViewController:chC animated:YES];

                

            }

 

            //[nav1 pushViewController:twoNav animated:YES];

 

            

            

        }];

        

        [alertCon addAction:okAction];

        

        [tabbarUm.viewControllers[0] presentViewController:alertCon animated:YES completion:nil];

 

    }else{

        

        CHTabBarViewController *tabbarUm = (CHTabBarViewController *)self.window.rootViewController;

        CHMyInsurancePolicyViewController *twoNav = [[CHMyInsurancePolicyViewController alloc]init];

        twoNav.tuisong = @"song";

        UINavigationController * nav1 = tabbarUm.viewControllers[0];

        

        if ([[userInfo objectForKey:@"keyWord"]isEqualToString:@"order"]) {

        [nav1 pushViewController:twoNav animated:YES];

        }else{

            

        CHHealthyMeViewController *chC = [[CHHealthyMeViewController alloc]init];

        

        [nav1 pushViewController:chC animated:YES];

            

        }

}

}

 

 

当程序未启动的时候

我这里是在applicationdelegate里面写一个属性 didFinishLaunchingWithOptions 方法里面写:

 NSDictionary* userInfo = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];

    if(userInfo){//推送信息

        self.notifyDic = userInfo;//[userInfo copy]

    }

 

在首页处理

viewdidload 判断用户是否接到通知

{

    AppDelegate * app = (AppDelegate *)[UIApplication sharedApplication].delegate;

    //可以根据他是否为空来判断是否有通知

    [self getPushInfo:app.notifyDic];

{

// 推送处理

-(void)getPushInfo:(NSDictionary *)notidic

{

    

    NSString *  pushName = [[notidic objectForKey:@"aps"] objectForKey:@"alert"];

    NSLog(@"0-0-0--%@",pushName);

    if (pushName) {

        

    CHMyInsurancePolicyViewController *Con = [[CHMyInsurancePolicyViewController alloc]init];

    Con.navigationItem.hidesBackButton = YES;

        

        if ([[notidic objectForKey:@"keyWord"]isEqualToString:@"order"]) {

            [self.navigationController pushViewController:Con animated:YES];

        }else{

            

            CHHealthyMeViewController *chC = [[CHHealthyMeViewController alloc]init];

            

            [self.navigationController pushViewController:chC animated:YES];

            

        }

 

        

    }

}