Ios 链接表视图以在应用内购买后解锁相应的ViewController

Ios 链接表视图以在应用内购买后解锁相应的ViewController,ios,objective-c,in-app-purchase,storekit,Ios,Objective C,In App Purchase,Storekit,通过使用RW的教程,我成功地实现了IAP,直到用户购买所选IAP时,它显示一个勾号。它还成功列出了我的4个可用IAP 我已经决定用一种更简单、需要更少代码的方式来实现这一点(我想) -而不是添加更多代码,允许用户下载苹果托管的内容,然后再编写更多代码,将内容传输回应用程序并传输到选定的视图中 我选择将内容嵌入到应用程序中,而只是锁定视图控制器或链接到相应视图控制器的按钮,直到用户购买了内容/IAP。我不想改变RW的方式,因为目前为止它工作得很好,我只想添加到它中,以便在用户购买内容后内容并勾选I

通过使用RW的教程,我成功地实现了IAP,直到用户购买所选IAP时,它显示一个勾号。它还成功列出了我的4个可用IAP

我已经决定用一种更简单、需要更少代码的方式来实现这一点(我想) -而不是添加更多代码,允许用户下载苹果托管的内容,然后再编写更多代码,将内容传输回应用程序并传输到选定的视图中

我选择将内容嵌入到应用程序中,而只是锁定视图控制器或链接到相应视图控制器的按钮,直到用户购买了内容/IAP。我不想改变RW的方式,因为目前为止它工作得很好,我只想添加到它中,以便在用户购买内容后内容并勾选IAP,然后解锁与该特定IAP相关的视图控制器

到目前为止,我如何继续添加到代码中以实现这一点?我有4个应用程序内购买(意味着4个单独的视图控制器链接到此代码),我想我需要扩展的代码如下

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

    NSString * productIdentifier = notification.object;
    [_products enumerateObjectsUsingBlock:^(SKProduct * product, NSUInteger idx, BOOL *stop) {
        if ([product.productIdentifier isEqualToString:productIdentifier]) {
            [self.tableView reloadRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:idx inSection:0]] withRowAnimation:UITableViewRowAnimationFade];
            *stop = YES;
        }
    }];

}

- (void)reload {
    _products = nil;
    [self.tableView reloadData];
    [[SecretsIAPHelper sharedInstance] requestProductsWithCompletionHandler:^(BOOL success, NSArray *products) {
        if (success) {
            _products = products;
            [self.tableView reloadData];
        }
        [self.refreshControl endRefreshing];
    }];
}

#pragma mark - Table View

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return _products.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath];

    SKProduct * product = (SKProduct *) _products[indexPath.row];
    cell.textLabel.text = product.localizedTitle;
    [_priceFormatter setLocale:product.priceLocale];
    cell.detailTextLabel.text = [_priceFormatter stringFromNumber:product.price];

    if ([[SecretsIAPHelper sharedInstance] productPurchased:product.productIdentifier]) {
        cell.accessoryType = UITableViewCellAccessoryCheckmark;
        cell.accessoryView = nil;
    } else {
        UIButton *buyButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
        buyButton.frame = CGRectMake(0, 0, 72, 37);
        [buyButton setTitle:@"Buy" forState:UIControlStateNormal];
        buyButton.tag = indexPath.row;
        [buyButton addTarget:self action:@selector(buyButtonTapped:) forControlEvents:UIControlEventTouchUpInside];
        cell.accessoryType = UITableViewCellAccessoryNone;
        cell.accessoryView = buyButton;
    }

    return cell;
}

- (void)buyButtonTapped:(id)sender {

    UIButton *buyButton = (UIButton *)sender;
    SKProduct *product = _products[buyButton.tag];

    NSLog(@"Buying %@...", product.productIdentifier);
    [[SecretsIAPHelper sharedInstance] buyProduct:product];

}

我认为您应该解决以下问题:

    - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([segue.identifier isEqualToString:@"showDetail"]) {
    DetailViewController * detailViewController = (DetailViewController *) segue.destinationViewController;
    SKProduct * product = (SKProduct *) _products[self.tableView.indexPathForSelectedRow.row];
    if ([[RageIAPHelper sharedInstance] productPurchased:product.productIdentifier]) {

        if ([product.productIdentifier isEqualToString:@"it.horizonmedia.testiap.ghesemmo"]) {

            detailViewController.image = [UIImage imageNamed:@"drummer.png"];
            detailViewController.message = @"Bravo che l'hai COMPRATA!!!";
        }


          else if ([product.productIdentifier isEqualToString:@"it.horizonmedia.testiap.prodottotest3"]) {
              detailViewController.message = @"Bravo che l'hai COMPRATA!!!";
              detailViewController.image = [UIImage imageNamed:@"iphonerage.png"];

        } else if ([product.productIdentifier isEqualToString:@"it.horizonmedia.testiap.prodottotest"]) {
            detailViewController.message = @"You made a Good Purchase!";
            detailViewController.image = [UIImage imageNamed:@"iphonerage.png"];


        }
    } else {
        detailViewController.image = nil;
        detailViewController.message = @"Purchase to see comic!";
    }
}
}

请记住,正如我猜您在教程中所做的那样,您必须在代码中替换真实的产品ID


让我知道它是否有效

看起来不错。什么不起作用?products数组应该包含未锁定的产品,并且该表应该只显示
\u products.count
行。@mundi RW的代码只显示购买后的勾号,这就是为什么我在购买后提出这个更简单的解决方案的原因。。。我可以在此代码中添加哪些内容,以便用户能够单击其应用程序内购买并查看未锁定的内容?顺便说一句,谢谢你的回复。只需将逻辑放入
didselectRowatineXpath:
@Mundi-(UITableViewCell*)tableView:(UITableView*)tableView CellforRowatineXpath:(NSIndexPath*)indexPath我想你是指这行代码。。。你的确切意思是什么?当我点击IAP时,它会带我进入详细视图屏幕。。。。不过,我想对其进行更改,以便在用户购买内容后,对于4次应用内购买中的每一次,它都会将用户带到不同的未锁定视图。