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

问题描述 投票:3回答:1

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

ios payment sirikit
1个回答
1
投票

在IntentHandler Extension中,有一个handle方法,当用户单击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;
}
© www.soinside.com 2019 - 2024. All rights reserved.