应用内购买崩溃

时间:2011-06-08 13:06:24

标签: iphone objective-c xcode in-app-purchase

我正在尝试将应用内购买添加到我的iPhone应用中。但是,当我运行我的应用程序或尝试购买项目时,我的应用程序崩溃并显示下一个错误:

  

警告:无法读取/Developer/Platforms/iPhoneOS.platform/DeviceSupport/4.3.3(8J2)/Symbols/Developer/usr/lib/libXcodeDebuggerSupport.dylib(未找到文件)的符号。   (gdb)

我将StoreKit代码放在NSObject类中,查看下面的代码。

StorePurchase.h

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

@interface StorePurchase : NSObject <SKProductsRequestDelegate, SKPaymentTransactionObserver> {

}

- (void)loadStore;
- (void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions;
- (void)purchase;
- (void)productsRequest:(SKProductsRequest *)request didReceiveResponse:(SKProductsResponse *)response;

@end

StorePurchase.m

#import "StorePurchase.h"

@implementation StorePurchase

- (void)loadStore {

    if ([SKPaymentQueue canMakePayments]) {
        NSLog(@"Parental-controls are disabled");

        SKProductsRequest *request = [[SKProductsRequest alloc] initWithProductIdentifiers:[NSSet setWithObject:@"testding2"]];
        request.delegate = self;
        [request start];

    }
    else {
        NSLog(@"Parental-controls are enabled");
    }

}

- (void)purchase {

    SKPayment *payment = [SKPayment paymentWithProductIdentifier:@"testding2"];
    [[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 found, joepie!!!");
    } else if (!validProduct) {
        NSLog(@"No products available");
    }

}

- (void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions {

    for (SKPaymentTransaction *transaction in transactions) {

        switch (transaction.transactionState) {

            case SKPaymentTransactionStatePurchasing:

                break;

            case SKPaymentTransactionStatePurchased:

                [[SKPaymentQueue defaultQueue] finishTransaction:transaction];

                break;

            case SKPaymentTransactionStateRestored:
                [[SKPaymentQueue defaultQueue] finishTransaction:transaction];

                break;

            case SKPaymentTransactionStateFailed:
                if (transaction.error.code != SKErrorPaymentCancelled) {
                    NSLog(@"An error encounterd");
                }
                else {
                    NSLog(@"Cancelled!");
                }

                [[SKPaymentQueue defaultQueue] finishTransaction:transaction];

                break;

        }

    }

}

@end

我像这样调用方法“loadStore”:

StorePurchase *classStorePurchase = [[StorePurchase alloc] init];

[classStorePurchase loadStore];

我希望有人可以帮助我...

2 个答案:

答案 0 :(得分:0)

您是否添加了StoreKit框架参考?

答案 1 :(得分:0)

您可以避免使用常规UIAlertView

-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex

并将代码放在

之间
 if ([SKPaymentQueue canMakePayments]) {
  ...
   ...
    ..
   [tmp show];
 }

直接执行您用于管理每个操作的程序。

关注此

  - (BOOL)canMakePurchases
 {
return [SKPaymentQueue canMakePayments];
 }
  - (void)purchaseMyProduct:(SKProduct*)product{
if ([self canMakePurchases]) {
    SKPayment *payment = [SKPayment paymentWithProduct:product];
    [[SKPaymentQueue defaultQueue] addTransactionObserver:self];
    [[SKPaymentQueue defaultQueue] addPayment:payment];
}
else{
    UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:
    @"Purchases are disabled in your device" message:nil delegate:
    self cancelButtonTitle:@"Ok" otherButtonTitles: nil];
    [alertView show];
}
}
-(IBAction)purchase:(id)sender{
[self purchaseMyProduct:[validProducts objectAtIndex:0]];
purchaseButton.enabled = NO; 
 }

祝你好运