Odd behavior using SKStoreProductViewController

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]; //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 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?

+4
source share
2 answers

You first code should work fine. However, the iPhone Simulator iTunes Store often returns an error.

I checked your first code on iPhone (with a different identifier) ​​and it works fine, but the SKStoreProductParameterITunesItemIdentifier that you provided (36372693196) seems to be wrong.

+3
source

completionBlock will never be called - on a simulator or in a real device - if the iTunes item id is invalid. It would seem that the result and error parameters are useless, so I would say that this is an error.

The simulator will also have additional problems in that it will not present any content even when the identifier is valid (and works on the device).

+2
source

Source: https://habr.com/ru/post/1493559/


All Articles