zoukankan      html  css  js  c++  java
  • iOS极光推送进一部使用(重点)

    一.设置标签alias(userId 单个推送)和别名tags(行业分类 多个推送) 
     
    覆盖逻辑 而不是新增逻辑 block回调
    + (void)      setTags:(NSSet *)tags
                    alias:(NSString *)alias
    fetchCompletionHandle:(void (^)(int iResCode, NSSet *iTags, NSString *iAlias))completionHandler;
     
     
    三. 应用程序进入前台各种情况的判断
    1.应用程序关闭
       NSDictionary* remoteNotification = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];
        if (remoteNotification ==nil) {
            //1.点击icon进入应用
        }else{
            //2.点击消息进入应用
            int badge =[remoteNotification[@"aps"][@"badge"] intValue];
            badge--;
            [APService setBadge:badge];
            [UIApplication sharedApplication].applicationIconBadgeNumber =badge;
            self.pushType = [remoteNotification objectForKey:@"msg_type"];
            self.pushID = [remoteNotification objectForKey:@"msg_id"];
            //根据推送消息的 类型 和 参数 推不同的控制器
            if ([self.pushType isEqualToString:@"news"]) {
            }else if([self.pushType isEqualToString:@"rsp-sl"]){ 
            }else if([self.pushType isEqualToString:@"rsp-sl-1"]){
            }
        }
    2.应用程序在活跃状态 
    //收到通知
    - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^) (UIBackgroundFetchResult))completionHandler {
        [JPUSHService handleRemoteNotification:userInfo];
        completionHandler(UIBackgroundFetchResultNewData);
       
        // 取得 APNs 标准信息内容
        //NSDictionary *aps = [userInfo valueForKey:@"aps"];
        //NSString *content = [aps valueForKey:@"alert"]; //推送显示的内容
        //NSInteger badge = [[aps valueForKey:@"badge"] integerValue]; //badge数量
        //NSString *sound = [aps valueForKey:@"sound"]; //播放的声音
        //取得Extras字段内容
        //NSString *customizeField1 = [userInfo valueForKey:@"customizeExtras"]; //服务端中Extras字段,key是自己定义的
        //NSLog(@"content =[%@], badge=[%lu], sound=[%@], customize field  =[%@]",content,badge,sound,customizeField1);
     
         int badge =[userInfo[@"aps"][@"badge"] intValue];
             badge--;
             [APService setBadge:badge];
             [UIApplication sharedApplication].applicationIconBadgeNumber =badge;
             self.pushType = [userInfo objectForKey:@"msg_type"];
             self.pushID = [userInfo objectForKey:@"msg_id"];
             //iOS的应用程序分为3种状态,1是前台运行的状态UIApplicationStateActive;
              2是后台运行的状态UIApplicationStateInactive;
              3是app关闭状态UIApplicationStateBackground     
                        现在只有第三种状态app关闭的情况下会自动统计角标数目;其它两种情况下都需要手动操作来实现角标的统计,这块的实现机制就是这样的。
       
             //1.应用程序处在前台
             if (application.applicationState == UIApplicationStateActive) {
                 UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"收到推送消息"
                                                                 message:userInfo[@"aps"][@"alert"]
                                                                delegate:self
                                                       cancelButtonTitle:@"取消"
                                                       otherButtonTitles:@"确定", nil,nil];
                 alert.tag=4020;
                 //点确定跳到相应的界面。
                 [alert show];
             }2.应用程序在后台
             else if(application.applicationState ==UIApplicationStateInactive){
                
                  //根据推送消息的 类型 和 参数 推不同的控制器
                 if ([self.pushType isEqualToString:@"news"]) {
                 }else if([self.pushType isEqualToString:@"rsp-sl"]){ 
                 }else if([self.pushType isEqualToString:@"rsp-sl-1"]){
                 }
        }
    }
     
    四.RegistrationID 设备ID
    集成了 JPush SDK 的应用程序在第一次成功注册到 JPush 服务器时,JPush 服务器会给客户端返回一个唯一的该设备的标识 - RegistrationID
    应用程序可以把此 RegistrationID 保存以自己的应用服务器上,然后就可以根据 RegistrationID 来向设备推送消息或者通知。

    iOS 9系统,应用卸载重装,APNs返回的devicetoken会发生变化,开发者需要获取设备最新的Registration id。请在kJPFNetworkDidLoginNotification的实现方法里面调用"RegistrationID"这个接口来获取 RegistrationID。

     
     
    五.设置JPush服务器中存储的badge值
    + (BOOL)setBadge:(int)value
    
    
    设置badge值,本地仍须调用UIApplication:setApplicationIconBadgeNumber函数
     
  • 相关阅读:
    BZOJ 1101 莫比乌斯函数+分块
    BZOJ 2045 容斥原理
    BZOJ 4636 (动态开节点)线段树
    BZOJ 2005 容斥原理
    BZOJ 2190 欧拉函数
    BZOJ 2818 欧拉函数
    BZOJ 3123 主席树 启发式合并
    812. Largest Triangle Area
    805. Split Array With Same Average
    794. Valid Tic-Tac-Toe State
  • 原文地址:https://www.cnblogs.com/cfl911014/p/5276197.html
Copyright © 2011-2022 走看看