检查是否已购买应用

时间:2014-11-23 12:09:04

标签: ios objective-c login app-store

我只想询问是否有办法检查用户是否确实以编程方式购买了应用。我看到Infinity Blade 3和其他游戏如何强迫用户登录他们的苹果帐户,并以某种方式与商店核实该应用程序是否已被购买。如何以编程方式创建?我在网上搜索过,只是为了找到如何打开storkit视图,你可以从中购买其他应用程序或视频等等...提前致谢

1 个答案:

答案 0 :(得分:5)

您可以尝试检查应用的收据并使用AppStore验证 -

NSURL* url = [[NSBundle mainBundle] appStoreReceiptURL]; // iOS 7+, do not use respondsToSelector as it will report YES for iOS 6 too

以下是关于如何验证收据的Apple's documentation 如果收据为nil或url指向不存在的路径,则可能需要刷新收据 实施SKRequestDelegate并检查:

NSError* err = nil;
if (![url checkResourceIsReachableAndReturnError:&err]){
    SKReceiptRefreshRequest* request = [[SKReceiptRefreshRequest alloc] initWithReceiptProperties:nil];
    request.delegate = self; /* or your delegate's instance here */
    [request start];
}
....
-(void)requestDidFinish:(SKRequest*)request{
    if([request isKindOfClass:[SKReceiptRefreshRequest class]]){
        // The URL should be available now, if it's not - I guess the app is cracked
    }
}
-(void)request:(SKRequest*)request didFailWithError:(NSError *)error{
    ; // This does not mean the app is pirated, use this to schedule the test for later.
}

我会在调试模式下(以及在模拟器上)禁用这些检查 您可能需要检查此项目 - VerifyStoreReceiptiOS以验证收据。