Created
September 24, 2011 22:01
-
-
Save raulriera/1239923 to your computer and use it in GitHub Desktop.
Local Notification
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This piece of code makes the notification run "once" after 3 seconds of calling the | |
// function, but it SHOULD re appear the next day and so on right? it doesn't | |
(function() { | |
app.model.scheduleLocalNotification = function() { | |
// Set the target date | |
var d = new Date(); | |
// Here we schedule a notification to popup everyday when the app was first launched | |
var notification = Ti.App.iOS.scheduleLocalNotification({ | |
alertBody: L("notification_message"), | |
alertAction: L("notification_button_label"), | |
userInfo: { | |
"fetchNewChallenge": true | |
}, | |
repeat: "daily", | |
sound: "/audio/ding.caf", | |
badge: 1, | |
date: new Date(new Date().getTime() + 3000) | |
}); | |
// Debug info | |
Ti.API.info("Local notification scheduled daily at " + d); | |
// Set a global property | |
Ti.App.Properties.setBool("isLocalNotificationSet", true); | |
Ti.App.iOS.addEventListener('notification',function(){ | |
Ti.API.info('Local notification received'); | |
}); | |
}; | |
// Check if the local notification has not been set before | |
if (!Ti.App.Properties.hasProperty('isLocalNotificationSet')) { | |
app.model.scheduleLocalNotification(); | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment