2014-11-03 103 views
9

我有一个应用程序,它使用本地通知和ti用于在以前的版本中正常工作。我已经更新了iOS 8的应用程序并测试并正常工作。将更新提交给应用商店后,少数用户抱怨他们没有收到任何本地通知。但是,我检查的用户数量较多,没有发现任何问题。本地通知不适用于某些用户(iOS 8)

对于出现错误的用户(至少其中一个用户),他们无法在“设置 - > myApp”屏幕中看到“通知”项目;整个选项缺失,不是它被禁用。 “位置”和“使用蜂窝数据”在该屏幕中,但不是通知。我尝试更改“设置 - >通知 - > myApp”下的设置,并按预期工作。

有关如何调试此问题的任何建议将非常有帮助。谢谢!

+0

同一个问题:http://stackoverflow.com/questions/20180806/app-with-local-notifications-not-appearing-in-notification-center-list-in-settin?rq=1 – Mikrasya 2014-11-04 03:43:24

+0

同问题(另一种):http://stackoverflow.com/questions/25827650/app-from-app-store-doesnt-show-up-for-all-users-under-notification-center-loca?rq=1 – Mikrasya 2014-11-04 03:43:49

+1

I有同样的问题。很高兴看到我并不孤单。我希望有人能很快找到答案。 – dadThrowsBolts 2014-11-05 17:44:09

回答

8

尝试此Objective-C的:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions: (NSDictionary *)launchOptions 
{ 
// are you running on iOS8? 
if ([application respondsToSelector:@selector(registerUserNotificationSettings:)]) 
    { 
    UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeBadge|UIUserNotificationTypeAlert|UIUserNotificationTypeSound) categories:nil]; 
    [application registerUserNotificationSettings:settings]; 
    } 
else // iOS 7 or earlier 
    { 
    UIRemoteNotificationType myTypes = UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeSound; 
    [application registerForRemoteNotificationTypes:myTypes]; 
    } 
} 

对于Swift:

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: NSDictionary?) -> Bool { 
// Override point for customization after application launch. 
if(UIApplication.instancesRespondToSelector(Selector("registerUserNotificationSettings:"))) 
{ 
    application.registerUserNotificationSettings(UIUserNotificationSettings(forTypes: UIUserNotificationType.Sound | UIUserNotificationType.Alert | UIUserNotificationType.Badge, categories: nil)) 
} 
else 
{ 
    // 
} 
return true 
} 
+2

谢谢。我选择这个作为正确的答案,因为这是第一个要回答的问题。在发布这些答案之前,我已经实现了相同的代码(registerUserNotificationSettings),并要求我的一个用户使用临时测试进行测试,并确认问题已解决。 **在iOS 8中,本地通知也需要注册**。 – Mikrasya 2014-11-25 04:52:29

1

首先,你必须注册才能使用本地推送通知

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

,那么你可以把本地推送通知通过此

UILocalNotification *notification = [UILocalNotification new]; 
notification.alertBody = @"Local Push !!!"; 
notification.applicationIconBadgeNumber=1; 
[[UIApplication sharedApplication] presentLocalNotificationNow:notification]; 
0
void EnableLocalNotificationIOS8 
{ 
    UIApplication *app = [UIApplication sharedApplication]; 

    if ([app respondsToSelector:@selector(registerUserNotificationSettings:)]) 
    { 
     UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeAlert | UIUserNotificationTypeBadge | UIUserNotificationTypeSound categories:nil]; 
     [app registerUserNotificationSettings:settings]; 
     [app registerForRemoteNotifications]; 
    } 
} 
相关问题