LocalNotification not working in iOS 10

Hi


I have a application built on iOS 9.3. When i install ipa file of this app in iOS 10 devices local notification are not showing. Is this beacuse of deprecation of UILocalNotification API in iOS 10, but how it will impact on local notification if i build against iOS 9.3 ?


Thanks

Aneesh Kumar P

Accepted Reply

Is this beacuse of deprecation of UILocalNotification API in iOS 10 …

That’s very unlikely. UILocalNotification has been deprecated but it still works. I tried this here in my office with a small test app. Here’s the code I used to post the notification:

let t = UIApplication.shared.beginBackgroundTask(expirationHandler: nil)
NSLog("schedule")
Timer.scheduledTimer(withTimeInterval: 5.0, repeats: false) { _ in
    NSLog("fire")
    let note = UILocalNotification()
    note.alertBody = "Hello Cruel World!"
    UIApplication.shared.presentLocalNotificationNow(note)
    UIApplication.shared.endBackgroundTask(t)
}

And don’t forget you have to register for permission to post notifications:

let settings = UIUserNotificationSettings(types: [.alert], categories: nil)
UIApplication.shared.registerUserNotificationSettings(settings)

After setting the deployment target to iOS 10 I get lots of deprecation warnings when building the app, but the app functions just fine (built with Xcode 8.2, running on iOS 10.1.1).

IMPORTANT The code above was part of a quick hack; it is not intended to be production quality.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

Replies

Is this beacuse of deprecation of UILocalNotification API in iOS 10 …

That’s very unlikely. UILocalNotification has been deprecated but it still works. I tried this here in my office with a small test app. Here’s the code I used to post the notification:

let t = UIApplication.shared.beginBackgroundTask(expirationHandler: nil)
NSLog("schedule")
Timer.scheduledTimer(withTimeInterval: 5.0, repeats: false) { _ in
    NSLog("fire")
    let note = UILocalNotification()
    note.alertBody = "Hello Cruel World!"
    UIApplication.shared.presentLocalNotificationNow(note)
    UIApplication.shared.endBackgroundTask(t)
}

And don’t forget you have to register for permission to post notifications:

let settings = UIUserNotificationSettings(types: [.alert], categories: nil)
UIApplication.shared.registerUserNotificationSettings(settings)

After setting the deployment target to iOS 10 I get lots of deprecation warnings when building the app, but the app functions just fine (built with Xcode 8.2, running on iOS 10.1.1).

IMPORTANT The code above was part of a quick hack; it is not intended to be production quality.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

Hi


Thanks for your answer, i have solved the issue, as repeatInterval property of UILocalNotification was set to some garbage value.