Local notifications are not working on device but working on simulator

人走茶凉 提交于 2019-12-05 12:50:46
Ivan

I see that you're using Objective-C. Considering this question was asked a year ago, you've probably either figured this out or you're using Swift 2.0 now. I had the same issue and I was able to resolve it with Swift 2.0 by adding the following code.

AppDelegate.swift:

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
    // Override point for customization after application launch.

    application.registerUserNotificationSettings(UIUserNotificationSettings(forTypes: [.Alert, .Badge, .Sound], categories: nil))
    application.beginBackgroundTaskWithName("showNotification", expirationHandler: nil)

    return true
}

You can see my full answer here.

The fact that you get the notification in the iOS 8.0+ Simulator is a limitation of the iOS Simulator runtime. On device, when your app is in the background, it is not actually running, the task gets suspended. In the iOS Simulator, the task continues to run in the background.

Sometimes we don't get Local notification instantly but after 1hour almost I get notification. So, wait for a particular time then again check.

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