Local Notification not working since updating to IOS 8 and Xcode 6

不羁的心 提交于 2019-12-21 03:13:34

问题


Has anyone else had problems with local notifications since updating to IOS 8 and Xcode 6? I have my application which was running fine and the notification.firdate was set from date picker and working fine, notification.alertBody showed up fine. Now i've updated it doesn't work. I've added break points and my firedate has a value stored in it. Can anyone please help me?


回答1:


You need to update your code to be able to receive notifications in iOS8. More info here.

Objective-C code:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    if ([UIApplication instancesRespondToSelector:@selector(registerUserNotificationSettings:)]){
    [application registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeAlert|UIUserNotificationTypeBadge|UIUserNotificationTypeSound categories:nil]];
    }
    // Override point for customization after application launch.
    return YES;
}

Swift Code:

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: NSDictionary?) -> Bool {
//registering for sending user various kinds of notifications
application.registerUserNotificationSettings(UIUserNotificationSettings(forTypes: UIUserNotificationType.Sound|UIUserNotificationType.Alert |UIUserNotificationType.Badge, categories: nil)   
// Override point for customization after application launch.     
return true
}



回答2:


In order to receive Local NSNotification, follow the below steps:

  1. Add code into your appDelegate.h in didFinishLaunchingWithOptions method

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


来源:https://stackoverflow.com/questions/26101395/local-notification-not-working-since-updating-to-ios-8-and-xcode-6

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!