我正在使用以下意图集成 Sirikit 和Bill Payment:INPayBillIntentHandling
(最近在 iOS 10.3+ 中发布,2017年3月27日)。
苹果文档是here。
当我在设备上启动该应用并说“使用DemoApp支付账单”时,Siri表示“我希望可以,但是DemoApp尚未对此进行设置”
请帮我。提前致谢!
到目前为止,我已执行以下步骤:
1)创建一个演示Xcode项目
2)在主要应用程序功能中,启用Siri。
3)使用添加了Sirikit扩展
4)在主AppDelegate中添加了以下内容:
#import <Intents/Intents.h>
[INPreferences requestSiriAuthorization:^(INSiriAuthorizationStatus status) {
NSLog(@"Siri Authorization status...%ld", status);
}];
5)在主应用程序Info.plist中,添加了带有用法说明的 key
NSSiriUsageDescription
6)IntentExtension,Info.plist,
NSExtension->IntentsSupported->added key INPayBillIntent
7)在IntentHandler.m中,为INPayBillIntentHandling添加了所有委托(delegate)方法
@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:NSStringFromClass([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__);
INSpeakableString *speakableStr = [[INSpeakableString alloc] initWithIdentifier:@"XYZ Bill" spokenPhrase:@"XYZ Bill" pronunciationHint:@"XYZ Bill"];
INSpeakableString *speakableStr1 = [[INSpeakableString 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__);
INSpeakableString *speakableStr2 = [[INSpeakableString alloc] initWithIdentifier:@"john.smith" spokenPhrase:@"john.smith" pronunciationHint:@"john.smith"];
INSpeakableString *speakableStr3 = [[INSpeakableString 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 decimalNumberWithString:@"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 (^)(INStringResolutionResult *resolutionResult))completion NS_SWIFT_NAME(resolveTransactionNote(forPayBill:with:)) {
NSLog(@"\n%s", __func__);
INStringResolutionResult *finalResult = [INStringResolutionResult successWithResolvedString:@"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:INBillTypeElectricity];
completion(finalResult);
}
- (void)resolveDueDateForPayBill:(INPayBillIntent *)intent
withCompletion:(void (^)(INDateComponentsRangeResolutionResult *resolutionResult))completion NS_SWIFT_NAME(resolveDueDate(forPayBill:with:)) {
NSLog(@"%s", __func__);
completion([INDateComponentsRangeResolutionResult notRequired]);
}
最佳答案
我发现了问题,并在以下行中找到:
INCurrencyAmount *currencyAmt = [[INCurrencyAmount alloc] initWithAmount:[NSDecimalNumber decimalNumberWithString:@"100"] currencyCode:@"784"];
至
INCurrencyAmount *currencyAmt = [[INCurrencyAmount alloc] initWithAmount:[NSDecimalNumber decimalNumberWithString:@"100"] currencyCode:@"USD"];
斯威夫特3.0
let currencyAmmount = INCurrencyAmount(amount: NSDecimalNumber(string: "100"), currencyCode: "USD")
您使用的货币格式不正确,导致Siri抛出此消息。
关于ios - SiriKit INPayBillIntentHandling-Siri说, "I wish I could, but <App> hasn'尚未与我建立联系。”,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/43066231/