添加振动的本地通知背景



我将视频聊天添加到我的应用程序中,并在应用程序在后台时使用PushKit来获得PushNotification。我无法将CallKit用于视频,因为它弄乱了我正在使用的SDK,因此我添加了本地推送通知,该通知从Pushkit代表方法中启动。

我想知道WhatsApp如何通过他们的视频通话来完成。目前,他们显示了推动通知,但以我无法识别的方式显示。推动被两次振动驱动,两秒钟后,有一个新的推动将第一个通知重叠,您可以感觉到另外两个振动,依此类推,直到回答为止。他们如何做到这一点,因为您无法一遍又一遍地添加振动,并且如何在后台删除通知并在后台建立新通知。如果添加[[UIApplication sharedApplication] beginBackgroundTaskWithName:expirationHandler:],则可以使用计时器180秒,但只有当该应用程序处于活动状态时。

因此,真正的问题是如何添加可以重复几次并添加振动的本地通知?

对于 ios 10 及以后。使用 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 }

您可以在将来创建一个通知,当它被调用时,请取消所有先前的通知并重新安排,直到您满意为止。

  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];

然后在应用程序中didReceivelocalnotification:(uilocalnotification *(通知:

- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification {
    application cancelAllLocalNotifications;
}

最新更新