我使用以下行注册通知:
application.registerUserNotificationSettings(UIUserNotificationSettings(forTypes: UIUserNotificationType.Sound|UIUserNotificationType.Alert | UIUserNotificationType.Badge, categories: nil))
此功能设置通知:
func setNotification(verseRecord:NSManagedObject) {
var verseDate :String=verseRecord.valueForKeyPath("date")as String
var timeString : String = "7:00am";
var datetimeString : String = verseDate + " " + timeString
let formatter = NSDateFormatter()
formatter.dateFormat = "yyyy-MM-dd hh:mma"
formatter.timeZone = NSTimeZone.localTimeZone();
var date = formatter.dateFromString(datetimeString)
let lang = NSUserDefaults.standardUserDefaults().stringForKey("language");
var record:String=verseRecord.valueForKeyPath(lang!) as String
var localNotification:UILocalNotification = UILocalNotification()
localNotification.soundName = UILocalNotificationDefaultSoundName
localNotification.alertAction = "Testing notifications on iOS8"
localNotification.alertBody=record
println(date!);
localNotification.timeZone = NSTimeZone.localTimeZone();
localNotification.fireDate=date! IApplication.sharedApplication().scheduleLocalNotification(localNotification)
}
此应用程序仅在iPhone 6和iPad Air 2上崩溃:
localNotification.fireDate=date!