Hello for a project I'm working on I have to perform n-SLRequest in background, So what I tought is to add these requests to an NSOperationQueue as the code below show
- (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();
}
}
Now What I'm wondering is if this is the best approach I can use to perform multiple SLRequest in background. Any suggestion / correction is really appreciated