SKStoreProductViewController showing up with delay

我怕爱的太早我们不能终老 提交于 2019-11-29 03:16:19

问题


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];
        }
    }];
}

回答1:


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.



来源:https://stackoverflow.com/questions/16546431/skstoreproductviewcontroller-showing-up-with-delay

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!