【发布时间】:2015-01-21 05:12:05
【问题描述】:
我只是想问问是否有办法检查用户是否真的以编程方式购买了应用程序。我看到 Infinity Blade 3 和其他游戏如何强制用户登录他们的苹果帐户,并以某种方式与商店核实该应用程序是否已被购买。这怎么可能以编程方式创建?我搜索了整个网络,只是为了找到如何打开 storkit 视图,您可以从中购买其他应用程序或视频等...提前致谢
【问题讨论】:
标签: ios objective-c login app-store
我只是想问问是否有办法检查用户是否真的以编程方式购买了应用程序。我看到 Infinity Blade 3 和其他游戏如何强制用户登录他们的苹果帐户,并以某种方式与商店核实该应用程序是否已被购买。这怎么可能以编程方式创建?我搜索了整个网络,只是为了找到如何打开 storkit 视图,您可以从中购买其他应用程序或视频等...提前致谢
【问题讨论】:
标签: ios objective-c login app-store
您可以尝试检查应用的收据并通过 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 以验证您的收据。
【讨论】:
didFailWithError 消息,我的意思是你的代码证明用户之前购买了我的应用程序吗?