Reputation: 119
My iOS app uses a C function for some computing. I want to call it from -(void)viewDidLoad but I don't want it to freeze the main thread. I tried calling it with dispatch_async(dispatch_get_main_queue... block but it still was being called on the main thread. Also including function call into objective-c method and calling [self performSelector: InBackground] didn't work either. Please help. Is there any way I can perform C function in background in objective-c app ?
Upvotes: 0
Views: 841
Reputation:
Or you can put it into an obj-c method and call that using:
[NSThread detachNewThreadSelector:(SEL)aSelector toTarget:(id)aTarget withObject:(id)anArgument];
Upvotes: 0
Reputation: 130082
You have to use a different queue, e.g.:
dispatch_queue_t backgroundQueue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
dispatch_async(backgroundQueue, ^{
// do something
});
See Dispatch Queues for more details.
Upvotes: 2