我已经写了一个函数来在需要时调用Notification。
如何在收到通知时添加消息音和振动:
func getNotification(message:String)
{
let curentSeting = UIApplication.sharedApplication().currentUserNotificationSettings()
if(curentSeting!.types == .None)
{
let newSeting = UIUserNotificationSettings(forTypes: [.Alert, .Badge, .Sound], categories: nil)
UIApplication.sharedApplication().registerUserNotificationSettings(newSeting)
}
let nfnVar = UILocalNotification()
nfnVar.fireDate = NSDate(timeIntervalSinceNow: 0)
nfnVar.alertBody = message
nfnVar.soundName = UILocalNotificationDefaultSoundName
nfnVar.userInfo = ["NamKey":"NamVey"]
UIApplication.sharedApplication().scheduleLocalNotification(nfnVar)
}