我有一个应用程序,我最近更新,以便在应用程序购买中使用.之前的版本(付费但没有在应用内购买)是1.0,当前版本是1.1.
由于应用程序内购买实际上解锁了所有功能(包含在付费版本1.0中),我想要一种方式,如果用户按下我的恢复购买按钮,则最初下载的版本1.0将被升级.
为此,我首先尝试恢复购买,如果回复:
- (void)paymentQueueRestoreCompletedTransactionsFinished:(SKPaymentQueue *)queue
Run Code Online (Sandbox Code Playgroud)
如果这为我提供了一个事务计数为0的队列,我检查收据以查看安装的原始版本是否为1.0.
获得收据的代码是根据Apple的文档
- (void)tryRestoreFromOriginalPurchase
{
// Load the receipt from the app bundle
NSError *error;
NSData *receipt = [NSData dataWithContentsOfURL:[[NSBundle mainBundle] appStoreReceiptURL]];
if (receipt == nil) {
[self restoreFromOriginalVersionWithReceipt:nil];
return;
}
// Create the JSON object that describes the request
NSDictionary *requestContents = @{@"receipt-data": [receipt base64EncodedStringWithOptions:0]};
NSData *requestData = [NSJSONSerialization dataWithJSONObject:requestContents options:0 error:&error];
if (!requestData) {
[self restoreFromOriginalVersionWithReceipt:nil];
return;
}
// Create a POST request with the receipt data
NSURL *storeURL = [NSURL URLWithString:@"https://buy.itunes.apple.com/verifyReceipt"]; …Run Code Online (Sandbox Code Playgroud)