0

我使用通知服务扩展来振动设备两次,后台模式开启,下面的方法正在运行,iOS 1112.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)
}

}

4

1 回答 1

0

我发现如果振动设置已关闭,它将无法正常工作。(转到系统设置\声音=>响铃振动。)

如果您发送带有声音的推送通知,只有徽章,但没有文字提示,如果您的手机未处于静音模式,它将播放声音,但如果它处于静音模式,它将不会播放声音。

现在,如果您向该通知添加文本警报,它会正常播放声音,即使在振动模式下也是如此。

可能还有更多的测试要做。例如:如果您发送自定义键/值对,它会播放声音吗?没有把握。

于 2018-12-06T12:52:10.307 回答