0
votes

I made in app purchase code and it returns me this:

2014-10-16 23:12:49.130 app[202:9218] BSXPCMessage received error for message: Connection interrupted
2014-10-16 23:12:53.531 app[202:9200] -[__NSCFConstantString productIdentifier]: unrecognized selector sent to instance 0xce14c
2014-10-16 23:12:53.533 app[202:9200] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFConstantString productIdentifier]: unrecognized selector sent to instance 0xce14c'
*** First throw call stack:
(0x23390f87 0x30d31c77 0x2339637d 0x23394259 0x232c5d68 0x2678cee1 0xcb349 0x2683f977 0x2683f919 0x2682a51d 0x2683f349 0x2683f023 0x26838929 0x2680f195 0x26a82853 0x2680dbd7 0x23357807 0x23356c1b 0x23355299 0x232a2db1 0x232a2bc3 0x2a5d6051 0x2686df01 0xcc815 0x312cdaaf)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb) 

It's my code:

#import "PurchaseViewController.h"
@interface PurchaseViewController ()
@property (strong, nonatomic) SKProduct *product;
@property (strong, nonatomic) PurchaseViewController *purchaseController;
@property (strong, nonatomic) NSString *productID;
@property (strong, nonatomic) IBOutlet UITextView *productDescription;
- (void)getProductInfo:(UIViewController *)viewController;
@end
@implementation PurchaseViewController
- (void)viewDidLoad {
  [super viewDidLoad];
_purchaseController = [[PurchaseViewController alloc]init];
[[SKPaymentQueue defaultQueue] addTransactionObserver:_purchaseController];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}
- (IBAction)purchaseItem:(id)sender {
_purchaseController.productID = @"game";

[self.navigationController
 pushViewController:_purchaseController animated:YES];
[_purchaseController getProductInfo: self];
SKPayment *payment = [SKPayment paymentWithProduct:_product];
[[SKPaymentQueue defaultQueue] addPayment:payment];
}
-(void)getProductInfo: (PurchaseViewController *) viewController
{
if ([SKPaymentQueue canMakePayments])
{
    SKProductsRequest *request = [[SKProductsRequest alloc]
                                  initWithProductIdentifiers:
                                  [NSSet setWithObject:self.productID]];
    request.delegate = self;
    [request start];
}
else
    _productDescription.text =
    @"Please enable In App Purchase in Settings";
     }
#pragma mark -
#pragma mark SKProductsRequestDelegate
-(void)productsRequest:(SKProductsRequest *)request didReceiveResponse:(SKProductsResponse *)response
{

NSArray *products = response.products;
products = response.invalidProductIdentifiers;
_product = products[0];
for (SKProduct *product in products)
{
    NSLog(@"Product not found: %@", product);
}
}
#pragma mark -
#pragma mark SKPaymentTransactionObserver
-(void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions
{
    for (SKPaymentTransaction *transaction in transactions)
    {
    switch (transaction.transactionState) {
        case SKPaymentTransactionStatePurchased:
            [self unlockFeature];
            [[SKPaymentQueue defaultQueue]
             finishTransaction:transaction];
            break;
        case SKPaymentTransactionStateFailed:
            NSLog(@"Transaction Failed");
            [[SKPaymentQueue defaultQueue]
             finishTransaction:transaction];
            break;     
        default:
            break;
    }
}
}
-(void)unlockFeature
{
    NSLog(@"bought");
}
@end
1
Which line of code is causing the problem? - rmaddy
I don't know. Everything looks good, but crashes. - Mikey
Use the debugger and see where it crashes. - rmaddy
How to check it? Sorry I'm new to ios development. - Mikey

1 Answers

0
votes

The error indicates that something is sending a productIdentifier getter message to a string. If you're not doing it yourself than it's probably the SKPaymentQueue trying to access the productIdentifier of ... maybe an SKProduct? However, instead of an SKProduct (or similar StoreKit object that responds to productIdentifier), it has a reference to a string.

Looking at your code (and not knowing where the crash happens) I'm going to guess that your _product is actually getting set to an NSString instead of a SKProduct. To test this, breakpoint the code in purchaseItem: just before paymentWithProduct: and type po [_product class] in the debugger. Is it actually an SKProduct?