SKStoreProductViewController出现延迟 [英] SKStoreProductViewController showing up with delay

查看:91
本文介绍了SKStoreProductViewController出现延迟的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的应用中使用了SKStoreProductViewController.它可以正确显示,但会延迟几秒钟,这会减慢用户体验.

I use in my app the SKStoreProductViewController. It shows up correctly, but with a few seconds of delay, which slows down the user experience.

我的代码有问题吗?还是应该通知用户VC正在加载?因为现在人们可以相信按下按钮后没有任何反应(触发以下代码):

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

推荐答案

之所以造成延迟,是因为在成功加载产品之后显示了viewController.

The delay is caused because you present the viewController after the products have been loaded sucesfully.

您可以将调用presentViewController:animated:completion:放在产品加载后被调用的块之外.在这种情况下,控制器将显示为空,并且在装入产品后将其装满.

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.

遵循这些原则:

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.

或者您使用[UIApplication sharedApplication].networkActivityIndicatorVisible = YES;

有两种方法可以解决此问题.

There are a couple of ways to handle this.

这篇关于SKStoreProductViewController出现延迟的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆