如何为我的IAP集成Touch ID?

时间:2016-06-15 04:22:01

标签: objective-c in-app-purchase touch-id

我的IAP有以下代码,该代码可以成功运行,但不支持那些想要使用Touch ID购买的用户。我需要在removeAdsButton方法中添加什么才能支持此功能?如果我没有添加任何内容来支持Touch ID,交易是否仍会成功处理?

- (void)removeAdsButton {
    if([SKPaymentQueue canMakePayments]){

        SKProductsRequest *productsRequest = [[SKProductsRequest alloc]
        initWithProductIdentifiers:[NSSet setWithObject:kRemoveAdsProductIdentifier]];
        productsRequest.delegate = self;
        [productsRequest start];
    }
    else{
    }
}

- (void)productsRequest:(SKProductsRequest *)request didReceiveResponse:(SKProductsResponse *)response{
    SKProduct *validProduct = nil;
    int count = (int)[response.products count];
    if(count > 0){
        validProduct = [response.products objectAtIndex:0];
        [self purchase:validProduct];
    }
    else if(!validProduct){
    }
}

- (void)purchase:(SKProduct *)product{
    SKPayment *payment = [SKPayment paymentWithProduct:product];

    [[SKPaymentQueue defaultQueue] addTransactionObserver:self];
    [[SKPaymentQueue defaultQueue] addPayment:payment];
}

- (void) paymentQueueRestoreCompletedTransactionsFinished:(SKPaymentQueue *)queue{
    for(SKPaymentTransaction *transaction in queue.transactions){

        if(transaction.transactionState == SKPaymentTransactionStateRestored){
            [self doRemoveAds];
            [[SKPaymentQueue defaultQueue] finishTransaction:transaction];
            break;
        }
    }   
}

- (void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions{

    for(SKPaymentTransaction *transaction in transactions){

        switch(transaction.transactionState){
            case SKPaymentTransactionStateDeferred: 
                break;
            case SKPaymentTransactionStatePurchasing:
                break;
            case SKPaymentTransactionStatePurchased:
                [self doRemoveAds];
                [[SKPaymentQueue defaultQueue] finishTransaction:transaction];
                break;
            case SKPaymentTransactionStateRestored:
                [[SKPaymentQueue defaultQueue] finishTransaction:transaction];
                break;
            case SKPaymentTransactionStateFailed:
                if(transaction.error.code == SKErrorPaymentCancelled){
                }
                [[SKPaymentQueue defaultQueue] finishTransaction:transaction];
                break;
        }
    }
}

- (void)restorePurchasesButton {
    [[SKPaymentQueue defaultQueue] addTransactionObserver:self];
    [[SKPaymentQueue defaultQueue] restoreCompletedTransactions];
}

- (void)doRemoveAds{
    //Does my ad removal stuff.
}

1 个答案:

答案 0 :(得分:-1)

请关注https://discussions.apple.com/thread/5349382?tstart=0主题。希望这对您有帮助。