集成極光IM時(shí)候的需求 要像微信一樣 在前端收到推送時(shí),聲音和震動(dòng)分開(kāi)的需求
使用系統(tǒng)的語(yǔ)音進(jìn)行開(kāi)啟 震動(dòng)也是一個(gè)語(yǔ)音 kSystemSoundID_Vibrate 可以自己錄個(gè)無(wú)聲語(yǔ)音 然后進(jìn)行設(shè)置 然后根據(jù)需求發(fā)送不同的聲音自定義
播放震動(dòng)
AudioServicesPlaySystemSound(kSystemSoundID_Vibrate)
靜音效果
//音效文件路徑
let path = Bundle.main.path(forResource: "noSound", ofType: "wav")
//組裝并播放音效
var soundID:SystemSoundID = 0;
let filePath = NSURL.fileURL(withPath: path!, isDirectory: false)
AudioServicesCreateSystemSoundID(filePath as CFURL, &soundID)
AudioServicesPlaySystemSound(soundID)
只有系統(tǒng)聲音
var soundID:SystemSoundID = 0;
let path = "/System/Library/Audio/UISounds/sms-received1.caf"
let filePath = NSURL.fileURL(withPath: path, isDirectory: false)
AudioServicesCreateSystemSoundID(filePath as CFURL, &soundID)
AudioServicesPlaySystemSound(soundID)
系統(tǒng)聲音加震動(dòng)
completionHandler? (Int(UNNotificationPresentationOptions.badge.rawValue | UNNotificationPresentationOptions.sound.rawValue