如何在Flutter插件中添加桥接头

Dim*_*ira 5 xcode ios cocoapods podspec flutter

我正在尝试创建Flutter插件,该插件使用Swift并具有一个pod依赖项(NearbyMessages

首先,我已将其添加到 .podspec

#
# To learn more about a Podspec see http://guides.cocoapods.org/syntax/podspec.html
#
Pod::Spec.new do |s|
  s.name             = 'flutter_nearby_messages'
  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'
  s.dependency 'Flutter'
  //************ I've added this lines ***************
  s.dependency 'NearbyMessages' 
  s.xcconfig = { 'SWIFT_OBJC_BRIDGING_HEADER' => 'Classes/bridging_header.h' }
  //********* ^^ I've added this lines ^^ ************
  s.static_framework = true
  s.ios.deployment_target = '8.0'
end
Run Code Online (Sandbox Code Playgroud)

在安装Pod和构建初始空项目之后,一切似乎都很好

我试过在Objective-C中使用它:

#import "FlutterNearbyMessagesPlugin.h"
#import <NearbyMessages/GNSMessages.h>
#import <flutter_nearby_messages/flutter_nearby_messages-Swift.h>

@implementation FlutterNearbyMessagesPlugin
+ (void)registerWithRegistrar:(NSObject<FlutterPluginRegistrar>*)registrar {    
    GNSMessageManager *messageManager =
    [[GNSMessageManager alloc] initWithAPIKey:@"API_KEY"];
  [SwiftFlutterNearbyMessagesPlugin registerWithRegistrar:registrar];
}
@end
Run Code Online (Sandbox Code Playgroud)

它有效,但是当我尝试时:

public class SwiftFlutterNearbyMessagesPlugin: NSObject, FlutterPlugin {
    private var client: GNSMessageManager? = nil
Run Code Online (Sandbox Code Playgroud)

XCode说 Use of undeclared type GNSMessageManager

我知道,我需要桥接标头,并且我已经尝试创建它,但是似乎根本没有链接。

桥接头仅包含一行: #import <NearbyMessages/GNSMessages.h>

所以我的问题是,如何在flutter插件中添加桥接头?

Hem*_*Odd 7

将桥接头文件添加到 Flutter 插件中对我有用的唯一解决方案是将头文件放入Classes文件夹中,然后将其添加到.podspec

s.public_header_files = 'Classes/**/*.h'
Run Code Online (Sandbox Code Playgroud)