Search code examples
iosswiftfirebasefirebase-cloud-messagingcallkit

iOS - PushKit without VOIP / FCM with CallKit


I am developing an application which uses CallKit for notify users. However, I am testing the application with APNs and it is not working as I expected.

The flow should be: Receive FCM -> Create a call with Callkit -> user accept the call -> do something.

THE FLOW IS SIMILAR WITH APP LIKE WHATSAPP BUT I DON'T HAVE VOIP, I JUST NEED TO MAKE SURE CALLKIT IS ACTIVATE EVERY TIME THERE IS A FCM.

However, currently, if the app is in background or inactive, the callkit will not start.

I am thinking of using PushKit for implement that. However, I have no experience what so ever with PushKit (and not sure if my app will be banned or not, according to this 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)

}

The code above is what I am using right now for CallKit.


Solution

  • From what I understand about call kit + push kit is that in order to get the app to become active after a user force quits it. You need to send a special VOIP push notification that is uses your voip push cert configured in Certificates, Identifiers & Profiles section of developer.apple.com.

    So from what I see is that your approach is backwards. You should be using an external server to send a voip push notification which will wake your app to handle the notification... then do any additional processing you need.

    Additionally, you will also need to indicate that your app is using the VOIP background modes. And it's also worth noting that if you are not actually using VOIP as intended, then apple will most likely reject you from the app store.