我正在关注this In App Purchase tutorial,我可以看到我在iTunesConnect IAP内容中发布的产品说明和标题。但是,当我点击buyButton
时,我收到了Thread 1:EXC_BAD_ACCESS(code=1, address=0xc)
错误:
- (IBAction)buyProduct:(id)sender {
SKPayment *payment = [SKPayment paymentWithProduct:_product];//<-- This line course the error.
[[SKPaymentQueue defaultQueue] addPayment:payment];
}
有人建议我在_product
之前和之后对buyButton
进行检查,结果确实不同:
-(void)productsRequest:(SKProductsRequest *)request didReceiveResponse:(SKProductsResponse *)response
{
NSArray *products = response.products;
if (products.count != 0)
{
_product = products[0];
_buyButton.enabled = YES;
_productTitle.text = _product.localizedTitle;
_productDescription.text = _product.localizedDescription;
NSLog(@"productsRequest: %@", _product);
//NSLog(@"productsRequest: %@", _product.localizedTitle);
} else {
_productTitle.text = @"Product not found";
}
products = response.invalidProductIdentifiers;
for (SKProduct *product in products)
{
NSLog(@"Product not found: %@", product);
}
}
- (IBAction)buyProduct:(id)sender {
NSLog(@"Product title: %@", _product);//<-- this give different result from productsRequest function.
}
从-(void)productsRequest
开始,
productsRequest: <SKProduct: 0x17e8e3f0>
来自- (IBAction)buyProduct
,我得到
Product title: #<CGRegion 0x17e8e3f0 empty>
有时随机的长期结果:
Product title: Length 11 (2 blocks, 1 used, block 0 is at 0)
11 0x165ae790 {
NSColor = "UIDeviceRGBColorSpace 0.838794 0.39337 1 1";
NSFont = "<UICTFont: 0x165ae010> font-family: \".HelveticaNeueInterface-M3\"; font-weight: normal; font-style: normal; font-size: 17.00pt";
NSParagraphStyle = "Alignment 1, LineSpacing 0, ParagraphSpacing 0, ParagraphSpacingBefore 0, HeadIndent 0, TailIndent 0, FirstLineHeadIndent 0, LineHeight 0/0, LineHeightMultiple 0, LineBreakMode 4, Tabs (\n 28L,\n 56L,\n 84L,\n 112L,\n 140L,\n 168L,\n 196L,\n 224L,\n 252L,\n 280L,\n 308L,\n 336L\n), DefaultTabInterval 0, Blocks (null), Lists (null), BaseWritingDirection -1, HyphenationFactor 0, TighteningFactor 0, HeaderLevel 0";
NSShadow = "NSShadow {0, -1} color = {(null)}";
}
知道如何解决这个问题?