【发布时间】:2014-12-29 11:22:18
【问题描述】:
我正在使用推送通知开发 iPhone 应用程序。我遇到了通知问题,我在 iOS 6、7、8.1、8.1.2 中成功获取了设备令牌 ID,但对于我的 iPhone 6 和 iOS 8.0。
所以在我的推送通知方法“didRegisterForRemoteNotificationsWithDeviceToken”中,令牌 ID 返回 nil。所以,我无法获得推送通知。我不知道是什么问题。
这是我的代码:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
if ([application respondsToSelector:@selector(registerUserNotificationSettings:)]) {
[application registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeAlert|UIUserNotificationTypeBadge|UIUserNotificationTypeSound categories:nil]];
}
else{
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:
(UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)];
}
.
.
.
.
[self.window makeKeyAndVisible];
return YES;
}
- (void)application:(UIApplication*)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData*)deviceToken
{
NSString *newToken = [deviceToken description];
newToken = [newToken stringByTrimmingCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@"<>"]];
newToken = [newToken stringByReplacingOccurrencesOfString:@" " withString:@""];
[GlobalVariables proTrain].deviceToken = newToken;
NSLog(@"device token id = %@", newToken);
}
- (void)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings {
[application registerForRemoteNotifications];
}
【问题讨论】:
标签: ios ios8 push-notification apple-push-notifications