iOS 13错误:主线程检查器:在后台线程上调用了UI API:-[UITableView reloadData]应用内购买

时间:2019-09-27 15:14:45

标签: ios objective-c in-app-purchase app-store ios13

在转换为iOS 13.1主要问题后,仅发现此错误,因为它会导致应用内购买视图崩溃。五年来一直在我们的应用程序中使用此应用程序内Apple代码,因此需要帮助以进行分类。如果您有特定的代码解决方案,请回复。谢谢!

- (void)viewDidLoad
{
    [super viewDidLoad];

    appCode = [Plis getSetting :@"AppCode"];

    NSLog (@"InApp...VDL...appCode %@",appCode);

    [self.tabBarController.tabBar setHidden:NO];

    self.title = @"In-App Store";

    [_detailView setDelegate:self];
    [_detailView setDataSource:self];

    self.refreshControl = [[UIRefreshControl alloc] init];
    [self.refreshControl addTarget:self action:@selector(reload) forControlEvents:UIControlEventValueChanged];
    [self reload];
    [self.detailView reloadData];
    [self.refreshControl beginRefreshing];

    _priceFormatter = [[NSNumberFormatter alloc] init];
    [_priceFormatter setFormatterBehavior:NSNumberFormatterBehavior10_4];
    [_priceFormatter setNumberStyle:NSNumberFormatterCurrencyStyle];

    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Restore" style:UIBarButtonItemStylePlain target:self action:@selector(restoreTapped:)];
    }

- (void)restoreTapped:(id)sender {
    [[InAppProdID sharedInstance: appCode] restoreCompletedTransactions];
}

- (void)viewWillAppear:(BOOL)animated {
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(productPurchased:) name:IAPHelperProductPurchasedNotification object:nil];
    [self.tabBarController.tabBar setHidden:NO];
}

- (void)viewWillDisappear:(BOOL)animated {
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}

- (void)productPurchased:(NSNotification *)notification {

    NSString * productIdentifier = notification.object;
    [productArr enumerateObjectsUsingBlock:^(SKProduct * product, NSUInteger idx, BOOL *stop) {
        if ([product.productIdentifier isEqualToString:productIdentifier]) {

            self.productPurchased = productIdentifier;
            [self unlockProduct];

            [self.detailView reloadRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:idx inSection:0]] withRowAnimation:UITableViewRowAnimationFade];
            *stop = YES;
        }
    }];

}

- (void)reload {
    productArr = nil;
    [self.detailView reloadData];
    [[InAppProdID sharedInstance: appCode] requestProductsWithCompletionHandler:^(BOOL success, NSArray *products) {
        if (success) {
            productArr = products;
            // HERE IS WHERE THE ERROR OCCURS!
            [self.detailView reloadData];
        }
        [self.refreshControl endRefreshing];
    }];
}

0 个答案:

没有答案