iOS7 - 在应用内购买问题

时间:2014-01-17 16:11:36

标签: ios ios7 in-app-purchase

我已将应用程序上传到AppStore给客户。除了In App Purchases,一切正常。他们可以购买产品,但代理方法似乎并未因完整交易而被解雇。虽然,如果按下“恢复”按钮(我制作),他们会收回他们购买的东西,所以我的问题是我需要能够确认他们的产品而不必恢复它。

我的标题文件:

#import <UIKit/UIKit.h>
#import <StoreKit/StoreKit.h>

@interface StartViewController : UIViewController<UIAlertViewDelegate,SKPaymentTransactionObserver, SKProductsRequestDelegate>

@property (strong, nonatomic) IBOutlet UIScrollView *scrollview;

@property (strong, nonatomic) SKProduct *product;
@property (strong, nonatomic) NSString *productID;
@property (strong, nonatomic) SKProductsRequest *request;

@end

我的主要档案(相关部分):

       - (void)buyPro1{
    if ([SKPaymentQueue canMakePayments]){
        self.productID = PRODUCT_ID_PRO1; // NSString
        self.request = [[SKProductsRequest alloc]
                                      initWithProductIdentifiers:
                                      [NSSet setWithObject:self.productID]];
        self.request.delegate = self;
        [self.request start];

        NSLog(@"starting buy!!");
    }
    else{
        UIAlertView *a = [[UIAlertView alloc] initWithTitle:nil message:@"Please enable In App Purchase in Settings" delegate:nil cancelButtonTitle:nil otherButtonTitles:@"OK", nil];
        [a show];
    }
}  

        - (void)buyPro2{
            if ([SKPaymentQueue canMakePayments]){
                self.productID = PRODUCT_ID_PRO2; // NSString


    self.request = [[SKProductsRequest alloc]
                            initWithProductIdentifiers:
                            [NSSet setWithObject:self.productID]];
            self.request.delegate = self;
            [self.request start];

            NSLog(@"starting buy!!");
        }
        else{
            UIAlertView *a = [[UIAlertView alloc] initWithTitle:nil message:@"Please enable In App Purchase in Settings" delegate:nil cancelButtonTitle:nil otherButtonTitles:@"OK", nil];
            [a show];
        }
    }

#pragma mark SKProductsRequestDelegate

-(void)productsRequest:(SKProductsRequest *)request didReceiveResponse:(SKProductsResponse *)response{

    NSArray *products = response.products;

    NSLog(@"starting buy 2!!");

    if (products.count != 0)
    {
        self.product = products[0];

        NSLog(@"pro: %@", self.product.localizedTitle);
        SKPayment *payment = [SKPayment paymentWithProduct:self.product];
        [[SKPaymentQueue defaultQueue] addPayment:payment];

    } else {
        NSLog(@"pro: not found");
    }

}

#pragma mark SKPaymentTransactionObserver

-(void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions
{
    for (SKPaymentTransaction *transaction in transactions)
    {
        switch (transaction.transactionState) {
            case SKPaymentTransactionStatePurchased:
                if([self.productID isEqualToString:PRODUCT_ID_PRO1]){
                    [[SessionManager sharedSession] setAppLimitVersion:PRO_ONE];
                    UIAlertView *a = [[UIAlertView alloc] initWithTitle:nil message:@"Du har nu 3 veckors schemat" delegate:nil cancelButtonTitle:nil otherButtonTitles:@"OK", nil];
                    [a show];
                }
                else if([self.productID isEqualToString:PRODUCT_ID_PRO2]){
                    [[SessionManager sharedSession] setAppLimitVersion:PRO_TWO];
                    UIAlertView *a = [[UIAlertView alloc] initWithTitle:nil message:@"Du har nu 6 veckors schemat" delegate:nil cancelButtonTitle:nil otherButtonTitles:@"OK", nil];
                    [a show];
                }
                [[SKPaymentQueue defaultQueue]
                 finishTransaction:transaction];
                break;

            case SKPaymentTransactionStateFailed:{
                UIAlertView *a = [[UIAlertView alloc] initWithTitle:nil message:@"Betalningen misslyckades" delegate:nil cancelButtonTitle:nil otherButtonTitles:@"OK", nil];
                [a show];

                [[SKPaymentQueue defaultQueue]
                 finishTransaction:transaction];
                break;
            }

            default:
                break;
        }
    }
}


- (void)request:(SKRequest *)request didFailWithError:(NSError *)error{
    UIAlertView *a = [[UIAlertView alloc] initWithTitle:nil message:error.localizedDescription delegate:nil cancelButtonTitle:nil otherButtonTitles:@"OK", nil];
    [a show];
}

我会为此提出赏金,但我必须等待2天。任何一个可以帮助我的人,我真的很感激。

0 个答案:

没有答案
相关问题