gpt4 book ai didi

ios - 设备 token NULL

转载 作者:可可西里 更新时间:2023-11-01 05:44:12 24 4
gpt4 key购买 nike

我有一个奇怪的问题,我无法自行复制。我的一些用户为 Apple 推送通知返回空白(或空)设备 token 。它可能发生在 5% 的用户身上。任何人都遇到过同样的问题或对此有所了解。

我获取设备 token 的代码是:

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

NSUserDefaults *def = [NSUserDefaults standardUserDefaults];
[def setObject:tokenString forKey:@"deviceToken"];

}

- (void)application: (UIApplication*)application didFailToRegisterForRemoteNotificationsWithError: (NSError*)error
{
NSLog(@"Failed to get token, error: %@", error) ;
}

最佳答案

您不应该以这种方式操纵设备 token ,尤其是不应该使用 description 方法,它是一种调试辅助工具,而不是convert-to-string运营商。

来自UIApplicationDelegate reference :

deviceToken

A token that identifies the device to APS. The token is an opaque data type because that is the form that the provider needs to submit to the APS servers when it sends a notification to a device. The APS servers require a binary format for performance reasons.

The size of a device token is 32 bytes.

Note that the device token is different from the uniqueIdentifier property of UIDevice because, for security and privacy reasons, it must change when the device is wiped.

以二进制形式存储设备 token 。

关于ios - 设备 token NULL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25680077/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com