I am trying to use SKStoreProductViewController to open the App Store modally within my app. I have looked at many examples on the web, and there are two ways people are doing this.
SKStoreProductViewController *storeController = [[SKStoreProductViewController alloc] init];
[storeController setDelegate:self];
//set product parameters
//must be a number wrapped in a string
NSDictionary *productParameters = @{ SKStoreProductParameterITunesItemIdentifier : @"36372693196"};
[storeController loadProductWithParameters:productParameters completionBlock:^(BOOL result, NSError *error) {
if (result) {
//show
[self presentViewController:storeController animated:YES completion:nil];
}else {
NSLog(@"ERROR WITH STORE CONTROLLER %@\n", error.description);
//redirect to app store
//[[UIApplication sharedApplication] openURL:[[self class] appStoreURL]];
}
}];
If I do it this way ^^ nothing happens. The if (result) or else statement within the block is never executed.
I also see people passing in nil for the completion block, and presenting the view controller modally immediately after this like below:
SKStoreProductViewController *storeController = [[SKStoreProductViewController alloc] init];
[storeController setDelegate:self];
//set product parameters
//must be a number wrapped in a string
NSDictionary *productParameters = @{ SKStoreProductParameterITunesItemIdentifier : @"36372693196"};
[storeController loadProductWithParameters:productParameters completionBlock:nil];
[self presentViewController:storeController animated:YES completion:nil];
When I present the view controller, the code inside the block for loadProductWithParameters executes. I am extremely confused at this point..How do I check for success or failure if the block isn't run until after I present it.
Lastly, I read you should execute the loadProductWithParameters in a background thread. I tried this as well. The second option is the only one that brought up the modal - with a Cannot connect to iTunes message from the simulator and device. I have tried multiple app ids. What is going on? How do I get this working?