Reputation: 447
Purchasing in an iOS simulator is a well known "no, it's not possible". However, retrieving SKProduct
information by providing product identifiers to a SKProductsRequest
used to work before iOS 11.
In the SKProductsRequestDelegate
I'm getting the following error: Error Domain=SSErrorDomain Code=0 "Cannot connect to iTunes Store"
From what I found out, this can happen either when the product identifiers are wrong, or the Apple Sandbox servers are down. However this is not the case since products are loaded fine on iOS 10..
My implementation of product fetching is pretty much the same as in the Apple guides
Is anyone else experiencing this or found a solution?
The products are loading fine when the app is running on a physical device. I'm using Xcode 9.0.
Upvotes: 10
Views: 3863
Reputation: 355
Similar question and this answer helped me: https://stackoverflow.com/a/58065711/5525237
BTW: testing with real device solved the problem completely
Upvotes: 0
Reputation: 12844
It's an apple issue. I also had similar problem. After trying a lot, i recall the product request method for 10 times and i got response in second try. It works on iOS 9 and 11 only. Not for iOS 10. And once you get your products, you will surly get it in first time later. It works on both device and simulator. My implementation is like :
- (void)request:(SKRequest *)request didFailWithError:(NSError *)error
{
int tried=(int)[[NSUserDefaults standardUserDefaults] integerForKey:@"try"];
[[NSUserDefaults standardUserDefaults] setInteger:tried+1 forKey:@"try"];
[[NSUserDefaults standardUserDefaults] synchronize];
if([[GameState shared].availableInApps count]==0&&(int)[[NSUserDefaults standardUserDefaults] integerForKey:@"try"]>10)
{
[NSTimer scheduledTimerWithTimeInterval:10 target:self selector:@selector(retry_product) userInfo:nil repeats:NO];
}
Upvotes: 0
Reputation: 291
Same here. If you repeat the request when it fails, just try again. After the umpteenth repetition it will finally return the products. It may take 10, 50 or even more than 100 repetitions.
So this is how my code looks now:
- (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];
}
}
Upvotes: 5