davut dev
davut dev

Reputation: 228

Siri - Lang Swift 3, INPayBillIntent is not working, Siri says "You will have to continue in DemoApp, Would you like to open it?"

I'm integrating Sirikit, Bill Payment using the intent:

INPayBillIntentHandling (which was released recently in iOS 10.3+, 27 Mar 2017).

Apple Documentation is here.

Note: I'm using Swift Language, XCode 8.3, Device iPhone 6 with iOS 10.3.3 & Demo Project iOS Deployment target is iOS 10.3 AND also enabled the Siri when asked the permission for the first time and also verified that In Settings, Siri is enabled. When I launch the app on device and say "Bill Payment using DemoApp", Siri says "You can get this information on DemoApp, Do you wish to go to DemoApp?"

Please help me. Thanks in Advance!

So far I did the following steps:

1) Create a Demo Xcode project

2) In Main App Capabilities, Enabled Siri.

3) Added Sirikit extension using

File -> New -> Add Target -> Intent Extension -> Next ->Add ProductName and say Finish

Note: I've disabled the Sirikit UI Extension. 4) In Main AppDelegate.swift added the following:

import Intents

INPreferences.requestSiriAuthorization { (status) in
            if status == INSiriAuthorizationStatus.authorized{
                print("Authorized")
            }else
            {
                print("Not authorized")
            }
        }
        return true

5) In Main app Info.plist, added key NSSiriUsageDescription with usage description

6) In IntentExtension, Info.plist, NSExtension->IntentsSupported->added key INPayBillIntent

7) In IntentHandler.swift, added this:

override func handler(for intent: INIntent) -> Any {
        if intent is INPayBillIntent{
            print("Response: payBill")
         return PayBillHandler()
        }

8) In PayBillHandler.swift added all the delegate methods for INPayBillIntentHandling:

import Intents


class PayBillHandler: NSObject, INPayBillIntentHandling {
    func handle(intent: INPayBillIntent, completion: @escaping (INPayBillIntentResponse) -> Void){

        let userActivity = NSUserActivity(activityType: NSStringFromClass(INPayBillIntent.self))
        let response = INPayBillIntentResponse(code: .ready, userActivity: userActivity)
        completion(response)
    }
    func resolveBillType(for intent: INPayBillIntent, with completion: @escaping (INBillTypeResolutionResult) -> Void) {

        let finalResult = INBillTypeResolutionResult.success(with: .water)
        completion(finalResult)
    }

    func resolveBillPayee(for intent: INPayBillIntent, with completion: @escaping (INBillPayeeResolutionResult) -> Void) {

        let speakableStr = INSpeakableString(identifier: "XXX", spokenPhrase: "XXX", pronunciationHint: "XXX")
        let speakableStr1 = INSpeakableString(identifier: "YYY", spokenPhrase: "YYY", pronunciationHint: "YYY")
        let billPayee = INBillPayee(nickname: speakableStr, number: "10112122112", organizationName: speakableStr1)
        let finalResult = INBillPayeeResolutionResult.success(with: billPayee!)
        completion(finalResult)
    }

    func resolveTransactionNote(for intent: INPayBillIntent, with completion: @escaping (INStringResolutionResult) -> Void) {

        let finalResult = INStringResolutionResult.success(with: "Bill Payment")
        completion(finalResult)

    }
    func resolveDueDate(for intent: INPayBillIntent, with completion: @escaping (INDateComponentsRangeResolutionResult) -> Void) {

        completion(INDateComponentsRangeResolutionResult.notRequired())
    }
    func resolveFromAccount(for intent: INPayBillIntent, with completion: @escaping (INPaymentAccountResolutionResult) -> Void) {

        let speakableStr2 = INSpeakableString(identifier: "Someone", spokenPhrase: "Someone", pronunciationHint: "Someone")
        let speakableStr3 = INSpeakableString(identifier: "", spokenPhrase: "", pronunciationHint: "organisation")
        let fromAccount = INPaymentAccount(nickname: speakableStr2, number: "10112122112", accountType: .credit, organizationName: speakableStr3)
        let finalResult = INPaymentAccountResolutionResult.success(with: fromAccount!)
        completion(finalResult)

    }
    func resolveTransactionAmount(for intent: INPayBillIntent, with completion: @escaping (INPaymentAmountResolutionResult) -> Void) {

        let currencyAmmount = INCurrencyAmount(amount: NSDecimalNumber(string: "100"), currencyCode: "USD")
        let transactionAmt = INPaymentAmount(amountType: .amountDue, amount: currencyAmmount)
        let finalResult = INPaymentAmountResolutionResult.success(with: transactionAmt)
        completion(finalResult)

    }
    func resolveTransactionScheduledDate(for intent: INPayBillIntent, with completion: @escaping (INDateComponentsRangeResolutionResult) -> Void) {

        completion(INDateComponentsRangeResolutionResult.notRequired())
    }

    func confirm(intent: INPayBillIntent, completion: @escaping (INPayBillIntentResponse) -> Void) {

        let response = INPayBillIntentResponse(code: .success, userActivity: nil)
        completion(response)
    }

}

By the way It's the same question as Joao Nunes's question, just modified it for swift and the question still waits for answer, Thanks :)

Upvotes: 1

Views: 615

Answers (2)

Mitali Kulkarni
Mitali Kulkarni

Reputation: 51

I am not sure if you have already found a solution for this. What worked for me was seeing the Deployment Target for SiriExtension to be 10.3+ along with Deployment target in main project 10.3+. Also changing the triggering phrase to "pay bill using demoapp".

The Apple Developer Forum link: https://forums.developer.apple.com/thread/71488

Upvotes: 1

Cherry_thia
Cherry_thia

Reputation: 696

Try installing iOS 11 beta 5 into your test phone.

I am trying out on iOS 11 beta 5 using swift and is a lot more stable.

Upvotes: 0

Related Questions