从Objective C委托回调到Cordova插件
情况:我正在构建一个cordova插件来将现有的iOS库与Ionic连接.方法的基本映射已完成且正在运行,这意味着我可以通过Angular方法调用iOS方法并获取成功/错误回调.
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.
问题:有一个登录方法被调用,然后调用了适当的委托方法(例如userDidLoginWithSuccess).从登录方法到cordova插件的回调很容易,但是我需要以某种方式从委托方法进行回调,以便让Ionic应用程序知道用户是否成功登录.
Problem: There's a login method which is called, and appropriate delegate methods (e.g. 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.
对此有何想法?谢谢.
PS:尽管这是一个类似的问题,但我检查了此帖子,但没有帮助. Phonegap-从Objective向Java脚本发送消息-c在插件委托中
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
在.h上创建一个属性callbackId,将用于存储插件的回调标识符
On your .h create a property callbackId that you will use to store the callback identifier of the plugin
@property (nonatomic, strong) NSString* callbackId;
然后,在您的插件方法上,将callbackId存储在您创建的属性上.
Then, on your plugin method, store the callbackId on the property you created.
self.callbackId = command.callbackId;
最后,在委托中,使用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];