在iPhone 5上都是好的,但在iPhone 3,4我得到交易失敗的狀態後按購買的按鈕... 我已嘗試幾乎所有東西,但始終同樣的問題,如果你有同樣的問題,你知道答案,請幫助它不到一分鐘;)謝謝!在應用程序購買不工作在iPhone 3,4
-(void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions {
for (SKPaymentTransaction *transaction in transactions) {
switch (transaction.transactionState) {
case SKPaymentTransactionStatePurchasing:{
// show wait view here
NSLog(@"Processing...");
break;
}
case SKPaymentTransactionStatePurchased:{
[[SKPaymentQueue defaultQueue] finishTransaction:transaction];
// remove wait view and unlock feature 2
NSLog(@"DONE!");
[prefs setObject:@"yes" forKey:@"payed"];
self.buyButton.hidden = TRUE;
[self getData:@"yes"];
break;
}
case SKPaymentTransactionStateRestored:{
[[SKPaymentQueue defaultQueue] finishTransaction:transaction];
NSLog(@"Error payment cancelled2");
break;
}
case SKPaymentTransactionStateFailed:{
if (transaction.error.code != SKErrorPaymentCancelled) {
NSLog(@"Error payment cancelled1:%@",transaction.error.description);
}
[[SKPaymentQueue defaultQueue] finishTransaction:transaction];
break;
}
default:{
break;
}
}
}
}
-(void)productsRequest:(SKProductsRequest *)request didReceiveResponse:(SKProductsResponse *)response
{
// remove wait view here
//statusLabel.text = @"";
int count = [response.products count];
if (count>0) {
SKProduct *validProduct = [response.products objectAtIndex:0];
//SKPayment *payment = [SKPayment paymentWithProduct:validProduct];
[[SKPaymentQueue defaultQueue] addTransactionObserver:self];
SKMutablePayment *payment = [SKMutablePayment paymentWithProduct:validProduct];
[[SKPaymentQueue defaultQueue] addPayment:payment];
} else {
// no products found
}
}
-(void)requestDidFinish:(SKRequest *)request
{
}
-(void)request:(SKRequest *)request didFailWithError:(NSError *)error
{
NSLog(@"Failed to connect with error: %@", [error localizedDescription]);
}
#pragma mark AlertView Delegate
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
NSLog(@"%d",buttonIndex);
if (alertView==askToPurchase) {
if (buttonIndex==1) {
// user tapped YES, but we need to check if IAP is enabled or not.
if ([SKPaymentQueue canMakePayments]) {
SKProductsRequest *request = [[SKProductsRequest alloc] initWithProductIdentifiers:[NSSet setWithObject:@"com.adam.CrowdControl.adamProduct1"]];
request.delegate = self;
[request start];
} else {
UIAlertView *tmp = [[UIAlertView alloc]
initWithTitle:@"Prohibited"
message:@"Parental Control is enabled, cannot make a purchase!"
delegate:self
cancelButtonTitle:nil
otherButtonTitles:@"Ok", nil];
[tmp show];
}
}
}
}