Search code examples
iosswiftcallkitsirikitnsuseractivity

NSUserActivity: Which method will be called when user will tap (or will make call ) from recent log of my app?


I am implementing CallKit in swift and I'm facing a problem with NSUserActivity while making a call directly from the recent log.

While tapping on my app entry in the recent log, my app is launching but any method of AppDelegate is not calling.

I have turned on Siri from application capabilities and have added NSUserActivityType in info.plist. I've added INStartAudioCallIntent and INStartVideoCallIntent inside NSUserActivityType. The method I've implemented inside AppDelegate class is the following:

func application(_ application: UIApplication,
                 continue userActivity: NSUserActivity,
                 restorationHandler: @escaping ([Any]?) -> Void) -> Bool {
    print("Restoration")

    return true
}

When tapping on any entry of my app from the recent log the following line is printed in the debugger console.

AppDelegate-BAA416CD-ED84-4161-A054-B2192AFAD47A application:continueUserActivity:restorationHandler:] has an interaction attached but it is not handled


Solution

  • Change the signature of the function, i.e. the restorationHandler parameter type from ([Any]?) -> Void to ([UIUserActivityRestoring]?) -> Void

    func application(_ application: UIApplication,
                     continue userActivity: NSUserActivity,
                     restorationHandler: @escaping ([UIUserActivityRestoring]?) -> Void) -> Bool {
        //if its a call
    
        guard let handle = userActivity.startCallHandle else {
            print("Could not determine start call handle from user activity: \(userActivity)")
            return false
        }
    }
    

    For more details: https://github.com/Lax/Learn-iOS-Swift-by-Examples/blob/master/Speakerbox/Speakerbox/AppDelegate.swift

    I changed the signature and it worked for me.