productsRequest 响应方法未调用

发布于 2024-08-30 13:26:51 字数 554 浏览 7 评论 0原文

向苹果商店发送请求,

- (void) requestProductData
{
 SKProductsRequest *request= [[SKProductsRequest alloc] initWithProductIdentifiers:
         [NSSet setWithObjects: featureAId,featureBId,nil]]; // add any other product here
 request.delegate = self;
 [request start];
}

我正在实施应用内购买,并且我通过响应方法

- (void)productsRequest:(SKProductsRequest *)request didReceiveResponse:(SKProductsResponse *)response
{
 [purchasableObjects addObjectsFromArray:response.products];
}

根本没有被调用。在我尝试的十次尝试中,只有一次它成功了。

I am implementing an in app purchase and I am sending the request to apple store through

- (void) requestProductData
{
 SKProductsRequest *request= [[SKProductsRequest alloc] initWithProductIdentifiers:
         [NSSet setWithObjects: featureAId,featureBId,nil]]; // add any other product here
 request.delegate = self;
 [request start];
}

the response method

- (void)productsRequest:(SKProductsRequest *)request didReceiveResponse:(SKProductsResponse *)response
{
 [purchasableObjects addObjectsFromArray:response.products];
}

is not getting called at all. Only once did it call out of ten attempts I tried.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

救星 2024-09-06 13:26:51

尝试还实现 - (void)request:(SKRequest *)request didFailWithError:(NSError *)error 方法 - 处理您的请求时可能会出现一些错误。

Try to implement also - (void)request:(SKRequest *)request didFailWithError:(NSError *)error method - may be there're some errors in processing of your requests.

陈独秀 2024-09-06 13:26:51

我遇到了同样的问题,但就我而言,原因是我正在使用自动引用计数并且我忘记保留请求。

我的代码是这样的:

- (void) requestProductData
{
    SKProductsRequest *request= [[SKProductsRequest alloc] initWithProductIdentifiers:[NSSet setWithObject:ProductIdentifier]];
    request.delegate = self;
    [request start];
}

但是委托的 productsRequest:didReceiveResponse: 从未被调用。

修复方法是:

@property (strong, nonatomic) SKProductsRequest *request;

- (void) requestProductData
{
    self.request= [[SKProductsRequest alloc] initWithProductIdentifiers:[NSSet setWithObject:ProductIdentifier]];
    self.request.delegate = self;
    [self.request start];
    // you can nil request property in request:didFailWithError: and requestDidFinish:
}

I faced the same problem, but in my case the cause was that I was using Automatic Reference Counting and I forgot to retain the request.

My code was like:

- (void) requestProductData
{
    SKProductsRequest *request= [[SKProductsRequest alloc] initWithProductIdentifiers:[NSSet setWithObject:ProductIdentifier]];
    request.delegate = self;
    [request start];
}

But delegate's productsRequest:didReceiveResponse: never got called.

A fix would be:

@property (strong, nonatomic) SKProductsRequest *request;

- (void) requestProductData
{
    self.request= [[SKProductsRequest alloc] initWithProductIdentifiers:[NSSet setWithObject:ProductIdentifier]];
    self.request.delegate = self;
    [self.request start];
    // you can nil request property in request:didFailWithError: and requestDidFinish:
}
橘寄 2024-09-06 13:26:51

我也有同样的问题。我创建了一个帮助程序类来处理 IAP 并检查产品。我最终发现我创建的类的实例在响应返回之前被释放,因此委托方法永远不会被调用,因为它们不再存在。

我通过在使用 @proprty(strong, nonatomic) 调用的类中保留辅助类的实例来解决我的问题...

如果您不使用辅助类并将其编码到现有类中,那么上面的答案将通过保留您的 SKProductRequest 来工作。

I had the same problem. I had created a helper class to handle the IAP and check for the products. What I finally found was the instance of the class I created was being released before the response came back, thus the delegate methods never got called because they did not exist anymore.

I solved my problem by retaining the instance of the helper class in the class I called it from using @proprty(strong, nonatomic)...

If you are not using a helper class and coding it into an existing class then the answer above will work by retaining your SKProductRequest.

随波逐流 2024-09-06 13:26:51

我也遇到过类似的问题(错误:无法连接到 iTunes Store)。将 iTunes Beta 升级到最新版本后,它再次开始工作。

I've had a similar problem (error: Cannot connect to iTunes Store). After upgrading iTunes Beta to the latest version it started working again.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文