1
votes

I'm trying to add In-App Purchase to my iPhone app. But when i run my app or try to purchase a item my app crashes and shows the next error:

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)

I placed the StoreKit code in a NSObject class, look the code bellow.

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

I call the method "loadStore" like this:

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

[classStorePurchase loadStore];

I hope someone can help me with this...

2

2 Answers

0
votes

Have you added the StoreKit framework reference?

0
votes

You can avoid the general UIAlertView

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

and put the code between the

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

directly on the procedure you've used to manage each of the itens.

Follow this

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

Best regards