Displaying local notifications on an iPhone
Along with push notifications (which come from a remote server), iOS also supports local notifications, which allow developers to create simple, basic notification alerts that look and act similar to push notifications without the hassle of creating all the certificates and server-side code necessary for push to work. In this recipe, we are going to extend the previous code that we wrote for our background service, and create a local notification when the app is pushed to the background of the system.
How to do it…
Open your project's bg.js
file from the previous recipe, and extend it by adding the following code:
var notification = Ti.App.iOS.scheduleLocalNotification({ alertBody: 'Hey, this is a local notification!', alertAction: "Answer it!", userInfo: { "Hello": "world" }, date: new Date(new Date().getTime() + 5000) });
Now, in your app.js
file, add the following code at the bottom:
Ti.App.iOS.addEventListener('usernotificationsettings...