SiriKit INPayBillIntentHandling – Siri dit: "J'aimerais pouvoir le faire, mais <App> ne m'a pas encore mis en place."

J'intègre Sirikit , Bill Payment en utilisant l'intention:

INPayBillIntentHandling (qui a été publié récemment dans iOS 10.3+ , 27 mars 2017).

La documentation Apple est ici .

Note: J'utilise Obj-C Language, XCode 8.3, Device iPhone 6S avec iOS 10.3 & Demo Project iOS cible de deployment est iOS 10.3 ET a également activé le Siri lorsque demandé la permission pour la première fois et également vérifié que dans les parameters, Siri est autorisé.

Lorsque je lance l'application sur l'appareil et que je dis "Bill Payment en utilisant DemoApp", Siri dit "J'aimerais pouvoir le faire, mais DemoApp ne m'a pas encore mis en place"

Aidez-moi, s'il vous plaît. Merci d'avance!

Jusqu'à présent, j'ai fait les étapes suivantes:

1) Créer un projet Demo Xcode

2) Dans Main App Capabilities, Enabled Siri.

3) Ajout de l'extension Sirikit en utilisant

Fichier -> Nouveau -> Ajouter une cible -> Intent Extension -> Suivant -> Ajouter ProductName et dire Terminer

Remarque: J'ai désactivé l'extension Sirikit UI.

4) Dans AppDelegate principal a ajouté ce qui suit:

 #import <Intents/Intents.h> [INPreferences requestSiriAuthorization:^(INSiriAuthorizationStatus status) { NSLog(@"Siri Authorization status...%ld", status); }]; 

5) Dans l'application principale Info.plist, key supplémentaire NSSiriUsageDescription avec description de l'utilisation

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

7) Dans IntentHandler.m, ajouté toutes les methods de délégué pour INPayBillIntentHandling

 @interface IntentHandler () <INPayBillIntentHandling> @end @implementation IntentHandler - (id)handlerForIntent:(INIntent *)intent { // This is the default implementation. If you want different objects to handle different intents, // you can override this and return the handler you want for that particular intent. return self; } - (void)confirmPayBill:(INPayBillIntent *)intent completion:(void (^)(INPayBillIntentResponse *response))completion NS_SWIFT_NAME(confirm(payBill:completion:)) { NSLog(@"\n%s", __func__); INPayBillIntentResponse *response = [[INPayBillIntentResponse alloc] initWithCode:INPayBillIntentResponseCodeSuccess userActivity:nil]; completion(response); } - (void)handlePayBill:(INPayBillIntent *)intent completion:(void (^)(INPayBillIntentResponse *response))completion NS_SWIFT_NAME(handle(payBill:completion:)) { NSLog(@"\n%s", __func__); NSUserActivity *userActivity = [[NSUserActivity alloc] initWithActivityType:NSSsortingngFromClass([INPayBillIntent class])]; INPayBillIntentResponse *response = [[INPayBillIntentResponse alloc] initWithCode:INPayBillIntentResponseCodeReady userActivity:userActivity]; completion(response); } - (void)resolveBillPayeeForPayBill:(INPayBillIntent *)intent withCompletion:(void (^)(INBillPayeeResolutionResult *resolutionResult))completion NS_SWIFT_NAME(resolveBillPayee(forPayBill:with:)) { NSLog(@"\n%s", __func__); INSpeakableSsortingng *speakableStr = [[INSpeakableSsortingng alloc] initWithIdentifier:@"XYZ Bill" spokenPhrase:@"XYZ Bill" pronunciationHint:@"XYZ Bill"]; INSpeakableSsortingng *speakableStr1 = [[INSpeakableSsortingng alloc] initWithIdentifier:@"XYZ Bill Payments" spokenPhrase:@"XYZ Payments" pronunciationHint:@"XYZ Bills"]; INBillPayee *billPayee = [[INBillPayee alloc] initWithNickname:speakableStr number:@"10112122112" organizationName:speakableStr1]; INBillPayeeResolutionResult *finalResult = [INBillPayeeResolutionResult successWithResolvedBillPayee:billPayee]; completion(finalResult); } - (void)resolveFromAccountForPayBill:(INPayBillIntent *)intent withCompletion:(void (^)(INPaymentAccountResolutionResult *resolutionResult))completion NS_SWIFT_NAME(resolveFromAccount(forPayBill:with:)) { NSLog(@"\n%s", __func__); INSpeakableSsortingng *speakableStr2 = [[INSpeakableSsortingng alloc] initWithIdentifier:@"john.smith" spokenPhrase:@"john.smith" pronunciationHint:@"john.smith"]; INSpeakableSsortingng *speakableStr3 = [[INSpeakableSsortingng alloc] initWithIdentifier:@"" spokenPhrase:@"" pronunciationHint:@"organisation"]; INPaymentAccount *fromAccount = [[INPaymentAccount alloc] initWithNickname:speakableStr2 number:@"10112122112" accountType:INAccountTypeCredit organizationName:speakableStr3]; INPaymentAccountResolutionResult *finalResult = [INPaymentAccountResolutionResult successWithResolvedPaymentAccount:fromAccount]; completion(finalResult); } - (void)resolveTransactionAmountForPayBill:(INPayBillIntent *)intent withCompletion:(void (^)(INPaymentAmountResolutionResult *resolutionResult))completion NS_SWIFT_NAME(resolveTransactionAmount(forPayBill:with:)) { NSLog(@"\n%s", __func__); INCurrencyAmount *currencyAmt = [[INCurrencyAmount alloc] initWithAmount:[NSDecimalNumber decimalNumberWithSsortingng:@"100"] currencyCode:@"784"]; INPaymentAmount *transactionAmt = [[INPaymentAmount alloc] initWithAmountType:INAmountTypeAmountDue amount:currencyAmt]; INPaymentAmountResolutionResult *finalResult = [INPaymentAmountResolutionResult successWithResolvedPaymentAmount:transactionAmt]; completion(finalResult); } - (void)resolveTransactionScheduledDateForPayBill:(INPayBillIntent *)intent withCompletion:(void (^)(INDateComponentsRangeResolutionResult *resolutionResult))completion NS_SWIFT_NAME(resolveTransactionScheduledDate(forPayBill:with:)) { completion([INDateComponentsRangeResolutionResult notRequired]); } - (void)resolveTransactionNoteForPayBill:(INPayBillIntent *)intent withCompletion:(void (^)(INSsortingngResolutionResult *resolutionResult))completion NS_SWIFT_NAME(resolveTransactionNote(forPayBill:with:)) { NSLog(@"\n%s", __func__); INSsortingngResolutionResult *finalResult = [INSsortingngResolutionResult successWithResolvedSsortingng:@"Bill Payment"]; completion(finalResult); } - (void)resolveBillTypeForPayBill:(INPayBillIntent *)intent withCompletion:(void (^)(INBillTypeResolutionResult *resolutionResult))completion NS_SWIFT_NAME(resolveBillType(forPayBill:with:)) { NSLog(@"\n%s", __func__); INBillTypeResolutionResult *finalResult = [INBillTypeResolutionResult successWithResolvedValue:INBillTypeElecsortingcity]; completion(finalResult); } - (void)resolveDueDateForPayBill:(INPayBillIntent *)intent withCompletion:(void (^)(INDateComponentsRangeResolutionResult *resolutionResult))completion NS_SWIFT_NAME(resolveDueDate(forPayBill:with:)) { NSLog(@"%s", __func__); completion([INDateComponentsRangeResolutionResult notRequired]); } 

J'ai trouvé le problème, et se trouve sur la ligne suivante:

 INCurrencyAmount *currencyAmt = [[INCurrencyAmount alloc] initWithAmount:[NSDecimalNumber decimalNumberWithSsortingng:@"100"] currencyCode:@"784"]; 

à

 INCurrencyAmount *currencyAmt = [[INCurrencyAmount alloc] initWithAmount:[NSDecimalNumber decimalNumberWithSsortingng:@"100"] currencyCode:@"USD"]; 

Swift 3.0

 let currencyAmmount = INCurrencyAmount(amount: NSDecimalNumber(ssortingng: "100"), currencyCode: "USD") 

Vous utilisez un format de devise incorrect avec les causes Siri pour lancer ce message.

Essayez-le sur iOS 11 version bêta. J'essaie d'utiliser swift sur iOS 11 beta 5, c'est beaucoup plus stable.