2016-10-24 10 views
11

私のアプリケーションでは、私は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が通貨をもっと短時間で解決したいときに呼び出されます)、中国通貨が得られます(ボタンのコードを追加する必要はありません

+1

ショートコードが間違っていることは間違いありません。おそらく、あなたは 'Button'のコードや、ユーザーのやり取りを行う要素を投稿したいと思うかもしれません。 –

+1

間違いなしです。私はそれがAppleの間違いかもしれないと思う。なぜなら、もし私がUSDを選択すると、私はすぐにSiriからGBPの通貨を手に入れることになる。 –

+1

大丈夫だが、あなたが正しいと思って、リンゴフレームワーク内のバグですが、このスレッドから何を期待していますか? –

答えて

3

私はこの問題を作成しました: Siri and wrong currency

あなたがする必要があるのは、ユーザーが選択した通貨を確認することだけです。 、confirmSendPayment法で

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) 
+0

解決方法があればフルコードを追加できますか? (あなたのコードを試すことができます。私の問題はメソッドを確認する前に発生するため、解決メソッドで発生するので、解決メソッドが同じであれば、Confirmメソッドは呼び出されません)。あなたの問題では、@ Reemユーザーは、この解決策は彼を助けなかったと言います。だから私はただコード全体を試したいと思っています –

+1

私はこれについて考えました、私は理解していません:私はcurrencyAmount、彼はGBPの通貨を選ぶことができるので私は彼の通貨を確認することはできませんが、アプリケーションはそれをサポートしていません。しかし、resolveCurrencyAmountメソッドがある場合、通貨がGBPですが、このケースでは私が問題を抱えている唯一のケースですので、完了(INCurrencyAmountResolutionResult.success)を返す必要があるときに、このメソッドでどのように判断するのか分かりません。あなたはほぼ完全なコードを与えることができれば、それは非常に良いでしょう –

+1

は、あなたがINpaymentRecordを作成すべきであるコードにコメントを追加しました – user3292998

0

INSendPaymentIntentResponseインスタンスを作成し、paymentRecordプロパティにINPaymentRecordインスタンスを割り当てます。 ご確認方法が誤って実装されている、あなたはこのようなもので通貨を確認する必要があります。私はこのことをするヘルパーメソッドを作った。

func confirm(sendPayment intent: INSendPaymentIntent, completion: (INSendPaymentIntentResponse) -> Void) { 
    let response = INSendPaymentIntentResponse(code: .Ready, userActivity: nil) 
    response.paymentRecord = getPaymentRecord(fromIntent: intent) 
    completion(response) 
} 

private func getPaymentRecord(fromIntent intent: INSendPaymentIntent) -> INPaymentRecord? { 
    let currencyAmount = INCurrencyAmount(amount: intent.currencyAmount?.amount ?? 0.0, currencyCode: "INR") 
    return INPaymentRecord(payee: intent.payee, payer: nil, currencyAmount: currencyAmount, paymentMethod: nil, note: nil, status: .Pending) 
} 

これが役立ちます。

+0

あなたがINR通貨で0を割り当てる金額を提供しなかった場合は金額と通貨を入力する必要があるので、resolveAmount関数私がこの機能を持っていれば、通貨が間違っていれば確認機能は実行されません。(間違っているのは間違っています) –

+0

「通貨が間違っていれば確認機能は実行されません。 – cheeseRoot

+0

通貨が間違っていると、EURとUSDのどちらかを選択するように求められますが、ユーザーはEURを選択しますが、iOSはGBPを選択したと考えているため、 –

関連する問題