Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS cordova plugin: How to send plugin result from ios plugin to javascript in background thread

Tags:

ios

cordova

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....

like image 405
Rashmi Ranjan mallick Avatar asked May 28 '13 13:05

Rashmi Ranjan mallick


1 Answers

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];
    }];
}
like image 55
jcesarmobile Avatar answered Nov 04 '22 01:11

jcesarmobile