如何设置SKP产品请求超时秒?SKProductsRequest 的默认超时秒是多少?



是否可以为 SKProductsRequest 设置超时?有人知道 SKProductsRequest 的默认超时吗?

没有打开苹果的 API 直接设置 SKProductRequests 超时,但是您可以实现一些简单的方法来手动设置它。在这种情况下,您需要保留对 SKProductsRequest 实例的强引用:

@property (nonatomic, strong) SKProductsRequest *productsRequest;

然后创建您的请求并使用 performSelector:withObject:afterDelay:在所需时间间隔内停止它的方法:

self.productsRequest = [[SKProductsRequest alloc] initWithProductIdentifiers:[StoreKitManager productsIDSet]];
self.productsRequest .delegate = self;
[self.productsRequest  start];
[self setupTimeout];
- (void)cancelTimeout {
    [NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(stopRequest) object:nil];
}
- (void)setupTimeout {
    [self cancelTimeout];
    [self performSelector:@selector(stopRequest) withObject:self afterDelay:30.0f];
}
- (void)stopRequest {
    [self.productsRequest cancel];
}

并且不要忘记取消委托中的超时:

- (void)productsRequest:(SKProductsRequest *)request didReceiveResponse:(SKProductsResponse *)response {
    [self cancelTimeout];
}
- (void)requestDidFinish:(SKRequest *)request {
    [self cancelTimeout];
}
- (void)request:(SKRequest *)request didFailWithError:(NSError *)error {
    [self cancelTimeout];
}

相关内容

  • 没有找到相关文章

最新更新