内容简介:上一篇简单的整理了一下Podspec语法整理,主要是为了这一篇Flutter中iOS原生模块开发。在开发Flutte中我们难免会遇到原生组件、插件或者与原生模块通信,比如地图、引入第三方sdk如微信、支付宝等SDK,还有摄像头SDK,我们必须要用到原生, 当然你也可以用pub.dev/flutter中的,但是这并不是最终的解决之道,Flutter刚发展不久,假如刚好没有或者并不满足你的需求,因此这就需要自己动手,俗话说自己动手丰衣足食这种方法比较简单就像iOS项目中直接引用,前提是pod search可以搜
上一篇简单的整理了一下Podspec语法整理,主要是为了这一篇Flutter中iOS原生模块开发。
简介
在开发Flutte中我们难免会遇到原生组件、插件或者与原生模块通信,比如地图、引入第三方sdk如微信、支付宝等SDK,还有摄像头SDK,我们必须要用到原生, 当然你也可以用pub.dev/flutter中的,但是这并不是最终的解决之道,Flutter刚发展不久,假如刚好没有或者并不满足你的需求,因此这就需要自己动手,俗话说自己动手丰衣足食
用法一,直接引用
这种方法比较简单就像iOS项目中直接引用,前提是pod search可以搜索到它。
#
# To learn more about a Podspec see http://guides.cocoapods.org/syntax/podspec.html
#
Pod::Spec.new do |s|
s.name = 'flutter_txmap_plugin'
s.version = '0.0.1'
s.summary = '一款腾讯地图Flutter插件'
s.description = <<-DESC
一款腾讯地图Flutter插件
DESC
s.homepage = 'http://example.com'
s.license = { :file => '../LICENSE' }
s.author = { 'Your Company' => 'my_snail@126.com' }
s.source = { :path => '.' }
s.source_files = 'Classes/**/*'
s.public_header_files = 'Classes/**/*.h'
s.dependency 'Flutter'
## 引入,还可以携带版本号
s.dependency 'AFNetworking', '~> 1.0'
s.ios.deployment_target = '9.0'
end
复制代码
用法二,将第三方库copy到新建的文件夹中
这种方法我们不可以像第一种直接引入,因为pod search根本搜索不到,比如腾讯地图,遇到这种方式的话只有下载他们的库,然后引入,例如:
#
# To learn more about a Podspec see http://guides.cocoapods.org/syntax/podspec.html
#
Pod::Spec.new do |s|
s.name = 'flutter_txmap_plugin'
s.version = '0.0.1'
s.summary = '一款腾讯地图Flutter插件'
s.description = <<-DESC
一款腾讯地图Flutter插件
DESC
s.homepage = 'http://example.com'
s.license = { :file => '../LICENSE' }
s.author = { 'Your Company' => 'my_snail@126.com' }
s.source = { :path => '.' }
s.source_files = 'Classes/**/*'
s.public_header_files = 'Classes/**/*.h'
s.dependency 'Flutter'
# 引入资源,比如我们想要显示标注的图片
s.resources = ['Images/*.png']
# 腾讯地图的framework库,pod search搜索的应该是很早的版本和最新的api对应不上
s.vendored_frameworks = 'Frameworks/QMapKit.framework', 'Frameworks/TencentLBS.framework'
s.ios.deployment_target = '9.0'
end
复制代码
第三种,假如不是framework库而是 .a 文件
最近在引入一个摄像头sdk和配置设备到Wi-Fi下面,都是.a的库,这种方式又是如何引入了,也是搞了好久,终于在 guides.cocoapods.org/syntax/pods… 中找到了 如下:
#
# To learn more about a Podspec see http://guides.cocoapods.org/syntax/podspec.html
#
Pod::Spec.new do |s|
s.name = 'erazl_plugin'
s.version = '0.0.1'
s.summary = 'A new flutter plugin project.'
s.description = <<-DESC
A new flutter plugin project.
DESC
s.homepage = 'http://example.com'
s.license = { :file => '../LICENSE' }
s.author = { 'Your Company' => 'email@example.com' }
s.source = { :path => '.' }
s.source_files = 'Classes/**/*'
s.public_header_files = 'Classes/**/*.h', 'Library/*.h'
# 引入Library文件夹下所有的*.a库
s.vendored_libraries = 'Library/*.a'
s.frameworks = 'MobileCoreServices', 'CFNetwork', 'CoreGraphics'
# 只是引入*.a库还是不行,还是要引入相关联的系统库,否则无法编译通过
# 用户目标(应用程序)需要链接的系统库列表,
s.libraries = 'z.1.2.5', 'c++', 'c', 'iconv.2.4.0', 'sqlite3', 'stdc++.6.0.9', 'xml2', 'bz2.1.0', 'resolv', 'xml2', 'z'
s.dependency 'Flutter'
s.ios.deployment_target = '9.0'
end
复制代码
上诉就是最近在开发iOS原生模块时遇到的各种问题,在此做个简单的总结,如果还有其他方式欢迎互相学习
以上所述就是小编给大家介绍的《Flutter插件开发《iOS原生模块开发》》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!
猜你喜欢:- 原生革命--跨平台开发技术解析
- 谁告诉你 Flutter 会干掉原生开发?
- Flutter 混合开发(集成到原生 iOS 项目)
- 基于 Go 语言开发 Serverless 云原生应用
- 持久存储为云原生开发人员带来更多自由
- 微信小程序之大转盘抽奖原生开发
本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
Domain-Driven Design Distilled
Vaughn Vernon / Addison-Wesley Professional / 2016-6-2 / USD 36.99
Domain-Driven Design (DDD) software modeling delivers powerful results in practice, not just in theory, which is why developers worldwide are rapidly moving to adopt it. Now, for the first time, there......一起来看看 《Domain-Driven Design Distilled》 这本书的介绍吧!