I am trying to use SKStoreProductViewController to open the App Store in my application. I have looked at many examples on the Internet, and there are two ways to do 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 this, then nothing happens. An if (result) or else statement inside a block is never executed.
I also see people going to zero for the completion block, and presenting the view controller modally right after that, as shown below:
SKStoreProductViewController *storeController = [[SKStoreProductViewController alloc] init]; [storeController setDelegate:self];
When I present the view controller, the code inside the block is executed for loadProductWithParameters. I am very confused in this matter. How to verify success or failure if the block does not start until I present it.
Finally, I read that you have to execute loadProductWithParameters in the background thread. I tried it too. The second option - the only one that caused a modality - with Can not connect to iTunes message from the simulator and device. I tried several application identifiers. What's happening? How to do it?
source share