码迷,mamicode.com
首页 > 其他好文 > 详细

《友盟推送调到指定界面》

时间:2016-04-12 12:53:47      阅读:144      评论:0      收藏:0      [点我收藏+]

标签:

  给大家讲一点常识,友盟推送分生产环境和开发环境。用手机刷上去的就是开发环境, 发布到苹果商店就是生产环境,没发布前怎么模拟呢, 用普通账号打的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];

            

        }

 

        

    }

}

 

 

 

 

 

 

 

《友盟推送调到指定界面》

标签:

原文地址:http://www.cnblogs.com/walkingzmz/p/5382024.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!