iOS中的Siri Integration用于付款转帐,无需指定收款人

时间:2017-02-27 16:22:21

标签: ios sirikit

我必须在我们申请付款的申请中整合Siri,而无需指定付款人。这可能吗?我怎么能这样做?

RequestPaymentIntentHandler

#import "RequestPaymentIntentHandler.h"

@implementation RequestPaymentIntentHandler

#pragma mark - Resolve

-(void)resolvePayerForRequestPayment:(INRequestPaymentIntent *)intent withCompletion:(void (^)(INPersonResolutionResult * _Nonnull))completion {

    completion([INPersonResolutionResult notRequired]);
}

-(void)resolveNoteForRequestPayment:(INRequestPaymentIntent *)intent withCompletion:(void (^)(INStringResolutionResult * _Nonnull))completion {

    completion([INStringResolutionResult notRequired]);
}

-(void)resolveCurrencyAmountForRequestPayment:(INRequestPaymentIntent *)intent withCompletion:(void (^)(INCurrencyAmountResolutionResult * _Nonnull))completion {

    if (! intent.currencyAmount || intent.currencyAmount.amount.doubleValue <= 0)
        completion([INCurrencyAmountResolutionResult needsValue]);

    else
        completion([INCurrencyAmountResolutionResult successWithResolvedCurrencyAmount:intent.currencyAmount]);
}

#pragma mark - Confirm

-(void)confirmRequestPayment:(INRequestPaymentIntent *)intent completion:(void (^)(INRequestPaymentIntentResponse * _Nonnull))completion {

    if (! intent || ! intent.currencyAmount)
        completion([[INRequestPaymentIntentResponse alloc] initWithCode:INRequestPaymentIntentResponseCodeFailure userActivity:nil]);

    else
        completion([[INRequestPaymentIntentResponse alloc] initWithCode:INRequestPaymentIntentResponseCodeSuccess userActivity:nil]);
}

#pragma mark - Handle

-(void)handleRequestPayment:(INRequestPaymentIntent *)intent completion:(void (^)(INRequestPaymentIntentResponse * _Nonnull))completion {

    INRequestPaymentIntentResponse *response;

    if (! intent || ! intent.currencyAmount) {

        NSLog(@"NO INTENT ");

        response = [[INRequestPaymentIntentResponse alloc] initWithCode:INRequestPaymentIntentResponseCodeFailure userActivity:nil];
        response.paymentRecord = [[INPaymentRecord alloc] initWithPayee:nil payer:nil currencyAmount:intent.currencyAmount paymentMethod:INPaymentMethodTypeUnknown note:nil status:INPaymentStatusFailed feeAmount:nil];

    } else {

        NSLog(@"INTENT VALIDO ");

        response = [[INRequestPaymentIntentResponse alloc] initWithCode:INRequestPaymentIntentResponseCodeSuccess userActivity:nil];
        response.paymentRecord = [[INPaymentRecord alloc] initWithPayee:nil payer:nil currencyAmount:intent.currencyAmount paymentMethod:INPaymentMethodTypeUnknown note:nil status:INPaymentStatusCompleted feeAmount:nil];
    }

    completion(response);
}

@end
resolvePayerForRequestPayment中的

.notRequired不起作用!似乎intent.payer必须存在。事实上,如果我说:&#34;收取Alex $ 30&#34;它有效,但如果我说:&#34;收费30美元&#34; 不起作用,因为Handle方法没有调用。 Siri总是告诉我继续在应用程序中。没有错误,没有警告,什么都没有!

intent.payer是readOnly因此无法强制使用。

IntentsExtension:

#import "IntentsExtension.h"
#import "RequestPaymentIntentHandler.h"

@implementation IntentsExtension

-(id)handlerForIntent:(INIntent *)intent {

    if ([intent isKindOfClass:[INRequestPaymentIntent class]])
        return [RequestPaymentIntentHandler new];

    return nil;
}


@end

这是扩展plist文件: Info.plist

目标应用 AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after application launch.

    if ([INPreferences siriAuthorizationStatus] != INSiriAuthorizationStatusAuthorized)
        [INPreferences requestSiriAuthorization:^(INSiriAuthorizationStatus status) {
        }];

    NSLog(@"--->SIRI LANGUAGE: %@<----", [INPreferences siriLanguageCode]);

    return YES;
}

启用Siri功能。

回顾一下我的目标是不指定付款人。有什么想法吗?

感谢。

0 个答案:

没有答案