当前位置: 动力学知识库 > 问答 > 编程问答 >

ios - How to check for purchased feature (InApp Purchase) when user delete and reinstall the app?

问题描述:

I am working on a project which include InApp purchase functionality. I am done with it and I store a key in NSUserDefault when user purchase the feature and check for the key to unlock the feature of app if user has already purchased it. But now the problem is that what if user delete the app and reinstall it, then all data of NSUserDefault get deleted. So what is the solution to check for unlocking the feature in that case?? Please tell me the possible solutions.

Thanks!!

网友答案:

When you'll submit your app to the AppStore, most likely it will be rejected since your solution doesn't provide an ability to restore user's IAPs on different devices using the same Apple ID. You are responsible for adding this feature to app. It might happens automatically or on user's demand, based on your UI flow.

Before start to implement, read related Apple Documentation

After you check that user is already purchased a feature you may store it as you proposed to do using NSUserDefaults, that will give you an ability to save app state between launches.

That is a most common and frequently used approach.

网友答案:
- (IBAction)RestoreBtnClicked:(id)sender
{

 [[SKPaymentQueue defaultQueue] addTransactionObserver:self];

  [[SKPaymentQueue defaultQueue]restoreCompletedTransactions];
}


// Then this is called

- (void)paymentQueueRestoreCompletedTransactionsFinished:(SKPaymentQueue *)queue {

    NSLog(@"%@",queue );

    NSLog(@"Restored Transactions are once again in Queue for purchasing %@",[queue transactions]);


    NSMutableArray *purchasedItemIDs = [[NSMutableArray alloc] init];

    NSLog(@"received restored transactions: %i", queue.transactions.count);

    UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:
    @"Purchase Restored" message:nil delegate:
        self cancelButtonTitle:@"Ok" otherButtonTitles: nil];
    [alertView show];


  for (SKPaymentTransaction *transaction in queue.transactions) {

        NSString *productID = transaction.payment.productIdentifier;

        [purchasedItemIDs addObject:productID];

        NSLog (@"product id is %@" , productID);

        // example if ([productID isEqualToString: @"youruniqueproductidentifier]){write files} else { nslog sorry}
    }
}
分享给朋友:
您可能感兴趣的文章:
随机阅读: