2

I can successfully launch my app from Siri, but I get that NSUserActivity message in the debugger. I don't recall seeing that message in previous versions, but maybe I wasn't paying attention. What am I missing? Is there something I'm supposed to pop off of some stack? Set some flag?

(I can only launch the app on a device, not in the simulator, but that's a question for another day. Siri tells me something's wrong and to try again.)

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

    if userActivity.activityType != "com.mydomain.myactivity" {
        os_log("The app was called with an invalid activityType")
        return false
    }

    let mainStoryboard = UIStoryboard(name: "Main", bundle: nil)
    
    let tabBarController = self.window!.rootViewController as! UITabBarController
    tabBarController.tabBar.barTintColor = UIColor(red: 184.0/255.0, green: 64.0/255.0, blue: 37.0/255.0, alpha: 0.2)

    guard let tabVCs = tabBarController.viewControllers else {
        os_log("restorationHandler: Can't get tabVCs")
        return false
    }
    
    guard let myTargetViewController = mainStoryboard.instantiateViewController(withIdentifier: "myTargetViewController") as? MyTargetViewController else {
        os_log("restorationHandler: Can't get myTargetViewController from storyboard")
        return false
    }
    
    guard let tab1NavViewController = tabVCs[0] as? UINavigationController else {
        os_log("restorationHandler: Can't get tab1NavViewController from tabVCs")
        return false
    }
    
    tabBarController.selectedIndex = 0
    myTargetViewController.calledFromShortcut = true
    
    tab1NavViewController.pushViewController(myTargetViewController, animated: true)
    
    return true
}
True Brue
  • 33
  • 7

1 Answers1

0

Message is appear because you did not handle userActivity's interaction. Simple handler is shown below:

func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([UIUserActivityRestoring]?) -> Void) -> Bool {
    userActivity.interaction?.donate(completion: { error in
         if let error = error {
             print("Donate Interaction with error: \(error.localizedDescription)")
         } else {
             print("Donate Interaction Success")
         }
    })
    return true
    }
  • 1
    While this code may answer the question, it would be better to include some context, explaining how it works and when to use it. Code-only answers are not useful in the long run. – 7uc1f3r Jan 18 '21 at 12:15
  • 1
    This got rid of the unhandled interaction error, but now I get this one: [Intents] -[NSUserActivity(IntentsAdditions) interaction] Unable to unarchive interactionPayloadData with error: Error Domain=NSCocoaErrorDomain Code=4865 "requested key: 'root'" UserInfo={NSDebugDescription=requested key: 'root'} – True Brue Jan 20 '21 at 22:41
  • @TrueBrue did you ever get a fix for that error? I'm seeing the same one (the "request key: root" one) – johnny Oct 15 '21 at 16:55
  • @johnny kehr sorry, I gave up and learned to live with it. – True Brue Oct 16 '21 at 19:52
  • @johnny did you ever come to a solution? I'm experiencing this still (unable to unarchive interactionPayloadData) – whendon Aug 04 '22 at 18:16
  • I did not. As far as I can tell it's not actually impacting user experience, so I just gave up trying to fix it – johnny Aug 04 '22 at 18:41