当前位置: 首页 > news >正文

Flutter插件ios_pod

Flutter创建插件的命令

创建插件的命令flutter create --org com.plugin.demo --template=plugin --platforms=android,ios -i swift -a java plugin_demo

OC引用swift 文件

.m文件中添加以下代码//以下代码实现OC调用Swift
#if __has_include(<plugin_demo/plugin_demo-Swift.h>)#import <plugin_demo/plugin_demo-Swift.h>
#else// Support project import fallback if the generated compatibility header// is not copied when this plugin is created as a library.// https://forums.swift.org/t/swift-static-libraries-dont-copy-generated-objective-c-header/19816#import "plugin_demo-Swift.h"
#endif

IOS插件plugin_demo.podspec配置


当对.podspec文件进行修改后,需要对项目执行pod install才有效#
# To learn more about a Podspec see http://guides.cocoapods.org/syntax/podspec.html.
# Run `pod lib lint plugin_demo.podspec` to validate before publishing.
#
Pod::Spec.new do |s|s.name             = 'plugin_demo's.version          = '0.0.1's.summary          = 'A new Flutter plugin project.'s.description      = <<-DESC
A new Flutter plugin project.DESCs.homepage         = 'http://example.com's.license          = { :file => '../LICENSE' }s.author           = { 'Your Company' => 'email@example.com' }s.source           = { :path => '.' }#s.source_files = 'Classes/**/*'#指定包含的源文件类型,但是插件中用到的.metallib,.tflite,.mbd文件放置在pod所在的文件夹下不能正常#引用,需要放到主项目中s.source_files = ['Classes/**/*.{swift,h,m,mm,framework,tflite,bmd,metallib}']s.dependency 'Flutter's.platform = :ios, '12.0'# 指定桥接头文件路径,实现swift文件能访问oc文件s.user_target_xcconfig = {'SWIFT_OBJC_BRIDGING_HEADER' => '${PODS_ROOT}/../.symlinks/plugins/plugin_demo/ios/Classes/plugin_demo-Bridging-Header.h'}
#指定用到的其他.frameworks.vendored_frameworks = "*.framework"#指定用到的系统frameworks.frameworks = "AppTrackingTransparency"#PODS_TARGET_SRCROOT =# Flutter.framework does not contain a i386 slice.s.pod_target_xcconfig = { 'DEFINES_MODULE' => 'YES', 'EXCLUDED_ARCHS[sdk=iphonesimulator*]' => 'i386' }s.swift_version = '5.0'# If your plugin requires a privacy manifest, for example if it uses any# required reason APIs, update the PrivacyInfo.xcprivacy file to describe your# plugin's privacy impact, and then uncomment this line. For more information,# see https://developer.apple.com/documentation/bundleresources/privacy_manifest_files# s.resource_bundles = {'plugin_demo_privacy' => ['Resources/PrivacyInfo.xcprivacy']}
end

官方文档

https://guides.cocoapods.org/syntax/podspec.html

以下配置来源于网上

   s.ios.source_files = 'PoCSDK/Classes/**/*','PoCSDK/Frameworks/Sinch.frameworks/Headers/*'#引用的第三方frameworks.ios.vendored_frameworks = 'PoCSDK/Sinch.framework'#配置头文件s.ios.public_header_files = 'PoCSDK/Frameworks/Sinch.frameworks/Headers/*'s.resource_bundles = {'NoddsSDK' => ['PoCSDK/Assets/*']}#指定项目中用到的系统库s.frameworks = 'UIKit', 'MapKit', 'AudioToolbox', 'AVFoundation's.ios.dependency 'Alamofire', '~> 4.5's.ios.dependency 'Socket.IO-Client-Swift's.ios.dependency 'ReachabilitySwift'

其它问题

当在.podspec文件中通过s.vendored_frameworks 配置了引用的第三方framework,但是build时依然编译不过
出现找不到对应的文件时,如 
iOS Undefined symbol: _OBJC_CLASS_$_XXXXXX , _OBJC_CLASS_$_XXX", referenced from:        in XXX.o  
解决方法:
1.点击Pods 在TARGETS 找到对应的插件。
2.切换到General -> Frameworks and Libraries 中点击加号+选择。
3.选择在插件目录中用到的framework.
3.视情况看是否对Framework标记为 Embed & Sign
http://www.lqws.cn/news/576541.html

相关文章:

  • 地级市-固定资产投资数据(2000-2023年)-实证数据
  • 气候智能体:AI如何重构人类应对气候危机的决策体系?
  • LabVIEW荧光微管图像模拟
  • Swift 实现二叉树垂直遍历:LeetCode 314 完整解析与实战示例
  • Pytest自动化测试框架入门?
  • Nordic空中升级OTA[NRF52832蓝牙OTA]
  • 免费文件管理 智能转换GC-Prevue:PDF 转 Word 多种格式 一键完成
  • 重构老项目不再“踩雷”:飞算JavaAI的本地化智能合并实战
  • Java基础(六):数组全面解析
  • 一套非常完整的复古传奇源码测试
  • 【时时三省】vectorcast使用教程
  • ChatGPT、DeepSeek等大语言模型技术教程
  • 【零基础学AI】第14讲:支持向量机实战 - 文本分类系统
  • EA自动交易完全指南:从策略设计到实盘部署
  • C# 委托(Lambda表达式)
  • 【冷知识】Spring Boot 配置文件外置
  • windows下使用cmake编译mingw版本的bcg729
  • 跨时间潜运动迁移以实现操作中的多帧预测
  • 出现滑块验证码的主要原因是什么?
  • 前端开发面试题总结-原生小程序部分
  • [特殊字符] Python 实战 | 从 Excel 提取数据 → 生成美观 Word 收货记录表格(含合并单元格 + 总计功能)
  • 力扣面试150(7/150)
  • 【MySQL】JDBC编程
  • 什么是集装箱残损识别系统?它如何提升港口效率?
  • 【AI时代速通QT】第四节:Windows下Qt Creator调试指南
  • nifi1.28.1集群部署详细记录
  • 【51单片机用数码管显示流水灯的种类是按钮控制数码管加一和流水灯】2022-6-14
  • JavaEE初阶第五期:解锁多线程,从 “单车道” 到 “高速公路” 的编程升级(三)
  • vue-32(部署一个 Nuxt.js 应用程序)
  • 多线程环境下的线程安全资源与缓存池设计:ThreadSafeObject 与 CachePool 实例解析