Question

I'm making an application in which,I have to make my Inappurchase product auto renewable,for this, after reading Apple documents i came to know that after every transaction for autorenewable product ,our app receives a transaction receipt for every purchase and i need to verify that receipt from Apple server after verifying my transaction receipt app has to save that transaction date. But after purchasing product when i am trying to verifying that transaction receipt from Apple server ,through the Apple Classes -Verification Controller, my app crashing at completion handler ,its showing completion handler NIL.

my _completionHandlers is released when execution reaches in any of these methods what to now?? Please guide me to solve this issue

- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
  {
    NSString *responseString = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
    // So we got some receipt data. Now does it all check out?
    BOOL isOk = [self doesTransactionInfoMatchReceipt:responseString];

    VerifyCompletionHandler completionHandler = _completionHandlers[[NSValue valueWithNonretainedObject:connection]];

    NSValue *key = [NSValue valueWithNonretainedObject:connection];

    NSLog(@"%@",_completionHandlers);
    [_completionHandlers removeObjectForKey:key];
    if (isOk)
    {
    //Validation suceeded. Unlock content here.
    NSLog(@"Validation successful");
    completionHandler(TRUE);
    } else {
    NSLog(@"Validation failed");
    completionHandler(FALSE);
    }
    }
Was it helpful?

Solution

I also ran into this problem i fixed this issue this way main issue is when you are setting value to completion handler in verifyPurchase method it is setting nil value so find this line in verifyPurchase method

_completionHandlers[[NSValue valueWithNonretainedObject:conn]] = completionHandler;

and replace it with

[_completionHandlers setObject:[completionHandler copy] forKey:[NSValue valueWithNonretainedObject:conn]];

changing these two lines will resolve your crash but to be double sure do these steps also

and find the connectionDidReceivedata method and replace it with

- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
    NSString *responseString = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];

    // So we got some receipt data. Now does it all 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]];
   }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top