2017-02-16 8 views
0

Siri에서 Payments를 수행 할 때 개념 증명을하고 있습니다.Sirikit은 항상 통화로 달러를 표시합니다.

나는 Siri가 항상 유로 대신 달러를 말한다는 것을 제외하고는 모든 것이 작동한다. 나는 Tim에게 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 
     } 
    } 
} 

누군가가 내가 잘못 알고 있나요?

+0

설정에 따라 지역에 따라 다르다고 생각합니다. 나는 시리 (Siri)에게 물어 보았다. 얼마나 많은 돈이 루피 (Rupees)의 값으로 응답했는지, 인도 통화 (India Currency). –

답변

2

해결책을 찾았습니다. 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) 
} 

는 그 다음 올바른 통화를 보여줍니다.

0

통화 코드는 INPaymentMethod 클래스 자체에서 설정할 수 있습니다.

 let paymentMethod = INPaymentMethod(type: .credit, name: "Visa Platinum", identificationHint: "•••• •••• •••• 1234", icon: INImage(named: "creditCardImage")) 
     let applePay = INPaymentMethod.applePay() // If you support Pay and the user has an Pay payment method set in your parent app 
     response.paymentMethods = [ paymentMethod, applePay ] 
     paymentMethod.currencyCode = "INR"