如何将paymentIntent传递给我的应用程序使用SiriKit付款?

时间:2016-10-07 11:37:13

标签: ios payment sirikit

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

1 个答案:

答案 0 :(得分:1)

在IntentHandler Extension中,有一个句柄方法,当用户点击Siri UI Extension中的“发送”按钮时,该方法有效。 (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;
}