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

时间:2017-03-30 13:45:23

标签: ios swift swift3 apple-push-notifications voip

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

我想:声音应响铃,直到用户接听/拒绝来电。

我的解决方案

  • 我应该放置冗长的声音,以便继续保持 振铃?

  • 或者我应该再次发送Voip Push,直到用户取消/参加通话?

  • 接到推后,我应该一次又一次地解雇。

1 个答案:

答案 0 :(得分:0)

我希望一旦你收到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
                    }

        }
    }

}

以终止状态调试pushkit通知

  • 将调试指针放在委托方法
  • 转到编辑方案
  • 选择运行选项,然后选择启动 - &gt;等待可执行文件启动
  • 从后端发送推送工具包有效负载
  • 在设备上获得有效负载后
  • 它会自动调用,调试指针将在委托方法中调用。

enter image description here

您可以在此处参考一些细节。

https://github.com/hasyapanchasara/PushKit_SilentPushNotification