gpt4 book ai didi

ios - 诗丽吉总是将美元显示为货币

转载 作者:行者123 更新时间:2023-11-28 19:32:35 25 4
gpt4 key购买 nike

我正在对使用 Siri 进行支付的概念进行验证。

除了 Siri 总是说美元而不是欧元,我的一切都正常。我真的是说给蒂姆寄 5 欧元。但是 Siri 从中赚钱。

这是我的代码:

class SendPaymentIntentHandler: NSObject, INSendPaymentIntentHandling {

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

if let payee = intent.payee, let currencyAmount = intent.currencyAmount {
print("CurrencyAmount \(currencyAmount.amount) currencyCode \(currencyAmount.currencyCode)")

let bundle = Bundle(for: SendPaymentIntentHandler.self)
let bundleIdentifier = bundle.object(forInfoDictionaryKey: "CFBundleIdentifier") as? String ?? "KBCPaymentIntent"
print("BundleIdentifier \(bundleIdentifier)")

let activity = NSUserActivity.init(activityType: bundleIdentifier)
let response = INSendPaymentIntentResponse(code: .success, userActivity: activity)
let paymentRecord = INPaymentRecord(payee: payee, payer: nil, currencyAmount: currencyAmount, paymentMethod: nil, note: intent.note, status: .pending)
response.paymentRecord = paymentRecord

completion(response)
} else {
// TODO what do we need to do?
print("Handle Failed")
completion(INSendPaymentIntentResponse.init(code: .failure, userActivity: nil))
}
}

func resolvePayee(forSendPayment intent: INSendPaymentIntent, with completion: @escaping (INPersonResolutionResult) -> Void) {
if let payee = intent.payee {
print("User to pay DISPLAYNAME: \(payee.displayName) FAMILYNAME: \(payee.nameComponents?.familyName ?? "not set") GIVENNAME: \(payee.nameComponents?.givenName ?? "Not set")")
let recipientMatched = self.inPerson()
completion(INPersonResolutionResult.success(with: recipientMatched))
}
}

func resolveCurrencyAmount(forSendPayment intent: INSendPaymentIntent, with completion: @escaping (INCurrencyAmountResolutionResult) -> Void) {
if let amount = intent.currencyAmount?.amount {
// TODO check if it's always EUR
print("Amount is resolved")
completion(INCurrencyAmountResolutionResult.success(with: INCurrencyAmount(amount: amount, currencyCode: "EUR")))
} else {
print("Amount is not resolved")
completion(INCurrencyAmountResolutionResult.success(with: INCurrencyAmount(amount: NSDecimalNumber.zero, currencyCode: "EUR")))
}
}

public func inPerson() -> INPerson {
let nameFormatter = PersonNameComponentsFormatter()

if let nameComponents = nameFormatter.personNameComponents(from: "Tim") {
let personHandle = INPersonHandle(value: "dd", type: .phoneNumber)
let person = INPerson.init(personHandle: personHandle, nameComponents: nameComponents, displayName: "Tim", image: nil, contactIdentifier: nil, customIdentifier: nil)

return person
} else {
let personHandle = INPersonHandle(value: "dd", type: .phoneNumber)
let person = INPerson.init(personHandle: personHandle, nameComponents: nil, displayName: "Tim", image: nil, contactIdentifier: nil, customIdentifier: nil)
return person
}
}
}

有人知道我做错了什么吗?

最佳答案

我找到了解决方案。

在 resolveCurrencyAmount 方法之后,您需要像这样确认它:

func confirm(sendPayment intent: INSendPaymentIntent, completion: @escaping (INSendPaymentIntentResponse) -> Void) {
print("Confirm sendPayment intent")
let response = INSendPaymentIntentResponse(code: .ready, userActivity: nil)
response.paymentRecord = INPaymentRecord(payee: intent.payee, payer: nil, currencyAmount: intent.currencyAmount, paymentMethod: nil, note: intent.note, status: .pending)

completion(response)
}

然后它会显示正确的货币。

关于ios - 诗丽吉总是将美元显示为货币,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42269079/

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