ฉันใช้ส่วนขยายบริการการแจ้งเตือนเพื่อสั่นอุปกรณ์สองครั้ง โหมดพื้นหลังเปิดอยู่ วิธีการด้านล่างใช้งานได้บน 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)
}
}