ios - in app purchases - device crash -
if run app in simulator says failedtransaction...
and if run on iphone crashes error:
* terminating app due uncaught exception 'nsinvalidargumentexception', reason: '* -[__nssetm addobject:]: object cannot nil'
here: code:
- (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]; }
and error here:
- (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 nil
this means have mutable set calling addobject:
on, variable passing in nil
.
in code post, place call in line:
[_purchasedproductidentifiers addobject:productidentifier];
...so wherever calling providecontentforproductidentifier:
, passing nil
.
Comments
Post a Comment