我有一个免费的应用程序(已在App Store中提供),它具有非消耗性IAP选项,它只是一个具有更多功能的高级版本...最低部署目标是8.0
我使用RMStore库(https://github.com/robotmedia/RMStore)进行收据验证...我意识到在已购买任何其他应用程序的设备上执行时验证不正确。 我的意思是,如果他的设备中有人(带有相应的Apple ID)过去已经购买了任何其他应用程序,那么当我在我的应用程序中输入时,收据验证会返回OK(就像那个人已经购买了我的高级版本一样)但是它不是: - (
下面是我使用RMStore进行收据验证的代码(在AppDelegate中):
RMStoreAppReceiptVerifier *_receiptVerifier = [[RMStoreAppReceiptVerifier alloc] init];
[RMStore defaultStore].receiptVerifier = _receiptVerifier;
if (_receiptVerifier.verifyAppReceipt) {
NSLog(@"PREMIUM VERSION");
PremiumRM = YES;
} else {
NSLog(@"NOT PREMIUM VERSION");
PremiumRM = NO;
}
有什么问题?
顺便说一下,在StackOverFlow的RMStore库和收据验证的其他帖子中," RMStoreAppReceiptVerificator"提到图书馆,但我没有...我是否需要它作为强制性的? (我使用" RMAppReceipt"和#34; RMStoreAppReceiptVerifier"库代替)。
答案 0 :(得分:0)
我更改了代码如下......
- (BOOL)verifyReceiptWithCustomLogic
{
RMStoreAppReceiptVerifier *verificator = [RMStoreAppReceiptVerifier new];
if ([verificator verifyAppReceipt])
{
return [[RMAppReceipt bundleReceipt] containsInAppPurchaseOfProductIdentifier:_PremiumIdentifier];
}
return NO;
}
-(void)PremiumVerification
{
const BOOL verified = [self verifyReceiptWithCustomLogic];
if (verified)
{
// Verification succeeded
NSLog(@"PREMIUM VERSION");
_Premium = YES;
}
else
{ // Apple recommends to refresh the receipt if validation fails on iOS
[[RMStore defaultStore] refreshReceiptOnSuccess:^{
const BOOL verifiedagain = [self verifyReceiptWithCustomLogic];
if (verifiedagain)
{
// Verification succeeded
NSLog(@"PREMIUM VERSION");
_Premium = YES;
}
else
{
// Verification failed
NSLog(@"RECEIPT NOT VALID");
_Premium = NO;
}
} failure:^(NSError *error) {
// Verification failed
NSLog(@"RECEIPT NOT VALID");
_Premium = NO;
}];
}
}
在AppDelegate的application didFinishLaunchingWithOptions
中调用PremiumVerification,现在它似乎工作正常。
但另一方面,在我看来,也应该在applicationDidBecomeActive
中调用PremiumVerification只是为了在来自后台或非活动状态时再次验证收据,这是正确的吗?