ios - Why does VerificationController crash inside of didReceiveData -
here function crashes. exact line of code 1 with: removeobjectforkey. when test function empty crashes on removeobjectforkey. note: i'm passing in empty function callback. currently, have arc off, need turn on? if possible, arc off, because turning on mean dealing alot of compile issues.
the function non-retained objects, hence memory issue.
- (void)connection:(nsurlconnection *)connection didreceivedata:(nsdata *)data { nsstring *responsestring = [[nsstring alloc] initwithdata:data encoding:nsutf8stringencoding]; // got receipt data. check out? bool isok = [self doestransactioninfomatchreceipt:responsestring]; verifycompletionhandler completionhandler = _completionhandlers[[nsvalue valuewithnonretainedobject:connection]]; [_completionhandlers removeobjectforkey:[nsvalue valuewithnonretainedobject:connection]]; if (isok) { //validation suceeded. unlock content here. nslog(@"validation successful"); completionhandler(true); } else { nslog(@"validation failed"); completionhandler(false); } } here verificationcontroller usage:
[[verificationcontroller sharedinstance] verifypurchase:transaction completionhandler:^(bool success) { if (success) { nslog(@"hi, success."); [self testmethod]; } else { nslog(@"payment not authorized."); } }]; } - (void) testmethod { } i use __weak have turn on arc, i'm trying avoid. note: verificaitioncontroller works when put inside other classes/objects, put in inapppurchasemanager blows anytime tries access self. self points instance of inapppurchasemanager defined (its phonegap plugin):
@interface inapppurchasemanager : cdvplugin <skpaymenttransactionobserver> { }
i ran problem fixed issue way main issue when setting value completion handler in verifypurchase method setting nil value find line in verifypurchase method
_completionhandlers[[nsvalue valuewithnonretainedobject:conn]] = completionhandler; and replace with
[_completionhandlers setobject:[completionhandler copy] forkey:[nsvalue valuewithnonretainedobject:conn]]; and find connectiondidreceivedata method , replace
- (void)connection:(nsurlconnection *)connection didreceivedata:(nsdata *)data { nsstring *responsestring = [[nsstring alloc] initwithdata:data encoding:nsutf8stringencoding]; // got receipt data. check out? bool isok = [self doestransactioninfomatchreceipt:responsestring]; if (_completionhandlers && [_completionhandlers respondstoselector:@selector(removeobjectforkey:)]) { verifycompletionhandler completionhandler = _completionhandlers[[nsvalue valuewithnonretainedobject:connection]]; [_completionhandlers removeobjectforkey:[nsvalue valuewithnonretainedobject:connection]]; if (isok) { //validation suceeded. unlock content here. nslog(@"validation successful"); completionhandler(true); } else { nslog(@"validation failed"); completionhandler(false); } } //[_completionhandlers removeobjectforkey:[nsvalue valuewithnonretainedobject:connection]]; } hope may , saves alot of time.
Comments
Post a Comment