Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SKProductsRequest not working in iOS 11 Simulators

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.

like image 645
emn.mun Avatar asked Sep 19 '17 14:09

emn.mun


People also ask

How do you run the Expo on simulation?

Start your app by using expo start command. Type i and a or click on Run on iOS simulator and Run on Android device/emulator buttons to launch your app on devices.

How do you enable simulation on iPhone?

Select a simulated device For iOS, tvOS, and watchOS apps, you can choose a simulated device, under [Platform] Simulators, from the run destination menu next to the scheme menu in the toolbar.

Which command is used to run the app on iOS simulator?

If you wish to run your app on an iPhone SE (2nd generation), run npx react-native run-ios --simulator='iPhone SE (2nd generation)' . The device names correspond to the list of devices available in Xcode. You can check your available devices by running xcrun simctl list devices from the console.


1 Answers

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];
    }
}
like image 173
vilmoskörte Avatar answered Oct 20 '22 00:10

vilmoskörte