【发布时间】:2019-10-14 04:49:56
【问题描述】:
我正在安排一个本地通知作为应用程序的警报,我正在设置收到本地通知时的音乐和振动。当应用程序处于前台状态时,一切正常,播放音乐,振动。
但是当应用程序处于后台状态时,只会出现默认通知音乐,即仅一次不重复且会发生单次振动。
func application(_ application: UIApplication, didReceive notification: UILocalNotification) {
//show an alert window
var isSnooze: Bool = false
var soundName: String = ""
var index: Int = -1
if let userInfo = notification.userInfo {
isSnooze = userInfo["snooze"] as! Bool
soundName = userInfo["soundName"] as! String
index = userInfo["index"] as! Int
}
playSound(soundName)
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let mainVC = storyboard.instantiateViewController(withIdentifier: "HomeViewController") as? HomeViewController
mainVC?.notification = notification
mainVC?.isFromNotificationDelegate = true
let nav = UINavigationController(rootViewController: mainVC!)
self.window?.rootViewController = nav
}
【问题讨论】:
标签: ios swift localnotification swift5