简体   繁体   中英

Callback to Cordova plugin from Objective C delegate

Situation: I'm building a cordova plugin to connect an existing iOS library with Ionic. The base mapping of methods is done and working, means I can call the iOS methods via Angular methods and getting success/error callbacks.

Problem: There's a login method which is called, and appropriate delegate methods (eg userDidLoginWithSuccess) are called afterwards. Callback from the login method to the cordova plugin is easy, but I need to somehow callback from the delegate method, in order to let the Ionic app know if the user was logged in successfully or not.

Any thoughts on this? Thanks.

PS: I checked this post, which didn't help, although it's a similar question. Phonegap - Send message to Javascript from Objective-c in a plugin delegate

On your .h create a property callbackId that you will use to store the callback identifier of the plugin

@property (nonatomic, strong) NSString* callbackId;

Then, on your plugin method, store the callbackId on the property you created.

self.callbackId = command.callbackId;

and finally, on the delegate send the plugin result using the callbackId

CDVPluginResult* result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:@"string result"];
[self.commandDelegate sendPluginResult:result callbackId:self.callbackId];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM