我在app中购买了代码并将其返回给我:
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 :(得分:0)
错误表示正在向字符串发送productIdentifier getter消息。如果你自己没有这样做,可能是SKPaymentQueue试图访问...的产品标识符......也许是SKProduct?但是,它不是SKProduct(或响应productIdentifier的类似StoreKit对象),而是对字符串的引用。
查看你的代码(而不知道崩溃发生在哪里)我猜你的_product实际上是设置为NSString而不是SKProduct。要测试这一点,请断开purchaseItem中的代码:在paymentWithProduct:之前,并在调试器中键入po [_product class]。它实际上是SKProduct吗?