我环顾了谷歌,几乎每一个关于添加应用内购买的stackoverflow问题,但似乎都不起作用。当我尝试在我的应用程序上进行购买时,一切正常,产品可用且一切正常,但有关购买的警报视图从未出现。这是我所有的 IAP 代码:
- (IBAction)tapsRemoveAdsButton{
NSLog(@"User taps remove ads button");
[self tapsRemoveAds];
}
- (void)tapsRemoveAds{
NSLog(@"User requests to remove ads");
if([SKPaymentQueue canMakePayments]){
NSLog(@"User can make payments");
SKProductsRequest *productsRequest = [[SKProductsRequest alloc] initWithProductIdentifiers:[NSSet setWithObject:kRemoveAdsProductIdentifier]];
productsRequest.delegate = self;
[productsRequest start];
}
else{
NSLog(@"User cannot make payments due to parental controls");
}
}
- (IBAction)purchase{
SKProduct *removeAdsProductID = (SKProduct *)kRemoveAdsProductIdentifier;
SKPayment *payment = [SKPayment paymentWithProduct:(SKProduct *)kRemoveAdsProductIdentifier];
[[SKPaymentQueue defaultQueue] addTransactionObserver:self];
[[SKPaymentQueue defaultQueue] addPayment:payment];
}
- (void)productsRequest:(SKProductsRequest *)request didReceiveResponse:(SKProductsResponse *)response{
SKProduct *validProduct = nil;
int count = [response.products count];
if(count > 0){
validProduct = [response.products objectAtIndex:0];
NSLog(@"Products Avalable!");
//[self sloganizeWord];
}
else if(!validProduct){
NSLog(@"No products avalable");
}
}
- (void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions{
for(SKPaymentTransaction *transaction in transactions){
switch (transaction.transactionState){
case SKPaymentTransactionStatePurchasing: NSLog(@"Transaction state -> Purchasing");
break;
case SKPaymentTransactionStatePurchased: [self doRemoveAds];
[[SKPaymentQueue defaultQueue] finishTransaction:transaction];
NSLog(@"Transaction state -> Purchased");
break;
case SKPaymentTransactionStateRestored:
NSLog(@"Transaction state -> Restored");
[[SKPaymentQueue defaultQueue] finishTransaction:transaction];
break;
case SKPaymentTransactionStateFailed:
if(transaction.error.code != SKErrorPaymentCancelled){
NSLog(@"Transaction state -> Cancelled");
}
[[SKPaymentQueue defaultQueue] finishTransaction:transaction];
break;
}
}
}
- (void)doRemoveAds{
areAdsRemoved = YES;
[[NSUserDefaults standardUserDefaults] setBool:areAdsRemoved forKey:@"areAdsRemoved"];
[[NSUserDefaults standardUserDefaults] synchronize];
}
如果我正确执行此操作,则警报视图应显示在我得到的控制台中的方法“paymentQueue”中:
user taps remove ads button
user requests to remove ads
user can make payments
products available!
一切直到 paymentQueue 方法,它也应该记录
transaction state -> purchasing
和其他的,我已经在 iTunes Connect 中设置了 IAP,并且 IAP 的 ID 是正确的。(否则它不会记录可用的产品)我在 iOS7 上使用的是非越狱设备,并且我已经设置了所有配置文件(或者至少我认为,因为我已经将应用程序提交到带有广告的应用程序商店) 同样,我已经查看了其他一些问题,但似乎没有一个问题对我有任何帮助。在此先感谢所有提供帮助的人:)