2 пользователя моего приложения, которые приобрели удаление рекламы, по-прежнему видят рекламу на своих устройствах. Проблема в том, что я не могу воспроизвести эту проблему ни на одном из моих устройств - она отлично работает на всех из них в Sandbox и даже с настоящим AppStore и Apple ID. Я потратил много часов, пытаясь выяснить причину проблемы, я дважды обновлял приложение, но оно не работало для одного пользователя, другой еще не обновил приложение. Я понятия не имею, как это исправить, может быть, кто-то здесь найдет что-то в моем коде?
вот мой код, ответственный за IAP:
- (void)viewDidLoad {
[super viewDidLoad];
[purchaseindicator stopAnimating];
[self getProductInfo];
myDefaults = [NSUserDefaults standardUserDefaults];
}
- (IBAction)restorePurchase:(id)sender{
[purchaseindicator startAnimating];
[[SKPaymentQueue defaultQueue] addTransactionObserver:self];
[[SKPaymentQueue defaultQueue] restoreCompletedTransactions];
}
- (IBAction)buyApp:(id)sender{
[purchaseindicator startAnimating];
if (product)
{
[[SKPaymentQueue defaultQueue] addTransactionObserver:self];
SKPayment *payment = [SKPayment paymentWithProduct:product];
[[SKPaymentQueue defaultQueue] addPayment:payment];
}
else
NSLog(@"Can't handle payment. Product is null");
}
- (void) getProductInfo
{
if ([SKPaymentQueue canMakePayments])
{
NSSet *productID = [NSSet setWithObject:@"xxx.xxx.xxx"];
SKProductsRequest *request = [[SKProductsRequest alloc]initWithProductIdentifiers:productID];
request.delegate = self;
[request start];
}
}
- (void) removeAds
{
NSLog(@"------------no ads--------------");
[myDefaults setObject:@"yes" forKey:@"purchased"];
[myDefaults synchronize];
[purchaseindicator stopAnimating];
}
- (void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions{
//NSLog(@"paymentQueue updatedTransactions");
for (SKPaymentTransaction *transaction in transactions)
{
switch (transaction.transactionState)
{
case SKPaymentTransactionStatePurchased:
NSLog(@"SKPaymentTransactionStatePurchased");
[self removeAds];
[[SKPaymentQueue defaultQueue] finishTransaction:transaction];
break;
case SKPaymentTransactionStateFailed:
NSLog(@"SKPaymentTransactionStateFailed");
[purchaseindicator stopAnimating];
[[SKPaymentQueue defaultQueue] finishTransaction:transaction];
break;
case SKPaymentTransactionStateRestored:
NSLog(@"SKPaymentTransactionStateRestored");
[self removeAds];
[[SKPaymentQueue defaultQueue] finishTransaction:transaction];
break;
case SKPaymentTransactionStatePurchasing:
NSLog(@"SKPaymentTransactionStatePurchasing");
break;
case SKPaymentTransactionStateDeferred:
NSLog(@"SKPaymentTransactionStateDeferred");
break;
default:
break;
}
}
}
- (void)productsRequest:(SKProductsRequest *)request didReceiveResponse:(SKProductsResponse *)response {
NSArray *products = response.products;
if ([products count] != 0)
{
product = [products objectAtIndex:0];
NSLog(@"product Title = %@", product.localizedTitle);
NSLog(@"product Description = %@", product.localizedDescription);
}
}
- (void)paymentQueue:(SKPaymentQueue *)queue restoreCompletedTransactionsFailedWithError:(NSError *)error{
[purchaseindicator stopAnimating];
//NSLog(@"Restore Completed Transactions Failed WithError...%@",error);
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"" message:@"Restore transaction unsuccessful..." preferredStyle:UIAlertControllerStyleAlert];
[alertController addAction:[UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action)
{}]];
[self presentViewController:alertController animated:YES completion:nil];
}
-(void)paymentQueueRestoreCompletedTransactionsFinished:(SKPaymentQueue *)queue {
//NSLog(@"received restored transactions: %lu", (unsigned long)queue.transactions.count);
[purchaseindicator stopAnimating];
NSMutableArray *arrPurchasedItemIDs = [[NSMutableArray alloc] init];
for (SKPaymentTransaction *transaction in queue.transactions)
{
NSString *productID = transaction.payment.productIdentifier;
[arrPurchasedItemIDs addObject:productID];
NSLog(@"arrPurchasedItemIDs : %@",arrPurchasedItemIDs);
if (transaction.transactionState == SKPaymentTransactionStateRestored) {
NSLog(@"Transaction State -> Restored");
[self removeAds];
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"" message:@"Restore transaction successful!" preferredStyle:UIAlertControllerStyleAlert];
[alertController addAction:[UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action)
{}]];
[self presentViewController:alertController animated:YES completion:nil];
[[SKPaymentQueue defaultQueue] finishTransaction:transaction];
break;
}else if(transaction.transactionState == SKPaymentTransactionStateFailed){
NSLog(@"Transaction State -> Restore Failed");
}else if(transaction.transactionState == SKPaymentTransactionStateDeferred){
NSLog(@"Transaction State -> Restore Deferred");
}else if(transaction.transactionState == SKPaymentTransactionStatePurchased){
NSLog(@"Transaction State -> Restore Purchased");
}
}
}
-(void)viewWillDisappear:(BOOL)animated{
[[SKPaymentQueue defaultQueue] removeTransactionObserver:self];
}
тогда, когда пользователь возвращается к предыдущему контроллеру просмотраЯ удаляю баннер следующим образом:
- (void) viewWillAppear:(BOOL)animated {
if([[myDefaults stringForKey:@"purchased"]isEqual:@"yes"]){
[GoogleBannerView removeFromSuperview];
}
}
, и вот мой ViewDidLoad в контроллерах представления, которые показывают рекламу:
- (void)viewDidLoad
{
[super viewDidLoad];
myDefaults = [NSUserDefaults standardUserDefaults];
NSLog(@"purchased: %@", [myDefaults stringForKey:@"purchased"]);
if(![[myDefaults stringForKey:@"purchased"]isEqual:@"yes"]){
GoogleBannerView = [[GADBannerView alloc] initWithAdSize:kGADAdSizeBanner];
CGRect frame = GoogleBannerView.frame;
frame.origin = CGPointMake(0.0, [UIScreen mainScreen].bounds.size.height - CGSizeFromGADAdSize(kGADAdSizeBanner).height);
GoogleBannerView.frame = frame;
self.GoogleBannerView.delegate = self;
self.GoogleBannerView.adUnitID = @"xxxxx";
self.GoogleBannerView.rootViewController = self;
GADMChartboostExtras *cbExtras = [[GADMChartboostExtras alloc] init];
cbExtras.framework = CBFrameworkOther;
cbExtras.frameworkVersion = @"8.0.1.1";
GADRequest *request = [GADRequest request];
[request registerAdNetworkExtras:cbExtras];
[self.GoogleBannerView loadRequest:request];
[self.view addSubview:GoogleBannerView];
self.interstitial_ = [self createAndLoadInterstitial];
[self showInterstitial];
}
}
Вы видите здесь, что вызывает проблему? После многих часов, потраченных на попытки исправить это, я просто сдаюсь :( Хуже всего то, что я не могу воспроизвести проблему на своих устройствах, поэтому я не знаю, что не так на этих устройствах двух пользователей