私のアプリケーションでは、私はEURとUSDの通貨のみをサポートしています。したがって、ユーザーがSiriでの支払いをGBPに送金しようとすると、EURとUSDのどちらかを選択するように求められます。私が見る画面上でその後Siriと支払いの統合に関する問題
:
- 100 $
- 100 EUR
私は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]
}
更新:(デイヴィッドの質問に応じて)を再現する方法:
1)はplistファイル内の新しい意思extantion
2)を作成します1つのタイプのインテントを残してください:http://take.ms/pt16N
3)IntentHandlerクラス(xCoによって作成されます)デ)この追加IntentHandlerクラスで)INSendPaymentIntentHandlingプロトコルに
4を確認する必要があります。
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)そして、あなたはシリで起動することができます:あなたが中国の通貨またはその他の規則的ではない通貨を選択した場合ていることがわかりますコードではEURとUSDのどちらかを選択しますが、RESOLVE関数では(後でsiriが通貨をもっと短時間で解決したいときに呼び出されます)、中国通貨が得られます(ボタンのコードを追加する必要はありません
ショートコードが間違っていることは間違いありません。おそらく、あなたは 'Button'のコードや、ユーザーのやり取りを行う要素を投稿したいと思うかもしれません。 –
間違いなしです。私はそれがAppleの間違いかもしれないと思う。なぜなら、もし私がUSDを選択すると、私はすぐにSiriからGBPの通貨を手に入れることになる。 –
大丈夫だが、あなたが正しいと思って、リンゴフレームワーク内のバグですが、このスレッドから何を期待していますか? –