Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/96.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 应用内购买-设备崩溃_Ios_In App Purchase - Fatal编程技术网

Ios 应用内购买-设备崩溃

Ios 应用内购买-设备崩溃,ios,in-app-purchase,Ios,In App Purchase,如果我在模拟器中运行我的应用程序,它会显示failedTransaction 如果我在iPhone上运行它,它会因以下错误而崩溃: *由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:“*-[\uu NSSetM addObject:]:对象不能为零” 这是我的代码: - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath: (NSIndexPath

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

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

*由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:“*-[\uu NSSetM addObject:]:对象不能为零”

这是我的代码:

- (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];

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

在您发布的代码中,您称之为this的唯一位置是:

[_purchasedProductIdentifiers addObject:productIdentifier];
…因此,无论您在何处调用
provideContentForProductIdentifier:
,您都在传递它
nil

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

在您发布的代码中,您称之为this的唯一位置是:

[_purchasedProductIdentifiers addObject:productIdentifier];

…因此,无论您在哪里调用
provideContentForProductIdentifier:
,您都在传递它
nil

更改
\u purchasedProductIdentifier的分配

替换
\u purchasedProductIdentifiers=[NSMutableSet]


通过
\u purchasedProductIdentifiers=[[NSMutableSet alloc]init]

更改
\u purchasedProductIdentifiers

替换
\u purchasedProductIdentifiers=[NSMutableSet]


通过
\u purchasedProductIdentifiers=[[NSMutableSet alloc]init]

错误发生在哪一行代码上?您发布的错误非常具体。您正在尝试将nil对象添加到可变数组中。在您发布的代码中,您可能应该检查以确保
productIdentifier
不为零。只有在iPhone上而不是在模拟器上运行应用程序时才会发生错误。错误发生在哪一行代码上?您发布的错误非常具体。您正在尝试将nil对象添加到可变数组中。在您发布的代码中,您可能应该检查以确保
productIdentifier
不为零。只有在我的iPhone上而不是在模拟器中运行应用程序时才会发生错误。为什么它只在我的手机上运行而不在模拟器中,它只是无法还原购买的产品。您没有提供足够的代码来确定这一点,但是如果我不得不猜测,我会说您正在从外部文件加载产品标识符,并且代码中用于文件名的大小写与实际文件名的大小写不匹配。iOS区分大小写,而OS X则不区分大小写。由于它找不到该文件,您最终得到的是
nil
,所有试图从该
nil
值获取信息的代码也将返回
nil
,最终导致您传递到
provideContentForProductIdentifier:
的产品标识符为
nil
。嘿,谢谢。。。。。我删除了我的测试acc并创建了一个新的,现在一切都正常了,一定是测试acc出错了…为什么它只在我的手机上执行,而不是在模拟器中执行,它只是无法还原购买的产品。你还没有提供足够的代码来确定这一点,但如果我不得不猜测,我要说的是,您正在从外部文件加载产品标识符,代码中用于文件名的大小写与实际文件名的大小写不匹配。iOS区分大小写,而OS X则不区分大小写。由于它找不到该文件,您最终得到的是
nil
,所有试图从该
nil
值获取信息的代码也将返回
nil
,最终导致您传递到
provideContentForProductIdentifier:
的产品标识符为
nil
。嘿,谢谢。。。。。我删除了我的测试acc,做了一个新的,现在一切都正常了,一定是测试acc出错了…这对我来说很有效,但我想知道它为什么有效,如果你能解释的话。。。我的问题不是_purchasedProductIdentifiers的零值,而是与我的测试帐户“保留”到以前的一些购买尝试有关。这对我来说是有效的,但我想知道它为什么有效,如果你能解释的话。。。我的问题不是_purchasedProductIdentifiers的零值,而是与我的测试帐户“保留”到以前的一些购买尝试有关。