2014-10-16 4 views
0

я сделал в приложение код покупки и возвращает мне это:OBJ с ошибкой покупки приложение

 
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) 

Это мой код:

#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 
+0

Какая строка кода вызывает проблему? – rmaddy

+0

Не знаю. Все выглядит хорошо, но падает. – Mikey

+0

Используйте отладчик и посмотрите, где он сбой. – rmaddy

ответ

0

Ошибка указывает на то, что что-то посылает геттер сообщение productIdentifier к строке. Если вы не делаете это самостоятельно, это, вероятно, SKPaymentQueue пытается получить доступ к productIdentifier ... возможно, SKProduct? Однако вместо SKProduct (или аналогичного объекта StoreKit, который отвечает на productIdentifier), он ссылается на строку.

Глядя на ваш код (и не зная, где произошел сбой) Я собираюсь предположить, что ваш _product фактически получает значение NSString вместо SKProduct. Чтобы проверить это, остановите код в buyItem: перед платежомWithProduct: и введите po [_product class] в отладчике. Это действительно SKProduct?

Смежные вопросы