I am trying to figure out how to setup a UILocalNotification in swift but I am not having a lot of luck. I am trying this:
var notification = UILocalNotification
Would be nice to also separate out some of the components:
private let kLocalNotificationMessage:String = "Your message goes here!"
private let kLocalNotificationTimeInterval:NSTimeInterval = 5
private func LocalNotification() -> UILocalNotification {
var localNotification:UILocalNotification = UILocalNotification()
localNotification.fireDate = NSDate(timeIntervalSinceNow:kLocalNotificationTimeInterval)
localNotification.alertBody = kLocalNotificationMessage
return localNotification
}
private func ScheduleLocalNotificationIfPossible() {
if (UIApplication.sharedApplication().isRegisteredForRemoteNotifications()) {
UIApplication.sharedApplication().scheduleLocalNotification(LocalNotification())
}
}
Now you can call, ScheduleLocalNotificationIfPossible()
to schedule the local notification if the user has registered for remote notifications.