-1

I'm adding a video chat to my app and use PushKit to get a pushNotification when the app is in the background. I Can't use the CallKit for video as it mess up the SDK I'm using so I have added a local push notification that fire up from the PushKit delegate method.

I'm wondering how Whatsapp does it with their Video call. For now they are showing a push notification but in a way that I can't recognize. The push is fired up with two vibrations and after two seconds there is a new push that overlaps the first notification and you can feel another two vibrations and so on until you answer. How do they do it as you can't add vibration over and over again and how do they delete the notification and establish a new one in the background as the NSTimer is not working in the background. If I add [[UIApplication sharedApplication] beginBackgroundTaskWithName:expirationHandler:] then I can use the timer for 180 seconds but only if the app was active.

So the real problem is how to add a local notification that can repeat itself few times and also add vibration to it?

NDM
  • 944
  • 9
  • 30

2 Answers2

1

You can create a notification in the future and when it gets called cancel all the previous ones and reschedule until you're satisfied.

  UILocalNotification* localNotification = [[UILocalNotification alloc] init];
                        localNotification.alertBody = body;
                        localNotification.timeZone = [NSTimeZone defaultTimeZone];
                        localNotification.fireDate = [NSDate new]; //<-Set the date here in 10seconds for example
 [[UIApplication sharedApplication] scheduleLocalNotification:localNotification];

Then in application didReceiveLocalNotification:(UILocalNotification *)notification:

- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification {
    application cancelAllLocalNotifications;
}
ahbou
  • 4,710
  • 23
  • 36
  • It is not good enough. didReceiveLocalNotification is getting called after you slide/press to view the notification. I need to build a calling mechanism. – NDM Apr 03 '18 at 11:44
  • @NDM-MobileDEV yes the implementation is up to you. If the answer helped you, consider upvoting to help others. – ahbou Apr 03 '18 at 17:15
  • The implementation didn’t helped me as I wrote In my question. I did a local notification from the PushKit delegate. I need a notification that behave like a ringer – NDM Apr 04 '18 at 10:06
1

For iOS 10 and later. Use UNUserNotificationCenter:

let notificationContent = UNMutableNotificationContent()

// this sets sound + vibration
notificationContent.sound = UNNotificationSound.default

let trigger = UNTimeIntervalNotificationTrigger(
  timeInterval: 1,
  repeats: false
)

let request = UNNotificationRequest(
  identifier: "notification_identifier",
  content: notificationContent,
  trigger: trigger
)

UNUserNotificationCenter.current().add(request) { _ in }
nayooti
  • 395
  • 2
  • 15