Sirikit and parent app communication in ios 10 : H

2019-09-09 02:01发布

问题:

I am using Sirikit to integrate with my payment domain app where I need to interact with the app. I read Apple documentation, they asked to use common frameworks. Is it possible to use handoff? if yes then how? How can I call the other viewController which is in parent app from sirikit?

I will really appreciate for any help. Thanks

回答1:

Check SiriKit Programming Guide,

To use handoff, You can create intent response object with NSUserActivity object. While creating NSUserActivity object assign userInfo property to appropriate object that you want,

let userActivity = NSUserActivity()
userActivity.userInfo = ["myKey": myAnyObject]

You will get this NSUserActivity object in parent application AppDelegate,

optional public func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: ([AnyObject]?) -> Swift.Void) -> Bool

Here you can get userInfo object which you can compare as per your requirement and call appropriate viewController.



回答2:

Every user activity object needs a type and we need to define those types in the

info.plist of the application

For Eg.

let userActivity = NSUserActivity(activityType: "uaType")
userActivity.title = "uaTitle"
userActivity.userInfo = ["uaKey": "uaValue"]

You can now access this activity object in AppDelegate as follows

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

        switch userActivity.activityType {
        case "uaType": 
        //Write your logic to access uaKey & uaValue here
        return true
        default: return false
        }
}