SKStoreProductViewController appears with a delay

I use SKStoreProductViewController in my application. It displays correctly, but with a few seconds of delay, which slows down the user.

Is there something wrong in my code? Or should I tell the user that VC is loading? Because now you can believe that nothing happens after clicking the button (which launches the following code):

 -(void)launchApp:(id)sender { // Recall on main thread if necessary if (![NSThread isMainThread]) { [self performSelectorOnMainThread:@selector(launchApp:) withObject:sender waitUntilDone:NO]; return; } // Initialize Product View Controller SKStoreProductViewController *storeProductViewController = [[SKStoreProductViewController alloc] init]; // Configure View Controller [storeProductViewController setDelegate:self]; [storeProductViewController loadProductWithParameters:@{SKStoreProductParameterITunesItemIdentifier : @"*********"} completionBlock:^(BOOL result, NSError *error) { if (error) { NSLog(@"Error %@ with User Info %@.", error, [error userInfo]); } else { // Present Store Product View Controller [self presentViewController:storeProductViewController animated:YES completion:nil]; } }]; } 
+7
source share
1 answer

The delay is caused by the fact that you present the viewController after the products have been loaded properly.

You can place a call to presentViewController:animated:completion: outside the block that is called after loading the products. In this case, the controller will be displayed empty, and it will be filled after loading the products.

Something in these lines:

 SKStoreProductViewController *storeProductViewController = [[SKStoreProductViewController alloc] init]; // Configure View Controller [storeProductViewController setDelegate:self]; [storeProductViewController loadProductWithParameters:@{SKStoreProductParameterITunesItemIdentifier : @364709193} completionBlock:^(BOOL result, NSError *error) { if (error) { NSLog(@"Error %@ with User Info %@.", error, [error userInfo]); } else { } }]; // Present Store Product View Controller [self presentViewController:storeProductViewController animated:YES completion:nil]; 

Or you can create a pop-up view that displays an activity indicator when the controller loads its contents.

Or you use [UIApplication sharedApplication].networkActivityIndicatorVisible = YES;

There are several ways to handle this.

+28
source

All Articles