cordova 插件开发留存文档

1、搭建 cordova 开发环境

     https://www.jianshu.com/p/6a6fc78d8e93

2、plugin.xml 文档配置,关联iOS相关资源文档

 

    <framework src="CoreFoundation.framework" />

    <source-file src="src/ios/rect.png" />

    <source-file src="src/ios/libGSDK.a" framework="true" />

    <header-file src="src/ios/JSONKit.h" compiler-flags="-fno-objc-arc" />

    <source-file src="src/ios/JSONKit.m" compiler-flags="-fno-objc-arc" />

 

  

3、MyJS.js 配置,配置js调用iOS相关类方法

var exec = require('cordova/exec');
var jsName = "MyJS";
var myjs = {
    //Bluetooth
    method: function (params, success, error) {
        exec(success, error, jsName, "method", [params]);
    },
}

module.exports = myjs;

4、iOS 类配置

#import <Cordova/CDV.h>

 

@interface MyJS : CDVPlugin

 

- (void)method::(CDVInvokedUrlCommand*)command;

 

@end

 

 

@implementation MyJS

 

- (void)method:(CDVInvokedUrlCommand*)command {

    [self.commandDelegate runInBackground:^{

         CDVPluginResult* pluginResult=nil;

         pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR

                                             messageAsString:@"-1"];

         //pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK

         //                                    messageAsString:@"1"];

 

         //多次回调
         [pluginResult setKeepCallback:@(YES)];


         [self.commandDelegate sendPluginResult:pluginResult

                                         callbackId:command.callbackId];

    }];

}

 

@end

猜你喜欢

转载自www.cnblogs.com/innovator/p/9103599.html