当前位置: 首页 > 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.lryc.cn/news/577160.html

相关文章:

  • 跨时间潜运动迁移以实现操作中的多帧预测
  • 云效DevOps vs Gitee vs 自建GitLab的技术选型
  • 临床试验审计问题分类与整改策略
  • 高效数据采集:Python与Rust完美结合
  • 将本地仓库推送到GitHub
  • 【Pandas】pandas DataFrame attrs
  • 2025年光学工程、精密仪器与光电子技术国际会议(OEPIOT 2025)
  • 【MCP服务】蓝耘元生代 | 蓝耘MCP平台来袭!DeepSeek MCP服务器玩转大模型集成
  • Python-Word文档、PPT、PDF以及Pillow处理图像详解
  • 车载ECU刷写文件格式汇总详解
  • 博图SCL编程:结构体(STRUCT)使用详解与实战案例
  • .net实现内容推荐算法代码
  • C++ --- list
  • ES6笔记1
  • ES6从入门到精通:箭头函数
  • 【PHP】.Hyperf 框架-collection 集合数据(内置函数归纳-实用版)
  • uniapp小程序蓝牙打印通用版(集成二维码打印)
  • Day113 切换Node.js版本、多数据源配置
  • 服务器被入侵的常见迹象有哪些?
  • AdGuard Home 安装及使用
  • SimLOD代码精读(二)建立Octree之Splitting Pass分裂阶段
  • 永磁同步电机无速度算法--基于带相位补偿的鉴相重构锁相环的滑模观测器
  • 华为云Flexus+DeepSeek征文 | 基于华为云Dify-LLM搭建知识库问答助手
  • 深入解析TCP:可靠传输的核心机制与实现逻辑
  • LaTeX 常用宏包(数学论文场景)
  • MySQL索引失效场景
  • NLP自然语言处理 01 文本预处理
  • 现代 JavaScript (ES6+) 入门到实战(三):字符串与对象的魔法升级—模板字符串/结构赋值/展开运算符
  • 【c/c++1】数据类型/指针/结构体,static/extern/makefile/文件
  • 【c/c++3】类和对象,vector容器,类继承和多态,systemd,stdboost