如果我在模拟器中运行我的应用程序,它会显示 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];
}
最佳答案
[__NSSetM addObject:]: object cannot be nil
这意味着您有一个可变集,您正在调用 addObject:
,但您传入的变量是 nil
。
在您发布的代码中,您唯一调用它的地方是在行中:
[_purchasedProductIdentifiers addObject:productIdentifier];
...因此,无论您在何处调用 provideContentForProductIdentifier:
,您都会将其传递给 nil
。
关于ios - 应用内购买 - 设备崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17820242/