Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
362 views
in Technique[技术] by (71.8m points)

ios - Restore already bought in-app-purchases on iPhone?

I got so far: After a reinstall, a user needs to click "buy feature", then he gets scared with the $0.99 question, then has to login and then gets told the feature is already bought and he gets it for free.

I know apple is a religion and users are strong believers, but isn't there a better way? :-) What I want is to check for the feature without actually buying it. Letting the user enter his account info seems to be neccessary, maybe buy a $0.00 feature? or is there a method somewhere that does this?

I'm using MKStoreKit for the whole In-App-Purchase, but any solution would be great.


UPDATE

thanx to darvids0n, your method solved my problem! here's some working code for others trying the same:

- (void)removePreviousPurchases { //just for sandbox testing
    [[MKStoreManager sharedManager] removeAllKeychainData];
}

- (void)restorePreviousPurchases { //needs account info to be entered
    if([SKPaymentQueue canMakePayments]) {
        [[MKStoreManager sharedManager] restorePreviousTransactionsOnComplete:^(void) {
             NSLog(@"Restored.");
             /* update views, etc. */
        }
        onError:^(NSError *error) {
            NSLog(@"Restore failed: %@", [error localizedDescription]);
            /* update views, etc. */
        }];
    }
    else
    {
        NSLog(@"Parental control enabled");
        /* show parental control warning */
    }
}
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

If the $0.99 item is non-consumable, then you should provide a "Restore Purchases" button (or similar) which calls

[[SKPaymentQueue defaultQueue] restoreCompletedTransactions];

Assuming you've added a transaction observer already, and implemented the protocol including a case to handle a restored transaction (with state SKPaymentTransactionStateRestored) this will work.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...