我正在开发一个推送通知的iOS应用程序,它正在通过xcode与device运行时工作正常。但是我尝试生成ipa并安装它无法正常工作。(从后端服务器发送通知,没有生成设备令牌ipa)。我用来注册推送通知的代码。
if ([application respondsToSelector:@selector(isRegisteredForRemoteNotifications)])
{
// iOS 8 Notifications
[application registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge) categories:nil]];
[application registerForRemoteNotifications];
}
else
{
// iOS < 8 Notifications
[application registerForRemoteNotificationTypes:
(UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeSound)];
}
- (void)application:(UIApplication*)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData*)deviceToken
{
NSString *tokenStr = [[[[deviceToken description]
stringByReplacingOccurrencesOfString:@"<" withString:@""]
stringByReplacingOccurrencesOfString:@">" withString:@""]
stringByReplacingOccurrencesOfString:@" " withString:@""];
NSLog(@"Device Token (raw): %@", deviceToken);
NSLog(@"Device Token (string): %@", tokenStr);
NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
[userDefaults setObject:tokenStr forKey:@"deviceToken"];
[userDefaults synchronize];
}
- (void)application:(UIApplication*)application didFailToRegisterForRemoteNotificationsWithError:(NSError*)error
{
[MSTLog printdebug:@"Failed to get token, error: %@", error];
}
我正在使用xcode 6.1。
答案 0 :(得分:3)
要看两件事:
供应配置文件不包含生产推送证书(通过Xcode运行时使用沙箱证书)
确保拨打APNS作品(即gateway.push.apple.com而不是gateway.sandbox.push.apple.com)
答案 1 :(得分:1)
XCode 7.1及更高版本如果您选择Adhoc部署,则iPA已使用分发签名,因此ipa安装将不会收到通知,而通过XCode安装时将收到通知。
答案 2 :(得分:0)