I use in my app the SKStoreProductViewController
. It shows up correctly, but with a few seconds of delay, which slows down the user experience.
Is there something wrong in my code ? Or should I inform the user that the VC is loading ? Because right now one can believe that nothing is happening after pressing the button (which triggers 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];
}
}];
}
The delay is caused because you present the viewController after the products have been loaded sucesfully.
You can put the call presentViewController:animated:completion:
outside of the block that is called after the products have been loaded. In this case the controller will be presented empty, and it is filled after the products have been loaded.
Something along those 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 could create a "popup" view that shows an activity indicator while the controller loads its content.
Or you use [UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
There are a couple of ways to handle this.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With