iOS - 不带 VOIP 的 PushKit / 带 CallKit 的 FCM

iOS - PushKit without VOIP / FCM with CallKit

我正在开发一个使用 CallKit 通知用户的应用程序。但是,我正在使用 APNs 测试应用程序,但它并没有像我预期的那样工作。

流程应该是: 接收 FCM -> 使用 Callkit 创建呼叫 -> 用户接受呼叫 -> 做一些事情。

流程类似于 WHATSAPP 之类的应用程序,但我没有 VOIP,我只需要确保每次有 FCM 时 CALLKIT 都处于激活状态。

但是,目前,如果应用程序处于后台或非活动状态,callkit 将不会启动。

我正在考虑使用 PushKit 来实现它。但是,我对 PushKit 没有任何经验(并且不确定我的应用程序是否会被禁止,根据这个post:PushKit: Can we use push kit(VoiP Push) in Chat Application without using VoiP

func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any],
                 fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
    // If you are receiving a notification message while your app is in the background,
    // this callback will not be fired till the user taps on the notification launching the application.
    // TODO: Handle data of notification
    // With swizzling disabled you must let Messaging know about the message, for Analytics
    // Messaging.messaging().appDidReceiveMessage(userInfo)
    // Print message ID.
    if let messageID = userInfo[gcmMessageIDKey] {
        print("Message ID: \(messageID)")
    }

    let aps = userInfo["aps"] as! [String: AnyObject]
    // 1
    if aps["content-available"] as? Bool == true {
        let uuid = UUID(uuidString: MyVariables.uuid)

        AppDelegate.shared.displayIncomingCall(uuid: uuid!, handle: "Sanoste", hasVideo: false) { _ in}

    }else  {
        completionHandler(UIBackgroundFetchResult.newData)
    }

    // Print full message.
    print(userInfo)

    completionHandler(UIBackgroundFetchResult.newData)

}

上面的代码是我现在用于 CallKit 的代码。

据我了解,call kit + push kit是为了让应用在用户强制退出后激活。您需要发送一个特殊的 VOIP 推送通知,它使用您在 developer.apple.com 的证书、标识符和配置文件部分配置的 voip 推送证书。

所以在我看来,你的做法是倒退的。您应该使用外部服务器发送 voip 推送通知,这将唤醒您的应用程序来处理通知……然后执行您需要的任何其他处理。

此外,您还需要指明您的应用正在使用 VOIP 后台模式。还值得注意的是,如果您实际上没有按预期使用 VOIP,那么苹果很可能会拒绝您进入应用商店。