本人做IOS推送,推送证书都弄好了,但是在真机测试的时候,总是获取的DeviceToken为空,实在是百思不得姐,忘各位大牛指点迷津。(证书已经导入到项目中,真机测试流程都对)
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)pToken{
    NSString *str = [[NSString alloc]initWithData:pToken encoding:NSUTF8StringEncoding];
    NSLog(@"---Token--%@", str);
    
}

解决方案 »

  1.   

    NSString * tokenAsString = [[[aDeviceToken description]
                                     stringByTrimmingCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@"<>"]]
                                    stringByReplacingOccurrencesOfString:@" " withString:@""];
        NSLog(@"-------》the device token is: %@", tokenAsString);
    试试这样
      

  2.   

    解决了,跟你写方法的一样。同样谢谢你。
    - (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
        
        self.deviceTokenStr =[[deviceToken description] stringByReplacingOccurrencesOfString: @"<" withString: @""];
        
        self.deviceTokenStr=[self.deviceTokenStr stringByReplacingOccurrencesOfString: @">" withString: @""];
        
        self.deviceTokenStr=[self.deviceTokenStr stringByReplacingOccurrencesOfString: @" " withString: @""];
        
        self.deviceTokenStr=[NSString stringWithFormat:@"%@",self.deviceTokenStr];
        
        NSLog(@"推送deviceTokenStr--------%@",self.deviceTokenStr);
        
    }