检查是否购买了应用程序(Check if app was bought)

编程入门 行业动态 更新时间:2024-10-25 07:17:16
检查是否购买了应用程序(Check if app was bought)

我只想询问是否有方法检查用户是否确实以编程方式购买了应用程序。 我看到无尽之剑3和其他游戏如何强制用户登录到他们的苹果帐户,并以某种方式与商店检查应用程序是否已被购买。 这怎么可能以编程方式创建? 我在网上搜索只是为了找到如何打开storkit视图,你可以从中购买其他应用程序或视频等...在此先感谢

I just wanted to ask if there is a way to check if the user actually did buy an app programmatically. I saw how Infinity Blade 3 and other games forced the user to log in to their apple accounts and somehow checked with the store on whether or not the app has been bought. How is this possible to create programmatically? I've searched all over the web just to find how to open up the storkit view from which you can purchase other apps or videos, etc... Thanks in advance

最满意答案

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

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

这是Apple关于如何验证收据的文档 。 如果收据为零或网址指向不存在的路径,则可能需要刷新收据。 实施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验证你的收据。

You could try to check for the app's receipt and verify it with the AppStore -

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

Here's Apple's documentation on how to verify your receipt. If the receipt is nil or the url points to a non existent path, you may need to refresh the receipt. Implement SKRequestDelegate and check:

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. }

I would disable these checks in debug mode (and on the simulator). You may want to check this project - VerifyStoreReceiptiOS for verifying your receipts.

更多推荐

本文发布于:2023-08-04 14:29:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1417641.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:应用程序   购买了   Check   app   bought

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!