Objective c 如何获取iOS 13+的设备令牌;目标c中的设备

Objective c 如何获取iOS 13+的设备令牌;目标c中的设备,objective-c,apple-push-notifications,Objective C,Apple Push Notifications,我的应用程序的推送通知在iOS 12.x设备上运行良好。我将设备令牌作为 -(void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken{ str = [NSString stringWithFormat:@"%@", deviceToken]; NSStri

我的应用程序的推送通知在iOS 12.x设备上运行良好。我将设备令牌作为

-(void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken{
    
    str = [NSString stringWithFormat:@"%@", deviceToken];
    
    
    NSString *token = [[[[deviceToken description]
                         stringByReplacingOccurrencesOfString:@"<"withString:@""]
                        stringByReplacingOccurrencesOfString:@">" withString:@""]
                       stringByReplacingOccurrencesOfString: @" " withString: @""];

由于令牌的格式不正确,推送通知无法正常工作。如何在iOS 13设备中获取设备令牌。

对于操作系统大于13的iPhone,我没有获取设备令牌。我修改了下面链接的答案,最终得到了答案

-(void)应用程序:(UIApplication*)应用程序DIDregisterforRemotionTificationswithDeviceToken:(NSData*)deviceToken{
str2=[self-fetchDeviceToken:deviceToken];
}
-(NSString*)fetchDeviceToken:(NSData*)deviceToken{
nsu整数len=设备token.length;
如果(len==0){
返回零;
}
const unsigned char*buffer=deviceToken.bytes;
NSMutableString*hexString=[NSMutableString stringWithCapacity:(len*2)];
对于(int i=0;i

设备令牌将分配给变量
str2

这是否回答了您的问题?问题只出现在iOS 13手机上。
{length=32,bytes=0x387de70558f0099d606d6cc1234c3967...8a7c5dccb10a67c2}
-(void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken{

    str2 = [self fetchDeviceToken:deviceToken];

}

- (NSString *)fetchDeviceToken:(NSData *)deviceToken {
    NSUInteger len = deviceToken.length;
    if (len == 0) {
        return nil;
    }
    const unsigned char *buffer = deviceToken.bytes;
    NSMutableString *hexString  = [NSMutableString stringWithCapacity:(len * 2)];
    for (int i = 0; i < len; ++i) {
        [hexString appendFormat:@"%02x", buffer[i]];
    }
    return [hexString copy];
}