Send Local Notifications while App is running in the background Swift 2.0

后端 未结 1 1787
遥遥无期
遥遥无期 2020-12-16 03:18

I am trying to send the user a \'Push Notification style\' Alert when the user minimizes the app (by clicking on the iPhone\'s Home Button or by locking the phone as well).

相关标签:
1条回答
  • 2020-12-16 03:54

    By default NSTimer does work only in simulator. Try to add this to your AppDelegate file:

    func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
    application.registerUserNotificationSettings(UIUserNotificationSettings(forTypes: [.Sound, .Alert, .Badge], categories: nil))
    
    application.beginBackgroundTaskWithName("showNotification", expirationHandler: nil)
    
            return true
        }
    
    0 讨论(0)
提交回复
热议问题