Reputation: 6620
I have a plugin class which is extending CDVPlugin. This plugin will invoked from a button click from HTML side. After that I am using UIImagePickerController to take two photos. Then I am trying to send those images to javascript callback function using pluginresult.
Here, as I am trying to send two images in one go, the UI is being stuck for some time. So, I want to send the result in a background thread. And also I should be receive that from javascript callback function.
Has someone done this before? Is there any way to achieve this so that UI navigation will be smoother....
Upvotes: 5
Views: 3703
Reputation: 53301
Something like this:
- (void)myPluginMethod:(CDVInvokedUrlCommand*)command
{
// Check command.arguments here.
[self.commandDelegate runInBackground:^{
NSString* payload = nil;
// Some blocking logic...
CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:payload];
// The sendPluginResult method is thread-safe.
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
}];
}
Upvotes: 6