2011-06-08 180 views
1

我正在嘗試將應用內購買添加到我的iPhone應用。但是當我運行我的應用程序或嘗試購買商品我的應用程序崩潰,並顯示下一個錯誤:應用內購買崩潰

warning: Unable to read symbols for /Developer/Platforms/iPhoneOS.platform/DeviceSupport/4.3.3 (8J2)/Symbols/Developer/usr/lib/libXcodeDebuggerSupport.dylib (file not found). (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]; 

我希望有人能幫助我這個...

回答

0

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

+0

是的,在StorePurchase.h文件。當我嘗試購買一個物品時,我會彈出購買它,但是當我取消並再次嘗試時,它大多會崩潰... – Flappy 2011-06-08 13:14:24

+0

如果打開Objective-C異常的Break,它應顯示它正在崩潰的行。 ..運行 - >在Objective-c異常中停止。讓我知道什麼線路崩潰.... – 2011-06-08 13:15:50

+0

它停在這裏:如果([SKPaymentQueue canMakePayments]){ – Flappy 2011-06-08 13:22:14

0

可以避開一般的UIAlertView中

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

,並把直接在你用來管理每個itens的過程

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; 
} 

問候