3

SiriKit可以将INSendPaymentIntent传递给我的应用程序吗?意图必须由我的应用程序处理,而不是在 Siri 扩展中。但是 INSendPaymentIntentResponse 没有 . continueInApp像 INStartAudioCallIntentResponseCode。有 .failureRequiringAppLaunch,但该行为不是首选行为。有什么想法吗?如何将对象传递给我的应用程序?

4

1 回答 1

1

在 IntentHandler 扩展中,当用户单击 Siri UI 扩展中的“发送”按钮时,有一个句柄方法起作用。(Swift 3、iOS 10 和 11)

class IntentHandler: INExtension, INSendPaymentIntentHandling {

    func handle(intent: INSendPaymentIntent, completion: @escaping (INSendPaymentIntentResponse) -> Void) {
        if let _ = intent.payee, let currencyAmount = intent.currencyAmount {
            // Handle the payment here!

            // Create a user activity to pass it to our application
            let userActivity = NSUserActivity(activityType:"myActivityName")

            // Pass parameter dictionary to the userinfo  
            userActivity.userInfo = ["amount": Int(truncating: currencyAmount.amount!)] 

            // By providing a userActivity to the intent response, Siri will open up the app and continue the payment there
            completion(INSendPaymentIntentResponse.init(code: .inProgress, userActivity: userActivity))
        }
    }
}

之后在我们的应用程序中调用 continueUserActivity

-(BOOL)application:(UIApplication *)application continueUserActivity:(NSUserActivity *)userActivity restorationHandler:(void (^)(NSArray * _Nullable))restorationHandler
{
    // Parse userActivity.userInfo parameter to get the amount etc.

    return YES;
}
于 2017-12-18T19:12:31.817 回答