为本地通知添加振动背景 [英] Add vibration the background for local notifications

查看:28
本文介绍了为本地通知添加振动背景的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在向我的应用程序添加视频聊天,并在应用程序处于后台时使用 PushKit 获取推送通知.我无法将 CallKit 用于视频,因为它弄乱了我正在使用的 SDK,因此我添加了一个从 PushKit 委托方法触发的本地推送通知.

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.

我想知道 Whatsapp 是如何通过他们的视频通话来实现的.现在他们正在显示推送通知,但我无法识别.推送以两次振动启动,两秒钟后有一个新推送与第一个通知重叠,您可以感觉到另外两次振动,依此类推,直到您回答.他们是怎么做的,因为你不能一遍又一遍地添加振动,他们如何删除通知并在后台建立一个新的通知,因为 NSTimer 不在后台工作.如果我添加 [[UIApplication sharedApplication] beginBackgroundTaskWithName:expirationHandler:] 那么我可以使用计时器 180 秒,但前提是应用程序处于活动状态.

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?

推荐答案

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

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

然后在应用中 didReceiveLocalNotification:(UILocalNotification *)notification:

Then in application didReceiveLocalNotification:(UILocalNotification *)notification:

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

这篇关于为本地通知添加振动背景的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆