flutter 创建插件

资料:

flutter与原生通信的方式简介 - 简书

完整流程 Flutter 集成 Golang 多语言跨端开发基础案例 - 知乎

https://www.cnblogs.com/webabcd/p/flutter_lib_plugin_plugin_ios.html

步骤1、创建插件

我创建的插件名字是konnect_im_sdk 选择的语言是 java和swift创建。

直接把插件放在项目中 plugins/konnect_im_sdk 如下

然后再项目的pubspec.yaml 引入本地项目插件

konnect_im_sdk:

path: plugins/konnect_im_sdk

然后再插件的ios项目目录下 创建 Products 将 完整流程 Flutter 集成 Golang 多语言跨端开发基础案例 - 知乎

生成的object-c的ios第三方sdk放进去

然后在 .podspec 文件配置 第三方sdk的路径

s.vendored_frameworks = 'Products/*.framework'

s.static_framework = true

Classes 下的文件中 导入 第三方库 如这样的

现在就可以调用object-c中的方法了

object-c 中声明文件

objectivec 复制代码
FOUNDATION_EXPORT BOOL Konnect_im_sdkInitSDK(id<Konnect_im_sdk_callbackOnConnListener> _Nullable listener, NSString* _Nullable operationID, NSString* _Nullable config);
objectivec 复制代码
@protocol Konnect_im_sdk_callbackOnConnListener;
@class Konnect_im_sdk_callbackOnConnListener;

@protocol Konnect_im_sdk_callbackOnBatchMsgListener <NSObject>
- (void)onRecvNewMessages:(NSString* _Nullable)messageList;
@end

@protocol Konnect_im_sdk_callbackOnConnListener <NSObject>
- (void)onConnectFailed:(int32_t)errCode errMsg:(NSString* _Nullable)errMsg;
- (void)onConnectSuccess;
- (void)onConnecting;
- (void)onKickedOffline;
- (void)onUserTokenExpired;
@end

@interface Konnect_im_sdk_callbackOnConnListener : NSObject <goSeqRefInterface, Konnect_im_sdk_callbackOnConnListener> {
}
@property(strong, readonly) _Nonnull id _ref;

- (nonnull instancetype)initWithRef:(_Nonnull id)ref;
- (void)onConnectFailed:(int32_t)errCode errMsg:(NSString* _Nullable)errMsg;
- (void)onConnectSuccess;
- (void)onConnecting;
- (void)onKickedOffline;
- (void)onUserTokenExpired;
@end

调用

Konnect_im_sdkInitSDK 第一个参数是这样写的

Swift 复制代码
 class MyConnectionListener:  Konnect_im_sdk_callbackOnConnListener {
    override func onConnectFailed(_ errCode: Int32, errMsg: String?) {
        print("连接失败,错误码:\(errCode),错误信息:\(errMsg ?? "")")
    }
    
    override func onConnectSuccess() {
        print("连接成功")
    }
    
    override func onConnecting() {
        print("正在连接...")
    }
    
    override func onKickedOffline() {
        print("您已被踢下线")
    }
    
    override func onUserTokenExpired() {
        print("用户令牌已过期")
    }
}

运行可以运行 但是报错了 报错同 go_seq_go_to_refnum on objective-c objects is not permitted

https://github.com/golang/go/issues/20254

记 IOS Swift 实现 gomobile interface 抛出异常 go_seq_go_to_refnum on objective-c objects is not permitted

swift 中是不存在多继承的 下面的写法 又报多继承

Swift 复制代码
 class MyConnectionListener: NSObject, Konnect_im_sdk_callbackOnConnListener {
     func onConnectFailed(_ errCode: Int32, errMsg: String?) {
        print("连接失败,错误码:\(errCode),错误信息:\(errMsg ?? "")")
    }
    
     func onConnectSuccess() {
        print("连接成功")
    }
    
     func onConnecting() {
        print("正在连接...")
    }
    
     func onKickedOffline() {
        print("您已被踢下线")
    }
    
     func onUserTokenExpired() {
        print("用户令牌已过期")
    }
}

那么 Konnect_im_sdk_callbackOnConnListener是一个类 不是协议 说明声明文件中Konnect_im_sdk_callbackOnConnListener定义有问题

找到第三方sdk定义的地方 注释掉

Konnect_im_sdk_callbackOnConnListener 不是既是协议 又同时定义为类

注释掉问题解决

总结

go_seq_go_to_refnum on objective-c objects is not permitted

是 传参类型不对导致的

安卓项目

修改 build.gradle 配置文件

dependencies {

// libs 是 第三方包的路径

implementation fileTree(dir: 'libs', include: ['*.jar'])

// imsdk

implementation(name: 'konnect_im_sdk', ext: 'aar')

}
文件中导入第三方包

package chat.konnect.konnect_im_sdk;

相关推荐
SoaringHeart1 分钟前
Flutter组件封装:视频播放组件全局封装
前端·flutter
程序员老刘4 小时前
Kotlin vs Dart:当“优雅”变成心智负担,我选择了更简单的 Dart
flutter·kotlin·dart
徐安安ye4 小时前
Flutter 车载系统开发:打造符合 Automotive Grade Linux 标准的 HMI 应用
linux·flutter·车载系统
恋猫de小郭6 小时前
2025 年终醒悟,AI 让我误以为自己很强,未来程序员的转型之路
android·前端·flutter
_大学牲6 小时前
Flutter 勇闯2D像素游戏之路(五):像元气骑士一样的设计随机地牢
flutter·游戏·游戏开发
音浪豆豆_Rachel9 小时前
Flutter鸿蒙化之深入解析Pigeon非空字段设计:non_null_fields.dart全解
flutter·harmonyos
Zender Han10 小时前
Flutter 图片裁剪插件 image_cropper 最新版介绍与使用教程
android·flutter·ios
子榆.10 小时前
Flutter 与开源鸿蒙(OpenHarmony)实时音视频通话实战:基于 AVSession 与 Native 音视频栈构建安全通信应用
flutter·开源·harmonyos
xianjixiance_10 小时前
Flutter跨平台向量数学库vector_math鸿蒙化使用指南
flutter·华为·harmonyos
消失的旧时光-194311 小时前
从命令式跳转到声明式路由:前端、Android、Flutter 的一次统一演进
android·前端·flutter·状态模式