您好,对于我正在处理的项目,我必须在后台执行 n-SLRequest,所以我需要将这些请求添加到 NSOperationQueue,如下面的代码所示
- (void)performBatchRequest:(void(^)(void))completion
{
NSURL *url = [NSURL URLWithString:@"https://api.twitter.com/1.1/direct_messages/new.json"];
NSOperationQueue *queue = [[NSOperationQueue alloc] init];
ACAccount *account = [self getStoredAccount];
for (NSDictionary *user in self.inviteList)
{
[queue addOperationWithBlock:^
{
NSDictionary *params = @{@"screen_name" :user[@"name"],@"text":@"message" }
SLRequest *inviteRequest = [SLRequest requestForServiceType:SLServiceTypeTwitter
requestMethod:SLRequestMethodPOST
URL:url
parameters:];
[inviteRequest setAccount:account];
[inviteRequest performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error)
{
if (error)
{
NSLog(@"Errror");
}
}];
}];
}
self.inviteList = nil;
if (completion)
{
completion();
}
}
现在我想知道这是否是我可以用来在后台执行多个 SLRequest 的最佳方法。非常感谢任何建议/更正