0

Just discovered this error after converting to iOS 13.1 Major issue since it causes the In-App Purchases view to crash. Have been using this In-App Apple code in our apps for five years and need help in sorting this out. Please reply if you have specific code solutions. Thanks!

- (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];
    }];
}
John
  • 538
  • 4
  • 18
  • did you try to just call the reload func async from the main thread? – thisIsTheFoxe Sep 27 '19 at 15:16
  • 1
    Yes, No data is returned although the data shows in the helper class... – John Sep 27 '19 at 15:18
  • Make sure all UI code in run on the main thread. This has always been the case. iOS 13 just enforces it more. – rmaddy Sep 27 '19 at 15:19
  • See [these search results](https://stackoverflow.com/search?q=%5Bobjective-c%5D+Main+Thread+Checker%3A+UI+API+called+on+a+background+thread) for other possible duplicates. – rmaddy Sep 27 '19 at 16:22

0 Answers0