iOS VoIP 推送通知在 1-2 秒后自动停止

标签 ios swift swift3 apple-push-notifications voip

我已经实现了 VoIP 推送。一切正常,但当应用程序收到推送时,手机开始响铃,并在 1-2 秒(我的 .wav 文件的长度)后停止。

我想要:声音应该响起,直到用户接受/拒绝调用。

我的解决方案

  • 我应该放置冗长的声音,以便它继续播放 响铃了吗?

  • 或者我应该一次又一次地发送 Voip 推送,直到用户取消/参加调用?

  • 收到推送后,我应该在本地一次又一次地触发推送。

最佳答案

我希望一旦您收到 Pushkit 有效负载,您就可以安排本地通知,并且本地通知具有声音文件。

声音文件在 2 个物体上播放,声音文件的长度(5/10/15 秒)或最长 30 秒。

因此,如果您的声音文件少于 30 秒,请编辑您的声音文件并使其重复直到 30 秒。

如果您想播放声音文件超过 30 秒,那么您可以每 30 秒重新安排一次带有声音文件的本地通知,直到用户接受调用,或者从后端重新发送推送工具包有效负载。

完成所有这些操作后,您的声音文件仍然会在 1/2 秒内停止,然后检查您的应用程序是否在后台崩溃或终止状态。

代码

@available(iOS 8.0, *)
func pushRegistry(registry: PKPushRegistry!, didReceiveIncomingPushWithPayload payload: PKPushPayload!, forType type: String!) {
        // Process the received push

        var arrTemp = [NSObject : AnyObject]()
        arrTemp = payload.dictionaryPayload

        let dict : Dictionary <String, AnyObject> = arrTemp["aps"] as! Dictionary<String, AnyObject>


        if "IfUserHasLoggedInWithApp" // Check this flag then only proceed
        {                

            if UIApplication.sharedApplication().applicationState == UIApplicationState.Background || UIApplication.sharedApplication().applicationState == UIApplicationState.Inactive
            {

                if "CheckForIncomingCall" // Check this flag to know incoming call or something else
                {

                    var strTitle : String = dict["alertTitle"] as? String ?? ""
                    let strBody : String = dict["alertBody"] as? String ?? ""
                    strTitle = strTitle + "\n" + strBody

                    let notificationIncomingCall = UILocalNotification()

                    notificationIncomingCall.fireDate = NSDate(timeIntervalSinceNow: 1)
                    notificationIncomingCall.alertBody =  strTitle
                    notificationIncomingCall.alertAction = "Open"
                    notificationIncomingCall.soundName = "SoundFile.mp3"
                    notificationIncomingCall.category = dict["category"] as? String ?? ""

                    notificationIncomingCall.userInfo = "As per payload you receive"

                    UIApplication.sharedApplication().scheduleLocalNotification(notificationIncomingCall)

                    }
                    else
                    {
                        //  something else
                    }

        }
    }

}

在终止状态下调试推送通知

  • 将调试指针放在委托(delegate)方法上
  • 前往编辑方案
  • 选择运行选项,然后启动 -> 等待可执行文件启动
  • 从后端发送推送套件负载
  • 在设备上获取负载后
  • 它将自动调用,并且调试指针将在委托(delegate)方法处调用。

enter image description here

您可以在此处引用一些详细信息。

https://github.com/hasyapanchasara/PushKit_SilentPushNotification

关于iOS VoIP 推送通知在 1-2 秒后自动停止,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43119767/

相关文章:

iOS 自动布局 UILabel 包装

ios - 将图像转换为帧时占用大量内存

swift3 - 错误 : Cannot use instance member within property initializer - Swift 3

ios - @IBInspectable为类设置Typealias

ios - 为 iOS 构建 Assimp

ios - Cocos2d加载纹理内存问题

ios - 在 Swift 中对元组进行模式匹配时如何解包 Optional?

swift - 如何从 viewcontroller 调用 skscene 的方法

ios - 执行 segue 时,主线程上的 UI 未更新

android - React Native 中的 Picker 和 PickerIOS 错误