在使用自动参考Couting的应用程序购买:SKProductsRequestDelegate崩溃 [英] In app purchase with Automatic Reference Couting: SKProductsRequestDelegate crashes

查看:156
本文介绍了在使用自动参考Couting的应用程序购买:SKProductsRequestDelegate崩溃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我现在已经尝试了两天在iOS应用中实施应用购买,同样的错误让我烦恼。

I've now been trying for two days to implement in app purchase in an iOS app, with the same error bugging me.

我每次都收到一个EXC_BAC_ACCESS错误时间我尝试启动我的SKProductsRequest对象。

I get an EXC_BAC_ACCESS error every time I try to start my SKProductsRequest object.

我已经读过几十个人,我有同样的错误,但没有一个解决方案似乎适合我。

I've read dozens of people having me same error, but none of the solutions seems to work for me.

当我设置NSZombieEnabled时,我收到以下错误:

When I set NSZombieEnabled, i get following error:

[AppShopper respondsToSelector:]: message sent to deallocated instance 0x1d9340

这是我的AppShopper.h:

Here's my AppShopper.h:

#import <StoreKit/StoreKit.h>

#define kInAppPurchaseManagerProductsFetchedNotification @"kInAppPurchaseManagerProductsFetchedNotification"


@interface AppShopper : NSObject <SKProductsRequestDelegate>

@property (nonatomic, strong) SKProduct *product;
@property (nonatomic, strong) SKProductsRequest *request;

- (void) requestProductData;

@end

和我的AppShopper.m:

And my AppShopper.m:

#import "AppShopper.h"

@implementation AppShopper

#define productId @"XXX.ProductID.XXX"

@synthesize request = _request;
@synthesize product = _product;

- (void) request:(SKRequest *)request didFailWithError:(NSError *)error{
    printf("Error!\n");
    _request = nil;
    _product = nil;
}

- (void) requestDidFinish:(SKRequest *)request {
    printf("Finished request!\n");
}

- (void) requestProductData{
    printf("requestProductData\n");

    NSSet *productIdentifiers = [NSSet setWithObject:productId];

    self.request = [[SKProductsRequest alloc] initWithProductIdentifiers: productIdentifiers];

    self.request.delegate = self;
    [self.request start];

    printf("requestProductData End\n");
}

#pragma mark -
#pragma mark SKProductsRequestDelegate methods

- (void)productsRequest:(SKProductsRequest *)request didReceiveResponse:(SKProductsResponse *)response
{
    printf("productsRequest\n");
    NSArray *products = response.products;

    self.product = [products count] == 1 ? [products objectAtIndex:0] : nil;
    if (self.product)
    {
        NSLog(@"Product title: %@" , self.product.localizedTitle);
        NSLog(@"Product description: %@" , self.product.localizedDescription);
        NSLog(@"Product price: %@" , self.product.price);
        NSLog(@"Product id: %@" , self.product.productIdentifier);
    }

    for (NSString *invalidProductId in response.invalidProductIdentifiers)
    {
        NSLog(@"Invalid product id: %@" , invalidProductId);
    }

    _request = nil;
    _product = nil;

    [[NSNotificationCenter defaultCenter] postNotificationName:kInAppPurchaseManagerProductsFetchedNotification object:self userInfo:nil];
}


@end

我试试使用以下代码开始应用内购买:

I try to start the in app purchase with the following code:

AppShopper *shopper = [[AppShopper alloc] init];
[shopper requestProductData];

我的输出仅为:

requestProductData
requestProductData End

2012-09-10 19:43:30.210 MyApp[4327:707] *** -[AppShopper respondsToSelector:]: message sent to deallocated instance 0x1d9340

而且,是的我是:


  1. 在物理设备上进行测试

  2. 在沙盒环境中与测试用户

  3. 并提供适当的配置文件

感谢任何帮助。谢谢。

推荐答案

该错误将出现在您的 AppShopper 中。

The bug will be in whichever object makes your AppShopper.

例如,

AppShopper *shopper = [AppShopper new];
... setup shopper here ...
[shopper requestProductData];

ARC如何知道您要保留 AppShopper 左右?它没有,它将在 requestProductData 之后立即释放它。然后,当请求返回时,它将尝试调用它的委托方法,这将不再存在。

How does ARC know that you want to keep your AppShopper around? It doesn't and it will release it immediately after requestProductData. Then, when the request returns it will try to call it's delegate methods, which won't exist anymore.

尝试存储 AppShopper 作为强大的属性而不是局部变量,看看是否有帮助。

Try storing your AppShopper as a strong property instead of a local variable and see if that helps.

这篇关于在使用自动参考Couting的应用程序购买:SKProductsRequestDelegate崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆