zoukankan      html  css  js  c++  java
  • iOS开发之iOS13推送deviceToken处理

    iOS13新出之后会有收不到推送的问题

    因为iOS13的处理方法变了,代码如下

    //获取DeviceToken成功
    - (void)application:(UIApplication *)application
    didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
    {
        //Xcode11打的包,iOS13获取Token有变化
        if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 13) {
            if (![deviceToken isKindOfClass:[NSData class]]) {
                //记录获取token失败的描述
                return;
            }
            const unsigned *tokenBytes = (const unsigned *)[deviceToken bytes];
            NSString *strToken = [NSString stringWithFormat:@"%08x%08x%08x%08x%08x%08x%08x%08x",
                                  ntohl(tokenBytes[0]), ntohl(tokenBytes[1]), ntohl(tokenBytes[2]),
                                  ntohl(tokenBytes[3]), ntohl(tokenBytes[4]), ntohl(tokenBytes[5]),
                                  ntohl(tokenBytes[6]), ntohl(tokenBytes[7])];
            NSLog(@"deviceToken1:%@", strToken);
            return;
        } else {
            NSString *token = [NSString
                           stringWithFormat:@"%@",deviceToken];
            token = [token stringByReplacingOccurrencesOfString:@"<" withString:@""];
            token = [token stringByReplacingOccurrencesOfString:@">" withString:@""];
            token = [token stringByReplacingOccurrencesOfString:@" " withString:@""];
            NSLog(@"deviceToken2 is: %@", token);
        }
    }
  • 相关阅读:
    链表逆序输出 ---九度1511
    java 通过ssh连接linux服务器的测试代码
    C/C++时间函数总结
    C,C++,windows api, linux api 操作文件总结
    基于大数据计算思想的分布式数据库
    手机定位的方式
    矩阵取数问题
    回文字符串
    linux shell重定向总结
    apache flink 入门
  • 原文地址:https://www.cnblogs.com/hecanlin/p/11646915.html
Copyright © 2011-2022 走看看