1
didFinishLaunchingWithOptions method

let notificationSettings = UIUserNotificationSettings(
  forTypes: [.Alert, .Badge, .Sound], categories: nil)         
UIApplication.sharedApplication()
  .registerUserNotificationSettings(notificationSettings)

And in sharedClass

 let localNotification = UILocalNotification()
 localNotification.timeZone = NSTimeZone.localTimeZone()
 localNotification.fireDate = getNextDate(NSDate(), duration: "5")
 localNotification.alertBody = "Temp"
 localNotification.alertAction = "OK"

 UIApplication.sharedApplication()
   .scheduleLocalNotification(localNotification)

I am able to get in foreground but not able to get in background. Anyone have idea about this?

Rajan Maheshwari
  • 14,465
  • 6
  • 64
  • 98
Rock
  • 1,408
  • 1
  • 12
  • 27
  • 2
    Please check the below URL http://stackoverflow.com/questions/16811466/local-notification-in-background – Annie Gupta Oct 14 '16 at 07:15
  • 1
    Check this one http://stackoverflow.com/questions/39713605/getting-local-notifications-to-show-while-app-is-in-foreground-swift-3 – Rajan Maheshwari Oct 14 '16 at 17:01
  • @Rock I don't know what you are doing wrong. Please run this code on Xcode 8.0. Its working absolutely fine. Notifications are coming in foreground and background both – Rajan Maheshwari Oct 14 '16 at 17:05

0 Answers0