How do i integrate Touch ID for my IAP?

旧巷老猫 提交于 2019-12-22 18:28:38

问题


I have the following code for my IAP, which works successfully, but doesn't support those who want to purchase with Touch ID. What do I need to add to my removeAdsButton method to support this? If I don't add anything to support Touch ID, will the transaction still process successfully?

- (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:


Please follow https://discussions.apple.com/thread/5349382?tstart=0 thread .Hope this will help you.



来源:https://stackoverflow.com/questions/37826095/how-do-i-integrate-touch-id-for-my-iap

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!