【问题标题】:How to pass paymentIntent to my app use SiriKit on payment?如何将 paymentIntent 传递给我的应用在付款时使用 SiriKit?
【发布时间】:2017-02-16 09:31:57
【问题描述】:

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

【问题讨论】:

    标签: ios payment sirikit


    【解决方案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;
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-08-18
      • 2012-03-18
      • 2019-09-30
      • 2020-04-17
      • 2017-11-14
      • 2021-10-13
      • 1970-01-01
      • 2021-02-18
      相关资源
      最近更新 更多