-
Re: LocalNotification not working in iOS 10
eskimo Dec 15, 2016 1:43 AM (in response to Aneesh Kumar P)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/Hardwarelet myEmail = "eskimo" + "1" + "@apple.com"
-
Re: LocalNotification not working in iOS 10
Aneesh Kumar P Dec 20, 2016 11:10 PM (in response to eskimo)Hi
Thanks for your answer, i have solved the issue, as repeatInterval property of UILocalNotification was set to some garbage value.
-