ios - 如何将 paymentIntent 传递到我的应用程序并使用 SiriKit 进行付款?

标签 ios payment sirikit

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

最佳答案

在 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;
}

关于ios - 如何将 paymentIntent 传递到我的应用程序并使用 SiriKit 进行付款?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39916296/

相关文章:

ios - 委派为 nil ,MVVM 方法,两个 VC 具有相同的 VM。 iOS, swift

html - iPhone 电子邮件客户端中 html 表中的蓝色下划线

security - iframe 中的支付网关 (eWay) 页面 - 有任何安全问题吗?

objective-c - HDFC iOS SDK 崩溃以集成到 Swift 中?

ios - 使用 IntentsUI 扩展中的 URL 打开应用程序

ios - 关闭键盘后,键盘网格仍然可见,iOS7

ios - Ionic 3.x : Push notification on iOS not working (works on Android? ) Ionic Native 插件推送

payment-gateway - Bluesnap 市场 - 如何阻止供应商销售?

ios - 如何根据 Intent 类型在 Sirikit 扩展中推送不同的 IntentViewController?

ios - 关于使用 `handleInApp` WorkoutIntentResponseCode Siri 总是说 "Sorry,you' ll need to continue in App“不像弃用的 `continueInApp`