Ios Swift:收到通知后添加消息音和振动

时间:2016-07-06 09:56:53

标签: ios swift uilocalnotification ringtone vibration

使用IOS 9和Swift 2

我已经写了一个函数来在需要时调用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)
}

0 个答案:

没有答案