0

如果我在模拟器中运行我的应用程序,它会显示 failedTransaction ...

如果我在我的 iPhone 上运行它,它会因以下错误而崩溃:

* 由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:“* -[__NSSetM addObject:]: object cannot be nil”

这里:是我的代码:

- (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([[ScoreboardIAPHelper 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);
[[ScoreboardIAPHelper sharedInstance] buyProduct:product];

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(productPurchased:) name:IAPHelperProductPurchasedNotification object:nil];



}

我在这里得到我的错误:

- (void)provideContentForProductIdentifier:(NSString *)productIdentifier {

[_purchasedProductIdentifiers addObject:productIdentifier];
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:productIdentifier];
[[NSUserDefaults standardUserDefaults] synchronize];
[[NSNotificationCenter defaultCenter] postNotificationName:IAPHelperProductPurchasedNotification object:productIdentifier];

 }
4

2 回答 2

4
[__NSSetM addObject:]: object cannot be nil

这意味着您有一个正在调用的可变集合addObject:,但您传入的变量是nil.

在您发布的代码中,您调用它的唯一位置是在该行中:

[_purchasedProductIdentifiers addObject:productIdentifier];

...所以无论你在哪里打电话provideContentForProductIdentifier:,你都在传递它nil

于 2013-07-23T20:26:06.043 回答
1

更改分配_purchasedProductIdentifiers

代替_purchasedProductIdentifiers = [NSMutableSet set];

经过_purchasedProductIdentifiers = [[NSMutableSet alloc] init];

于 2015-03-04T13:39:40.703 回答