0

I use Notification Service Extension to vibrate device two time, background mode is on, below method is working on iOS 11 & 12.0.1 but not working in iOS 12.1

background modes are below:

enter image description here

here is the code :

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)
}

}

chirag bhalara
  • 203
  • 1
  • 10

1 Answers1

0

I found out that it won't work if the vibration settings have been off. (Goto System Settings \ Sounds => Vibrate on Ring.)

If you send out a push notification with a sound, and badge only, but no text alert, it will play the sound if your phone is not in silent mode, however it will NOT play the sound if it IS in silent mode.

Now, if you add a text alert to that notification, it plays the sound fine, even while in vibrate mode.

There may be some more testing to be done around this. Eg: if you send custom key/value pairs does it play the sound then? Not sure.

AtulParmar
  • 4,358
  • 1
  • 24
  • 45
  • Good research @AtulParmar but notification has all the things text,alert,sound And as i mention it's work with another iphone 7 (iOS 12.0), issue raise only in iOS 12.1 – chirag bhalara Dec 06 '18 at 12:57
  • 1
    Have you checked 'Audio,AirPlay and Picture in Picture' within the 'Background Modes' of your apps Capabilities https://stackoverflow.com/questions/21173798/ios-background-service-vibrate-phone – AtulParmar Dec 06 '18 at 13:08
  • Yes it's added @AtulParmar – chirag bhalara Dec 06 '18 at 13:11