4

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?

4

2 回答 2

3

completionBlock如果 iTunes 项目标识符无效,则永远不会在模拟器或真实设备上调用。这似乎使resultanderror参数无用,所以我会说这是一个错误。

模拟器似乎还有其他问题,即使标识符有效(并且在设备上工作)它也不会呈现任何内容。

于 2015-01-18T20:38:47.870 回答
3

您是第一个代码应该可以正常工作。但是在 iPhone Simulator 中,iTunes Store 经常返回错误。

我已经在 iPhone 上测试了您的第一个代码(使用其他标识符),它工作得很好,但SKStoreProductParameterITunesItemIdentifier您提供的 (36372693196) 似乎不正确。

于 2013-10-09T13:36:29.653 回答