0

我必须在我们的应用程序中集成 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 必须存在。事实上,如果我说:“向 Alex 收取 30 美元”它会起作用,但如果我说:“收取 30 美元”不起作用,因为没有调用 Handle 方法。Siri 总是告诉我在应用程序中继续。没有错误,没有警告,什么都没有!

intent.payer 是只读的,因此不能强制。

意图扩展:

#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

目标 App 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 功能已启用。

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

谢谢。

4

0 回答 0