zoukankan      html  css  js  c++  java
  • iOS开发——消息推送跳转

    项目开发用集成是极光推送JPush

        这里主要是消息推送过来处理对应界面跳转

        
        同时看到两篇写的不错的相关博客分享一下:

         http://www.jianshu.com/p/eaf07c4372a8

         http://www.jianshu.com/p/d4460fed39c1

       

       推送的是根据用户ID及用户的绑定的JPush注册ID,对应用户推送。

        首先看一下推送过来的消息格式:


    推送来的字典:{
        "_j_msgid" = 976126105;
        aps =     {
            alert = "U865aU62dfU7b56U7565I160704711100001U5356U51faU80a1U7968:U5b9cU534eU5065U5eb7100U80a1U3001U4ef7U683cU4e3a32.15U3001U5171U8ba13215U2026U2026";
            badge = 50;
            sound = "";
        };
        "pro_id" = 160704711100001;
        "pro_type" = 1;
        "type_id" = 1;
    }



    其中    "pro_id" = 160704711100001;
        "pro_type" = 1;
        "type_id" = 1;

    这三个是后台服务自定义的键值信息,根据自己开发的需要自定义。主要靠这三个信息跳转到对应的界面。


      alert = "U865aU62dfU7b56U7565I160704711100001U5356U51faU80a1U7968:U5b9cU534eU5065U5eb7100U80a1U3001U4ef7U683cU4e3a32.15U3001U5171U8ba13215U2026U2026";
            badge = 50;
            sound = "";

    这三个是推送的固定格式,不管谁的推送都有,alert是通知栏提示的消息信息,badge是桌面app数字角标提醒

    sound是收到消息提醒的声音。

    接收到推送的通知有三种情况,第一种,App未启动  第二种,App在前台   第三种,App在后台

    第一种,App未启动的 时候,点击通知栏消息时,app从- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 这个方法里接受处理消息

    处理逻辑为:将消息放到专门的方法dealRemoteNotification里处理分析后跳转

     // 未启动 推送消息
        NSDictionary* userInfo = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];
        if(userInfo){
           
            [self dealRemoteNotification:userInfo];
        }


    其他的两种情况在下面方法处理

    - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {
        
        // iOS 7 Support Required
        [self dealRemoteNotification:userInfo];


        [JPUSHService handleRemoteNotification:userInfo];
        completionHandler(UIBackgroundFetchResultNewData);
    }

    处理跳转的方法如下

        // 推送消息处理跳转  
        -(void)dealRemoteNotification:(NSDictionary*)userInfo{  
              
            NSLog(@"推送来的字典:%@",userInfo);  
            // 取得 APNs 标准信息内容  
        //    NSDictionary *aps = [userInfo valueForKey:@"aps"];  
        //    NSString *content = [aps valueForKey:@"alert"]; //推送显示的内容  
        //    NSInteger badge = [[aps valueForKey:@"badge"] integerValue]; //badge数量  
        //    NSString *sound = [aps valueForKey:@"sound"]; //播放的声音  
        //  
              
            // 前台的时候不处理消息跳转  
            if ([UIApplication sharedApplication].applicationState == UIApplicationStateActive) { // 前台不处理推送  
                return;  
            }  
            //服务端自定义键值  
            NSString *typeID = [userInfo valueForKey:@"type_id"];     // 真实虚拟  
            NSString *proType = [userInfo valueForKey:@"pro_type"];   // IMP还是ISM  
            NSString *proID = [userInfo valueForKey:@"pro_id"];       // id或code  
          
            if (proType.integerValue == 4){  // 消息助手详情  
              
                MsgAssistant_PushViewController *MsgVC = [[MsgAssistant_PushViewController alloc]init];  
                  
                [self.window.rootViewController presentViewController:MsgVC animated:YES completion:^{  
                      
                }];  
              
            }  
              
            if (typeID.integerValue == 1) { // 虚拟  
                if (proType.integerValue == 1) { // ISM  
                      
                 
                    ISM_PushTradeCommandViewController *ISMPush = [[ISM_PushTradeCommandViewController alloc]init];  
                    ISMPush.ismCodeString                       = proID;  
                    ISMPush.isVirtualExperience                 = YES;  
                      
                      
                    [self.window.rootViewController presentViewController:ISMPush animated:YES completion:^{  
                          
                    }];  
                      
                }else if(proType.integerValue == 2){ // IMP  
                      
                    // IMP交易记录  
                    IMP_PushTradeRecordViewController *IMPPushVC = [[IMP_PushTradeRecordViewController alloc] init];  
                   
                    IMPPushVC.impId               = proID;  
                    IMPPushVC.isVirtualExperience = YES;  
                      
          
                    [self.window.rootViewController presentViewController:IMPPushVC animated:YES completion:^{  
                          
                    }];  
                  
                }else{  
                    return ;  
                }  
                  
            }else if (typeID.integerValue == 2){  // 真实  
              
                if (proType.integerValue == 1) { // ISM  
                      
                      
                    ISM_PushTradeCommandViewController *ISMPush = [[ISM_PushTradeCommandViewController alloc]init];  
                    ISMPush.ismCodeString                       = proID;  
                    ISMPush.isVirtualExperience                 = NO;  
                     
                    [self.window.rootViewController presentViewController:ISMPush animated:YES completion:^{  
                          
                    }];  
                      
                }else if(proType.integerValue == 2){ // IMP  
                      
                    // IMP交易记录  
                    IMP_PushTradeRecordViewController *IMPPushVC = [[IMP_PushTradeRecordViewController alloc] init];  
            
                    IMPPushVC.impId               = proID;  
                    IMPPushVC.isVirtualExperience = NO;  
                     
                      
                    [self.window.rootViewController presentViewController:IMPPushVC animated:YES completion:^{  
                          
                    }];  
              
            }else{  
              
                return ;  
            }  
              
          }  
              
        }  

    本跳转是单个界面,没有下一级,所以没用导航控制器

    根据个人情况处理,这里前台的时候没有处理,有的前台处理的时候是弹窗提示,引导跳转


    同时注意 跳转的界面返回的处理,这里重写跳转界面返回事件

    - (void)backButtonEvent{
        
        [self dismissViewControllerAnimated:YES completion:^{
            
        }];
        
    }

    一般情况下,看完一个消息详情界面用户会点击返回退出此界面,

    如果用户未退出消息详情界面,而下拉通知栏点击了消息,可能会由于未dimiss的界面,

    新的消息详情界面无法present出来,建议处理消息的方法里跳转前发送通知到控制器执行dimiss操作。


  • 相关阅读:
    这篇通俗实用的Vlookup函数教程,5分钟就可以包你一学就会
    nginx 常见正则匹配符号表示
    Nginx if 条件判断
    nginx 将请求全部指向到一个页面
    windows10下面部署nginx(解决文件名中文乱码问题)
    二.Nginx反向代理和静态资源服务配置
    Nginx的使用(一)代理静态文件
    使用Nginx反向代理和内容替换模块实现网页内容动态替换功能
    如何让NGINX显示文件夹目录
    Nginx 如何设置反向代理 多服务器,配置区分开来,单独文件保存单个服务器 server 主机名配置,通过 include 实现
  • 原文地址:https://www.cnblogs.com/LiuChengLi/p/5735989.html
Copyright © 2011-2022 走看看