gpt4 book ai didi

ios - APNS 设备 token 生成不正确

转载 作者:行者123 更新时间:2023-11-28 21:48:55 24 4
gpt4 key购买 nike

我已经集成了苹果推送通知,但在我的应用程序中遇到了一个奇怪的问题。当我通过 USB 连接通过 Xcode 直接安装应用程序时,设备 token 正在生成并正确存储在数据库中并且推送通知工作正常。但是当我创建 IPA 并通过在同一设备中创建的 ipa 安装应用程序时,设备 token 生成错误并且推送通知不起作用。下面是我的代码:

if ([[UIApplication sharedApplication] respondsToSelector:@selector(registerUserNotificationSettings:)]) {
[[UIApplication sharedApplication] registerUserNotificationSettings: [UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge) categories:nil]];
} else {
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:
(UIUserNotificationTypeBadge | UIUserNotificationTypeSound | UIUserNotificationTypeAlert)];
}

application.applicationIconBadgeNumber = 0;

#ifdef __IPHONE_8_0
- (void)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings
*)notificationSettings {
[application registerForRemoteNotifications];
}
#endif


- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData
*)deviceToken {
const unsigned *tokenData = deviceToken.bytes;
NSString *deviceTokenString = [NSString stringWithFormat:@"%08x%08x%08x%08x%08x%08x%08x%08x", ntohl(tokenData[0]),ntohl(tokenData[1]),ntohl(tokenData[2]),ntohl(tokenData[3]),ntohl(tokenData[4]),ntohl(tokenData[5]),ntohl(tokenData[6]),ntohl(tokenData[7])];
[[NSUserDefaults standardUserDefaults]setObject:deviceTokenString forKey:@"devicetoken"];
NSLog(@"Device Token = %@", deviceTokenString);
}

//Failed to Register for Remote Notifications
- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error {
NSLog(@"Error in registration. Error: %@", error);
}

最佳答案

设备 token 取决于您签署应用程序所使用的证书。如果你直接安装它是开发证书,而当为 AdHoc 签名时它是一个分发证书。对于推送,您需要在服务器上打包相应的分发或开发证书。

关于ios - APNS 设备 token 生成不正确,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29047175/

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