Sirikit始终将美元显示为货币

用户名

我正在为使用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)
}

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

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

SiriKit付款确认货币始终为美元

IntelliJ IDEA 始终将 MockitoAopProxyTargetInterceptor 显示为自动装配

Firefox始终将任何数字输入显示为NAN

Google Analytics(分析)始终将“平均网页加载时间”显示为零

使用get变量的Codeigniter分页始终将第1页显示为当前活动链接

setInterval始终将deltaSec的初始值显示为“未定义”

Android Studio 数据库检查器始终将数据库显示为“已关闭”

在macOS上,为什么“ ps”始终将会话ID显示为“ 0”

始终将JSON解析为数组

为什么idsntp通过所有主机始终将结果始终显示为当前本地时间?

Chrome多功能框建议始终始终将“ Google搜索”显示为第一条建议

查找命令始终将错误级别返回为零

始终将NULL排序为空字符串或0

强制Word 2013始终将文本粘贴为文本

始终将JSON解组为某些类型(字符串)

UILocalNotification始终将日期设置为本地时区

ELB始终将实例报告为不服务

TFS工作项始终将“关闭者”留为空白

Solr 6.2.0始终将布尔值发送为false

始终将JDesktopPane中包含的JPanel设置为始终位于顶部

是否应始终将默认设置为None的参数类型提示为Optional []?

货币检查是欧元还是美元

@QueryParam始终显示为空

如何在货币前将浮动货币显示为带有负号的货币

约会。保存和约会。更新始终将IsMeeting设置为true

使用 th:inline 设置 thymeleaf 变量始终将变量设置为 null

setText()方法是否始终将值设置为字符串?

Jwt Bearer Authentication 中间件始终将 User.Identity.IsAuthenticated 设置为 false

logback日志始终将show_sql设置为false的休眠查询