如何使用Apple的批量购买计划购买应用程序?

Mos*_*ieb 2 app-store ios apple-vpp

我有一个应用程序已在AppStore中提供了一段时间了.
我可以从iTunes报告中看到它是使用Apple的批量购买程序购买的,但这很棒 - 我想知道某个设备是运行批量购买的应用程序还是标准的AppStore应用程序.
我试图在收据([[NSBundle mainBundle] appStoreReceiptURL])内窥探,但我找不到任何信息.
为此目的创建不同的捆绑ID不是一种选择,有点遗漏了VPP的想法,请 - 请不要提供它.
是否有编程方式来判断应用程序是否是使用VPP购买的?

Rhy*_*man 5

您是否可以在应用收据中查看VPP信息,但您需要先使用SKReceiptPropertyIsVolumePurchase设置的标志刷新它:

self.refresh = [[SKReceiptRefreshRequest alloc] initWithReceiptProperties:@{SKReceiptPropertyIsVolumePurchase : @YES}];
self.refresh.delegate = self;
[self.refresh start];
Run Code Online (Sandbox Code Playgroud)

然后,您将获得收据数据 requestDidFinish:

- (void)requestDidFinish:(SKRequest *)request {
    NSURL *receiptURL = [[NSBundle mainBundle] appStoreReceiptURL];
    NSData *receipt = [NSData dataWithContentsOfURL:receiptURL];
    // decode receipt and examine vpp fields here 
}
Run Code Online (Sandbox Code Playgroud)

很多方法可以解码苹果收据,我发现最简单的方法是使用Apple的收据验证器,因此我将收据数据移动到receipt-data.der我的计算机上的文件()中:

curl -d "{ \"receipt-data\" : \"$(base64 receipt-data.der)\" }" https://sandbox.itunes.apple.com/verifyReceipt
Run Code Online (Sandbox Code Playgroud)

这显示了一些有趣的新领域:

"organization_display_name": "ACME Bad VPPReceipt Inc."
"receipt_type": "ProductionVPPSandbox"
"expiration_date": "2015-12-10 00:44:22 Etc/GMT"
Run Code Online (Sandbox Code Playgroud)

这是在沙箱中,因此当您转向生产时结果会发生变化,但这应足以确定给定设备是否为vpp.如果您使用Apple的收据验证程序,请确保将URL更改为https://buy.itunes.apple.com/verifyReceipt.