gpt4 book ai didi

ios - 支付问题的 Siri 集成

转载 作者:IT王子 更新时间:2023-10-29 05:27:45 26 4
gpt4 key购买 nike

在我的应用程序中,我只支持欧元和美元货币。因此,例如,当用户尝试使用 Siri 将付款转为英镑时,我会要求他在欧元和美元之间做出选择。

在那之后我在屏幕上看到:

  • 100 元
  • 100 欧元

如果我在 intent.currencyAmount!.currencyCode 中选择 100$,我总是有 GBP(但用户选择了美元)。这很奇怪。

这是我的代码:

func resolveCurrencyAmount(forSendPayment intent: INSendPaymentIntent, with completion: @escaping (INCurrencyAmountResolutionResult) -> Void) {
if let currencyAmount = intent.currencyAmount { // need to check if we have proper value
if let amount = currencyAmount.amount {

if amount.doubleValue == 0 { // wrong amount
completion(INCurrencyAmountResolutionResult.unsupported())
return
}

if let currencyCode = currencyAmount.currencyCode {
if let _ = EnumCurrency(rawValue: currencyCode) { // we found currency code that we know
completion(INCurrencyAmountResolutionResult.success(with: INCurrencyAmount(amount: NSDecimalNumber(value: abs(amount.doubleValue)), currencyCode: currencyCode)))
return
}
}


// if we are here so we don't have proper currency, try to offer user to choose the same amount but with all possible currencies
let disambiguationArray: [INCurrencyAmount] = EnumCurrency.allValues.map({ (currency) -> INCurrencyAmount in
return INCurrencyAmount(amount: NSDecimalNumber(value: abs(amount.doubleValue)), currencyCode: currency.rawValue)
})
completion(INCurrencyAmountResolutionResult.disambiguation(with: disambiguationArray))
}
}
else { // we don't have value
completion(INCurrencyAmountResolutionResult.needsValue())
}
}

enum EnumCurrency : String {
case EUR = "EUR"
case USD = "USD"

static let allValues = [EUR, USD]
}

更新:如何重现(根据 David 的问题):

1) 创建一个新的意图扩展

2) 在 plist 文件中只留下一种类型的意图:http://take.ms/pt16N

3) 您的 IntentHandler 类(将由 xCode 创建)必须确认 INSendPaymentIntentHandling 协议(protocol)

4) 在 IntentHandler 类中添加:

func resolveCurrencyAmount(forSendPayment intent: INSendPaymentIntent, with completion: @escaping (INCurrencyAmountResolutionResult) -> Void) {
if let currencyAmount = intent.currencyAmount { // need to check if we have proper value
if let amount = currencyAmount.amount {

if amount.doubleValue == 0 { // wrong amount


completion(INCurrencyAmountResolutionResult.unsupported())
return
}

if let currencyCode = currencyAmount.currencyCode {
if let _ = EnumCurrency(rawValue: currencyCode) { // we found currency code that we know
completion(INCurrencyAmountResolutionResult.success(with: INCurrencyAmount(amount: NSDecimalNumber(value: abs(amount.doubleValue)), currencyCode: currencyCode)))
return
}
}


// if we are here so we don't have proper currency, try to offer user to choose the same amount but with all possible currencies
let disambiguationArray: [INCurrencyAmount] = EnumCurrency.allValues.map({ (currency) -> INCurrencyAmount in
return INCurrencyAmount(amount: NSDecimalNumber(value: abs(amount.doubleValue)), currencyCode: currency.rawValue)
})
completion(INCurrencyAmountResolutionResult.disambiguation(with: disambiguationArray))
}
}
else { // we don't have value
completion(INCurrencyAmountResolutionResult.needsValue())
}
}

enum EnumCurrency : String {
case EUR = "EUR"
case USD = "USD"

static let allValues = [EUR, USD]
}

// MARK: - Confirm

func confirm(sendPayment intent: INSendPaymentIntent, completion: @escaping (INSendPaymentIntentResponse) -> Void) {
// success
completion(INSendPaymentIntentResponse(code: INSendPaymentIntentResponseCode.success, userActivity: nil))

}

// MARK: - Handle

func handle(sendPayment intent: INSendPaymentIntent, completion: @escaping (INSendPaymentIntentResponse) -> Void) {

// just for test
completion(INSendPaymentIntentResponse(code: .failureRequiringAppLaunch, userActivity: userActivity))
}

5) 你可以用 Siri 启动:你会看到,如果你选择中国货币或任何其他非常规货币,然后我在代码中让你在 EUR 和 USD 之间进行选择,但之后在 RESOLVE 函数中(当siri 想在更多时间解析货币)你会得到中国货币(所以你不需要像大卫问的那样为按钮添加任何代码,因为所有按钮接口(interface)将由 Siri 提供)

最佳答案

我创建了这个问题: Siri and wrong currency

您需要做的就是确认用户选择的货币。您的确认方法实现错误,您应该用这样的方式确认货币:

let response = INSendPaymentIntentResponse(code: .ready, userActivity: nil)
response.paymentRecord = INPaymentRecord(
payee: intent.payee,
payer: nil,
currencyAmount: intent.currencyAmount,
paymentMethod: nil,
note: nil,
status: .pending,
feeAmount: nil)
completion(response)

关于ios - 支付问题的 Siri 集成,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40215098/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com