我正在制作一个应用程序,其中,我必须使我的Inappurchase产品自动更新,为此,在阅读Apple文档后,我发现每次自动更新产品的交易后,我们的应用程序会收到每次购买的交易收据并且我需要在验证我的交易收据应用程序之后验证来自Apple服务器的收据是否必须保存该交易日期。 但在购买产品后,当我试图通过Apple Classes -Verification Controller验证来自Apple服务器的交易收据时,我的应用程序在完成处理程序中崩溃,其显示完成处理程序NIL。
当执行到达任何这些方法时,我的_completionHandlers被释放了什么? 请指导我解决这个问题
- (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);
}
}
答案 0 :(得分:5)
我也遇到了这个问题我用这种方式解决了这个问题 主要问题是当你在verifyPurchase方法中设置值为完成处理程序时,它设置为nil值,所以在verifyPurchase方法中找到这一行
_completionHandlers[[NSValue valueWithNonretainedObject:conn]] = completionHandler;
并将其替换为
[_completionHandlers setObject:[completionHandler copy] forKey:[NSValue valueWithNonretainedObject:conn]];
更改这两行将解决您的崩溃,但要确保执行这些步骤
找到connectionDidReceivedata方法并将其替换为
- (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]];
}