SKProductsRequest无法在iOS 11模拟器中运行

前端之家收集整理的这篇文章主要介绍了SKProductsRequest无法在iOS 11模拟器中运行前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
在iOS模拟器中购买是众所周知的“不,这是不可能的”.但是,通过向在iOS 11之前工作的SKProductsRequest提供产品标识符来检索SKProduct信息.

在SKProductsRequestDelegate中我收到以下错误:Error Domain = SSErrorDomain Code = 0“无法连接到iTunes Store”
根据我的发现,当产品标识符错误或Apple SandBox服务器关闭时,可能会发生这种情况.然而事实并非如此,因为产品在iOS 10上运行良好.

我对产品提取的实现与Apple guides中的实现非常相似

是否有其他人遇到此问题或找到解决方案?

当应用程序在物理设备上运行时,产品正在正常加载.
我正在使用Xcode 9.0.

解决方法

同样在这里.如果您在失败时重复请求,请再试一次.在无数次重复之后,它将最终返回产品.重复可能需要10次,50次甚至超过100次.

这就是我的代码现在的样子:

  1. - (void)inquireProducts {
  2. _availableProducts = [NSMutableArray arrayWithCapacity:0];
  3. NSURL *url = [[NSBundle mainBundle] URLForResource:@"productIds" withExtension:@"plist"];
  4. knownProductIdentifiers = [NSArray arrayWithContentsOfURL:url];
  5. if (knownProductIdentifiers && knownProductIdentifiers.count) {
  6. // Keep a strong reference to the product request
  7. productsRequest = [[SKProductsRequest alloc]initWithProductIdentifiers:[NSSet setWithArray:knownProductIdentifiers]];
  8. productsRequest.delegate = self;
  9. [productsRequest start];
  10. }
  11. }
  12.  
  13. #pragma mark SKProductsRequestDelegate method
  14.  
  15. - (void)productsRequest:(SKProductsRequest *)request didReceiveResponse:(SKProductsResponse *)response {
  16. for (SKProduct *product in response.products) {
  17. [_availableProducts addObject:product];
  18. }
  19. productsRequest = nil;
  20. [[NSNotificationCenter defaultCenter] postNotificationName:IAPPurchaseNotification object:self];
  21. }
  22.  
  23. - (void)request:(SKRequest *)request didFailWithError:(NSError *)error {
  24. if (request == productsRequest) {
  25. static int count = 0;
  26. NSLog(@"Request %@ Failed on %d. attempt with error: %@",request,++count,error);
  27. productsRequest = nil;
  28. // try again until we succeed
  29. [self inquireProducts];
  30. }
  31. }

猜你在找的iOS相关文章