在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次.
这就是我的代码现在的样子:
- (void)inquireProducts { _availableProducts = [NSMutableArray arrayWithCapacity:0]; NSURL *url = [[NSBundle mainBundle] URLForResource:@"productIds" withExtension:@"plist"]; knownProductIdentifiers = [NSArray arrayWithContentsOfURL:url]; if (knownProductIdentifiers && knownProductIdentifiers.count) { // Keep a strong reference to the product request productsRequest = [[SKProductsRequest alloc]initWithProductIdentifiers:[NSSet setWithArray:knownProductIdentifiers]]; productsRequest.delegate = self; [productsRequest start]; } } #pragma mark SKProductsRequestDelegate method - (void)productsRequest:(SKProductsRequest *)request didReceiveResponse:(SKProductsResponse *)response { for (SKProduct *product in response.products) { [_availableProducts addObject:product]; } productsRequest = nil; [[NSNotificationCenter defaultCenter] postNotificationName:IAPPurchaseNotification object:self]; } - (void)request:(SKRequest *)request didFailWithError:(NSError *)error { if (request == productsRequest) { static int count = 0; NSLog(@"Request %@ Failed on %d. attempt with error: %@",request,++count,error); productsRequest = nil; // try again until we succeed [self inquireProducts]; } }