使用Cordova 开发iOS项目

版权声明:本博客内容归个人所有,如需转载,请标明出处。 https://blog.csdn.net/m0_37468171/article/details/89248757

Cordova 官方文档: http://cordova.axuer.com/docs/zh-cn/latest/guide/platforms/ios/plugin.html

1、cordova 入门(内容很丰富): https://blog.csdn.net/csdn100861/article/details/78585333

2、按照该教程操作:https://www.jianshu.com/p/5e15e34ea336 (与需求不符合)

3、iOS项目中如何删除CocoaPods: https://www.jianshu.com/p/e66b71122cfe

4、使用plugman 创建一个自己的cordova插件: https://blog.csdn.net/b2259909/article/details/52471178

5、使用plugman 创建cordova插件-iOS为例 https://www.jianshu.com/p/d95a6d78b32c

创建插件

plugman create --name MyPlugin --plugin_id com.lvlv --plugin_version 0.0.1 

6、添加插件:

cordova plugin add <你的插件(名称\路径\git地址)>
egg: cordova plugin add /Users/charls/Desktop/MyPlugins/MyPlugin

添加支持平台

plugman platform add --platform_name <platform>
egg : plugman platform add --platform_name ios

7、cordova 基本命令 以及如何添加,删除插件 https://www.cnblogs.com/huangenai/p/6840333.html

a、遇到的bug,说是在工程目录下未找到 shimitest-Info.plist 文件?
我从老项目中拷贝了一份plist文件放在了改目录下面,成功运行

b、我创建了一个Masonry静态库,结果报错:IView mas_makeConstraints:] : unrecognized selector that sent to instance #450
解决办法:在Build Settings —》Other Linker Flags 中添加 -ObjC,就可以了

c、将插件放到Cordova中报错: a parameter list without type is only allowed in a function definition

__weak typeof(self) weakSelf = self;
    self.stock.stockBlock = ^(NSInteger index) {
        [weakSelf fetchDataWithIndex:index];
    };

解决方法: 在buildsettings 中设置 Apple LLVM 9.0 - Language —》C Language Dialect —》 GNU99[-std=gnu99]

8、将项目中的第三方库打包成静态文件:https://www.jianshu.com/p/90f5ec723175

参考例子:

https://github.com/wymsee/cordova-imagePicker 这个特殊之处是页面使用xib
https://github.com/xu-li/cordova-plugin-wechat 这个特殊之处是可以在安装插件的时候配置一些变量到plist,同时引入三方sdk

9、编辑 plugin.xml 文件内容

官方文档:
http://cordova.axuer.com/docs/zh-cn/latest/plugin_ref/spec.html
博客:
https://www.jianshu.com/p/15251237061d

引入系统库:

<framework src="libz.tbd" />

自己的静态库:

<source-file src="src/ios/libs/OpenSDK1.8.0/libWeChatSDK.a" framework="true" />
<framework src="src/ios/AFNetworking.framework”  custom="true" />

自己的.h 和 .m 文件

<header-file src="src/ios/CDVWechat.h" />
<source-file src="src/ios/CDVWechat.m" />

xib 、图片 文件

10、编辑 index.js 和 Kline.js 文件

index.js 举例:

onDeviceReady: function() {
        app.receivedEvent('deviceready');
        alert("成功!");
        function success(){
            console.log("chenggong");
            alert("成功!");
        }
        function error(){
            alert("失败!");
        }
        
        cordova.plugins.kline.coolMethod('3',success,error);
    },

kline.js 举例:

cordova.define("com.lvlv.kline", function(require, exports, module) {
var exec = require('cordova/exec');

exports.coolMethod = function (arg0, success, error) {
    exec(success, error, 'kline', 'coolMethod', [arg0]);
};

});

猜你喜欢

转载自blog.csdn.net/m0_37468171/article/details/89248757