ios - 应用内购买 - 设备崩溃

标签 ios in-app-purchase

如果我在模拟器中运行我的应用程序,它会显示 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/

相关文章:

in-app-purchase - 在Google Play商店分布式应用程序中使用不同的付款方式

windows-phone-8 - 什么样的 ID 进入 RequestProductPurchaseAsync?

ios - Urban Airship 和AirshipConfig.plist

ios - 在 NSAttributedString API 中将 Range<Index> 与 NSRange 一起使用

ios - 如何找到特定帧大小的所有 subview ?

Android IAP 收到错误此版本的应用程序未配置为通过 google play 计费检查帮助中心

c++ - 为 C++ 库创建 podspec

ios - 如何在 iOS 项目中使用自定义框架?

iphone - 是否可以对应用内购买的内容实现每个 iTunes 帐户的 DRM?

ios - 在 Mac 和 iOS 应用程序之间共享应用程序购买