[英]Push notification stopped working for IOS 8
我使用支持推送通知功能的企業證書對應用程序進行了簽名。 一切正常,當我將iPhone更新為iOS 8時,推送通知停止工作。 經過調試和很少的研究之后,我知道要添加以下代碼來從iOS 8開始檢索推送令牌。
if ([application respondsToSelector:@selector(registerUserNotificationSettings:)]) //>iOS8
{
UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:(UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert) categories:nil];
[[UIApplication sharedApplication] registerUserNotificationSettings:settings];
}else {// <iOS8
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)];
}
Add following callback methods,
- (void)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings
{
[application registerForRemoteNotifications];
}
- (void)application:(UIApplication *)application handleActionWithIdentifier:(NSString *)identifier forRemoteNotification:(NSDictionary *)userInfo completionHandler:(void(^)())completionHandler
{
//handle the actions
}
但是,我們的應用程序的Appstore版本不會遇到此問題,並且一切正常。 僅在企業認證上有問題嗎?
您[[UIApplication sharedApplication] registerForRemoteNotifications];
了一個行代碼: [[UIApplication sharedApplication] registerForRemoteNotifications];
像這樣的東西:
if ([application respondsToSelector: selector (registerUserNotificationSettings :)]) {
UIUserNotificationSettings * settings = [UIUserNotificationSettings settingsForTypes: UIUserNotificationTypeBadge | UIUserNotificationTypeAlert | UIUserNotificationTypeSound
categories: nil ];
[[UIApplication sharedApplication] registerUserNotificationSettings: settings];
[[UIApplication sharedApplication] registerForRemoteNotifications];
} else {
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:
UIRemoteNotificationTypeBadge |
UIRemoteNotificationTypeAlert |
UIRemoteNotificationTypeSound];
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.