【问题标题】:IOS app crashing when recieving pushkit voip notification after force closeIOS 应用程序在强制关闭后收到 pushkit voip 通知时崩溃
【发布时间】:2020-04-09 21:17:46
【问题描述】:

我正在尝试在应用程序关闭时使 pushkit voip 消息正常工作。当应用程序在前台或后台时,调用工作并显示。但是在用户强制终止应用程序后,当收到通知时,应用程序会以信号 9 终止(由用户/ios 终止)。

我该如何解决这个问题?

我的应用中启用了后台获取、voip、音频和推送通知。 还尝试删除所有 Unity 方法,将 Callkit 调用放在 PushRegistry 方法中,在收到通知时创建新提供程序,甚至订阅 UIApplicationDidFinishLaunchingNotification 事件,但没有任何效果。 我已经做到了,因此该应用程序可以在收到 voip 通知时显示呼叫。这是我的代码:

@objcMembers class CallPlugin: UIResponder, UIApplicationDelegate, PKPushRegistryDelegate, CXProviderDelegate {

static var Instance: CallPlugin!
var provider: CXProvider!
var registry:PKPushRegistry!
var uuid:UUID!
var callController: CXCallController!

//class entry point
public static func registerVoIPPush(_ message: String) {
    Instance = CallPlugin()

    //Pushkit
    Instance.registry = PKPushRegistry(queue: DispatchQueue.main)
    Instance.registry.delegate = Instance
    Instance.registry.desiredPushTypes = [PKPushType.voIP]

    //Callkit
    let providerConfiguration = CXProviderConfiguration(localizedName: "testing")
    providerConfiguration.supportsVideo = true
    providerConfiguration.supportedHandleTypes = [.generic]
    Instance.provider = CXProvider(configuration: providerConfiguration)
    Instance.provider.setDelegate(Instance, queue: nil)        

    UnitySendMessage("ResponseHandler", "LogNative", "registration success")
}

//Get token
func pushRegistry( _ registry: PKPushRegistry, didUpdate credentials: PKPushCredentials, for type: PKPushType) {
    if type == PKPushType.voIP {
        let deviceTokenString = credentials.token.map { String(format: "%02.2hhx", $0) }.joined()
        UnitySendMessage("ResponseHandler", "CredentialsRecieved",deviceTokenString)
    }
}       

//Get notification
func pushRegistry( _ registry: PKPushRegistry, didReceiveIncomingPushWith payload: PKPushPayload, for type:PKPushType, completion: @escaping () -> Void) {

    //UnitySendMessage("ResponseHandler", "LogNative", "Got something push")
    reportInComingCallWith(uuidString: "111", handle: "Paul", isVideo: false)
    completion()
}

//show the call
func reportInComingCallWith(uuidString:String,handle:String,isVideo:Bool) {
    //UnitySendMessage("ResponseHandler", "LogNative", "attempting call")
    let callUpdate = CXCallUpdate()        
    callUpdate.remoteHandle = CXHandle(type: .generic, value: handle)        
    callUpdate.hasVideo = false

    uuid = NSUUID() as UUID

    provider.reportNewIncomingCall(with: uuid as UUID, update: callUpdate){ (error) in
        if let error = error {
            UnitySendMessage("ResponseHandler", "LogNative", "error in starting call"+error.localizedDescription)
        }
    }
}

【问题讨论】:

  • 这是您的问题和解决方案。 answer
  • 您是否收到崩溃日志、堆栈跟踪或异常消息? @KasımÖzdemir 这不应该是他们的问题,因为他们正在报告来电
  • 问题是一样的。因此,当应用程序在 2 到 3 次尝试中被禁止时,它就会停止接收 voip。您必须卸载并重新安装应用程序。
  • @KasımÖzdemir 我知道该应用程序被禁止以及如何通过重新安装来修复它,但这不是问题所在。当您被禁止时,该应用程序将停止接收推送。我的应用程序并没有停止获取它们,它只是在发生 SIG-9 时崩溃。即使在重新安装后的第一次尝试。我不认为这是一个权利问题,因为当我收到 VOIP 推送时我确实会调用 Callkit
  • @Paulw11 我没有崩溃报告,因为我还没有将它上传到生产应用商店。调试器并没有真正向我显示任何东西,因为应用程序立即崩溃,调试器只看到信号 9。也许有一种方法可以查看应用程序以前崩溃的本地日志,但我不知道这些。这是一个 Unity 应用程序而不是原生 swift,不会让事情变得更容易检查

标签: ios swift background-process callkit pushkit


【解决方案1】:

问题是我的应用没有及时创建委托和推送注册表对象以使通知得到完全处理。

我通过覆盖应用委托并将通知初始化放在 WillFinishLaunching 中解决了这个问题,如下所示:

-(BOOL)application:(UIApplication *)application willFinishLaunchingWithOptions:(nullable NSDictionary<UIApplicationLaunchOptionsKey,id> *)launchOptions{
   [CallPlugin registerVoIPPush:@"hmm"];
   [super application:application willFinishLaunchingWithOptions:launchOptions];
   return true;
}

这样就可以处理通知了。我试着先把它放在 DidFinishLaunching 中,但是通知已经太晚了,到那时 IOS 正在杀死我的应用程序。

【讨论】:

  • 我有同样的问题,我正在为此使用 Cordova。在我使用的插件中,我没有看到“willFinishLaunchingWithOptions”方法。你是从零开始写的吗?
  • 是的,这个实现是我自己的。您可以添加它或任何其他应用程序委托方法并在主 appController 中覆盖它
猜你喜欢
  • 1970-01-01
  • 2019-09-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多