Вопрос

In iOS how to perform a method with NSData return type in background.

I have tried this:

NSData *loginiddata=[self performSelectorInBackground:@selector(loaddatawithurl:param:) withObject:OBJ];

but its not working.

Это было полезно?

Решение

There are two problems with performSelectorInBackground in your case: That method has no return value (compare Ken Thomases' comment above), and it works only with methods taking a single argument. The easiest solution (in my opinion) is to use GCD (Grand Central Dispatch) methods instead:

dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
    NSData *loginiddata = [self loaddatawithurl:url params:params];
    // ... 
});
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top