Cocoa SKProductRequest同步

Cocoa SKProductRequest同步,cocoa,storekit,Cocoa,Storekit,我已在操作块中启动产品请求 NSOperationQueue * queue = [[NSOperationQueue alloc] init]; [queue addOperationWithBlock:^{ SKProductsRequest * request= [[SKProductsRequest alloc] initWithProductIdentifiers: selectedSKIdentifiers]; request.delegate = sel

我已在操作块中启动产品请求

NSOperationQueue * queue = [[NSOperationQueue alloc] init];

[queue addOperationWithBlock:^{
      SKProductsRequest * request= [[SKProductsRequest alloc] initWithProductIdentifiers: selectedSKIdentifiers];

      request.delegate = self;

      [request start];

}];
所以我想使用一些同步版本,比如在下载数据时

NSData * data = [[NSData alloc] initWithContentsOfURL:url];
或者,解析XML也是同步的

NSXMLParser * parser = [[NSXMLParser alloc] initWithData:xmlData];
[parser setDelegate:self];
[parser parse];
[parser release];
是否有方法执行SKProductsRequest同步操作


苹果文档幸运地获得了关于这一主题的更多信息。在这一天,我找到了一种使任何方法同步的方法:

// create the object that will perform an async operation
MyConnection *conn = [MyConnection new];

// create the semaphore and lock it once before we start
// the async operation
self.theLock = [NSConditionLock new];

// start the async operation
self.testState = 0;
[conn doItAsyncWithDelegate:self];

// now lock the semaphore - which will block this thread until
// [self.theLock unlockWithCondition:1] gets invoked
[self.theLock lockWhenCondition:1];

// we're done
[self.theLock release];
[conn release];
确保调用

[self.theLock unlockWithCondition:1];
然后在代理中