我在App Store上有一个应用程序,它有一个应用内购买功能。 应用内购买工作数月没有任何问题,但突然停止了收据验证工作。 我不知道为什么,因为代码上的任何内容都没有改变。
是否有人可以对此进行遮挡? Apple最近是否改变了有关应用内购买的内容?
非常感谢! Eduardo Rangel
答案 0 :(得分:1)
如果您使用CargoBay第三方库来验证收据,这个框架已经有一段时间已经遭受证书过期,并且不再完全正常工作但是有一个工作可以让它部分工作,但我不是确定是不是你的情况。
如果您正在使用CargoBay,请在CBPurchaseInfoFromTransactionReceipt
中进行以下更改,并注释掉一部分将禁用部分本地安全检查的代码。
NSDictionary * CBPurchaseInfoFromTransactionReceipt(NSData *transactionReceiptData, NSError * __autoreleasing *error) {
NSDictionary *transactionReceiptDictionary = [NSPropertyListSerialization propertyListWithData:transactionReceiptData options:NSPropertyListImmutable format:nil error:error];
if (!transactionReceiptDictionary || ![transactionReceiptDictionary respondsToSelector:@selector(objectForKey:)]) {
return nil;
}
NSString *purchaseInfo = [transactionReceiptDictionary objectForKey:@"purchase-info"];
NSDictionary *purchaseInfoDictionary = [NSPropertyListSerialization propertyListWithData:CBDataFromBase64EncodedString(purchaseInfo) options:NSPropertyListImmutable format:nil error:error];
if (!purchaseInfoDictionary) {
return nil;
}
// Comment this section skipping local purchase validation. It's failing in Sandbox due to the old hardcoded certificate from April 2016, and it will move to Production in mid May 2016.
// Cargobay will still verify the purchase with the Apple Sandbox/Production server after skipping the local verification. Hopefully update hardcoded certificate
// in order to move back to Cargobay repository.
/*
NSString *signature = [transactionReceiptDictionary objectForKey:@"signature"];
NSDate *purchaseDate = CBDateFromDateString([purchaseInfoDictionary objectForKey:@"purchase-date"]);
if (!CBCheckReceiptSecurity(purchaseInfo, signature, purchaseDate)) {
if (error) {
NSMutableDictionary *userInfo = [NSMutableDictionary dictionary];
[userInfo setValue:NSLocalizedStringFromTable(@"Cannot extract purchase info from transaction receipt because purchase info failed to validate against its signature.", @"CargoBay", nil) forKey:NSLocalizedDescriptionKey];
[userInfo setValue:NSLocalizedStringFromTable(@"Purchase info failed to validate against its signature.", @"CargoBay", nil) forKey:NSLocalizedFailureReasonErrorKey];
*error = [NSError errorWithDomain:CargoBayErrorDomain code:CargoBayErrorCannotExtractPurchaseInfoFromTransactionReceipt userInfo:userInfo];
}
return nil;
}
*/
return purchaseInfoDictionary;
}