我使用通知服务扩展来振动设备两次,后台模式开启,下面的方法正在运行,iOS 11
但12.0.1
不工作iOS 12.1
背景模式如下:
这是代码:
override func didReceive(_ request: UNNotificationRequest, withContentHandler contentHandler: @escaping (UNNotificationContent) -> Void) {
self.contentHandler = contentHandler
bestAttemptContent = (request.content.mutableCopy() as? UNMutableNotificationContent)
if let bestAttemptContent = bestAttemptContent {
DispatchQueue.main.asyncAfter(deadline: .now() + 0.7) {
AudioServicesPlaySystemSound(kSystemSoundID_Vibrate)
}
DispatchQueue.main.asyncAfter(deadline: .now() + 1.4) {
AudioServicesPlaySystemSound(kSystemSoundID_Vibrate)
}
contentHandler(bestAttemptContent)
}
}