Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/105.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 生成的APNS设备令牌不正确_Ios_Apple Push Notifications_Devicetoken - Fatal编程技术网

Ios 生成的APNS设备令牌不正确

Ios 生成的APNS设备令牌不正确,ios,apple-push-notifications,devicetoken,Ios,Apple Push Notifications,Devicetoken,我集成了苹果推送通知,在我的应用程序中遇到了一个奇怪的问题。当我通过usb连接通过Xcode直接安装应用程序时,设备令牌被正确地存储在数据库中,推送通知工作正常。但是,当我创建IPA并通过在同一设备中创建的IPA安装应用程序时,设备令牌生成错误,推送通知不起作用。下面是我的代码: if ([[UIApplication sharedApplication] respondsToSelector:@selector(registerUserNotificationSettings:)]) {

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

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);
}

设备令牌取决于应用程序的签名证书。如果直接安装,则它是dev证书,而在为AdHoc签名时,它是分发证书。对于推送,您需要在服务器上打包相应的分发或开发证书。

通常情况下就是这样。但也可以设置为直接安装为带有临时证书的临时版本。(我自己正在以这种方式调试ad-hoc推送通知。比创建ad-hoc版本、上载到apple等更快。问题是,如果直接作为ad-hoc安装,它不允许进行调试。(应用程序在几秒钟后关闭。但是,我仍然可以打开设备并查看控制台输出)。