Is it possible to vibrate multiple times on receiving remote push notification in background?

I have push service extension which would be triggered when app receive 
remote notificaiton.I want it to vibrate 8 times in case our users, nurses,
missed the alerts that indicate their patients have some ermergent issues.
But when I do things like below for testing, it just only vibrate with
sound once as ordinary notifiaiton.
func didReceive(_ request: UNNotificationRequest, withContentHandler contentHandler: @escaping (UNNotificationContent) -> Void) {
....
AudioServicesPlayAlertSound(SystemSoundID(kSystemSoundID_Vibrate))
sleep(1)
AudioServicesPlayAlertSound(SystemSoundID(kSystemSoundID_Vibrate))
sleep(1)

....
}
Is there any way to make remote notificaiton vibrate more than once?
Or can I play the sound resouce default in iphone that can trigger
vibration many times? My main goal is to make the notificaiton more noticealbe
for nurses. Since if they missed it, bad things would happen on patients.
Thanks in advance!

Replies

Try a few other approaches rather than 'sleep'. For example:


        [self performSelector:@selector(cancelAlert) withObject:nil afterDelay:15.0f];




dispatch_after(dispatch_time(DISPATCH_TIME_NOW,
                                     1 * NSEC_PER_SEC),
                       dispatch_get_main_queue(),
                       ^{
                           // Do whatever you want here.
                       });

But it might be that you are getting kicked out when you try to add a delay.

More time...let me expand.


It may be that the app is opening in the background and is closing after you try a delay mechanism - if this is the case, perhaps other mechanisms would work. You could try executing something like (I only do Objectove C) this in your didReceive method:


func didReceive(_ request: UNNotificationRequest, withContentHandler conte......
    [self performSelector:@selector(playSound) withObject:nil afterDelay:1.0f]; 
    [self performSelector:@selector(playSound) withObject:nil afterDelay:2.0f]; 
    [self performSelector:@selector(playSound) withObject:nil afterDelay:3.0f]; 
.....


-(void)playSound{
  AudioServicesPlayAlertSound(SystemSoundID(kSystemSoundID_Vibrate))
}


Another approach would be to launch local notifications within the didReceive methhod. That would address the possibility that the app is not kept alive long enough to vibrate after a second. Although I thought you had 30 seconds.