【iOS 】swift项目使用pod引入百度地图oc库时找不到头文件

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/Summer_via/article/details/81354614

由于最近开发一个项目,需要用到百度地图API,于是使用pod添加了百度地图的库,podfile如下:

# Uncomment the next line to define a global platform for your project
# platform :ios, '11.4'

target 'BaiduLocTest' do
  # Comment the next line if you're not using Swift and don't want to use dynamic frameworks
use_frameworks!

  # Pods for BaiduLocTest
 pod 'BMKLocationKit','1.2.1'
 pod 'BaiduMapKit','4.1.1'
 pod 'SnapKit','~>4.0.0'
  target 'BaiduLocTestTests' do
    inherit! :search_paths
    # Pods for testing
  end

  target 'BaiduLocTestUITests' do
    inherit! :search_paths
    # Pods for testing
  end

end

按照其他人的博客:新建桥接文件-配置桥接文件路径-import头文件,报错:找不到头文件,如下图:
这里写图片描述
找了下网上的解决方案,都说是添加User Header Search Path,于是添加了路径
这里写图片描述
结果还是不行,还是找不到头文件错误。有人说要用单引号,不要前缀,结果还是不行。
文件目录的确是有对应的头文件的。
这时候一篇博客提到是因为podfile里使用了use_framework!命令造成的。于是试着去掉use_framework!,果然可以没报错了。use_framework!会将开源库编译成.framework文件,不使用会编译成静态库.a文件。这样虽然不报错,但是调用swift库的时候,use_framwork!是必须的,不然import找不到moudule。
于是找到百度地图的demo看了一下,发现import头文件的前缀不是BaiduMapKit,而是BaiduMapAPI_XXX,打开pods/BaiduMapKit才发现里面出了头文件还有一个framework文件夹,而里面放的就是变异出来的.framework文件,文件名正好对应前缀。于是找到要用头文件所属framework,用framework名作前缀就没问题了。

猜你喜欢

转载自blog.csdn.net/Summer_via/article/details/81354614