1 接入
前提
工程是在uniapp的基础上再接入高德地图导航SDK。由于uniapp自带了定位和地图SDK(同时包括高德地图和百度地图)但是不带导航SDK,导致接入导航SDK时出现了各种问题。
为什么接入高德地图
根据unipp官方文档可知,目前只有高德地图支持nvue(百度地图暂时不支持),而工程目前是以uniapp为基础且地图用到了nvue组件,所以暂时只能接入高德地图,并需要导入nvue对应的原生SDK。
高德地图接入
自动部署
通过Pod方式自动部署。
这个方式比较方便,且后期对SDK进行迭代升级时也比较简单,只需要修改Podfile对应的版本号即可。在接入高德地图的时候,着实被坑了一把:通过高德地图官网找到目前最新的导航SDK版本为9.3.0,真机调试没有问题,但是通过Archive打包却失败了。通过各种报错信息查找资料的时候,鬼使神差地跳到了高德地图官网的更新日志,赫然发现:。去掉即可(具体操作见下面“2 遇到的问题以及处理”)。
手动部署
下载高德导航SDK再导入到工程中。
由于uniapp离线工程本身包含有定位和地图SDK,包括高德地图SDK(比如AMapFoundationKit.framework、AMapLocationKit.framework、AMapSearchKit.framework以及MAMapKit.framework),但是不包含导航SDK(AMapNaviKit.framework),所以需要额外导入。但是高德地图对各个库进行了版本控制,所以在导入SDK时需要检查SDK的版本。
目前该问题未解决。
2 遇到的问题以及处理
执行pod install报错
(1)配置了Podfile,但是没有生效
- 原因:Podfile是手写的,重新核查发现有个pod写成Pod。修改后,可以正常执行命令pod install
然后:关掉该xode工程,会自动生成xcworkspace文件,点开就进入了工作空间(原因是Pods文件夹已经自动生成了)。
(2)pod install:无效
zsh: command not found: pod
- 处理:
通过ruby安装cocoapod:
sudo gem install cocoapods -v 1.8.3
(3)pod install报错
最开始Podfile引入库时未指定版本号。
Installing AMap3DMap (7.2.0)
Installing AMapFoundation (1.7.0)
Installing AMapLocation (2.9.0)
Installing AMapSearch (7.1.0)
原因:应该是SDK版本太低。
处理:修改SDK对应的版本号(如下)。由于导航SDK包含基础库,所以基础库可以不引入。
# pod 'AMap3DMap', '9.3.1' #3D地图SDK
pod 'AMapSearch', '9.3.1' #地图SDK搜索功能
# pod 'AMapLocation', '2.9.0' #定位SDK
pod 'AMapNavi', '9.3.0' #导航 SDK
鉴权问题
2022-07-15 11:47:04.981221+0800 app-demo-ios[4828:1921600] sy.app: Error: Error Domain=AMapSearchErrorDomain Code=1008 "INVALID_USER_SCODE" UserInfo={NSLocalizedDescription=INVALID_USER_SCODE} - 错误信息:安全码验证错误,bundleID与key不对应。请在<AMapSearchKit/AMapSearchError.h>头文件中查看错误信息或者访问【http://lbs.amap.com/api/ios-sdk/guide/map-tool/errorcode/】了解详细信息。
- 处理:配置从高德地图申请的APIKey即可。
工程签名报错
officialDemoNavi has conflicting provisioning settings.
officialDemoNavi is automatically signed, but provisioning profile 3f3a460b-b68c-4868-83fb-84c49237ee75 has been manually specified. Set the provisioning profile value to "Automatic" in the build settings editor, or switch to manual signing in the Signing & Capabilities editor.
原因:这是高德地图官方导航SDK工程,下载下来时签名已有配置。
处理:在project.pbxproj文件中删除如下语句:
PROVISIONING_PROFILE = "3f3a460b-b68c-4868-83fb-84c49237ee75";
引入库冲突
'MAMapView' has different definitions in different modules; first difference is definition in module 'AMapNaviKit.MAMapView' found property
排查:应该是3D和Nav两个库有冲突
原因:pch文件中有做高德地图库的导入,然后文件中又有相关库导入,导致库冲突了。
把pch文件中的导入注释掉即可。
经纬度浮点数不匹配
- 前端传递的经纬度如下:
{
latitude = "32.23333";
longitude = "123.3333";
}
iOS显示,类型为float:
lat:32.23332977294922, lon:123.3332977294922
- 排查:将第二个longitude设置为double类型,正常了。奇怪!
lat:32.23332977294922, lon:123.3333
- 处理:前端时通过JSON格式传递过来的时,其中的数值iOS接收后转为NSNumber,需要设置为double类型。
隐私权限弹窗
2022-08-03 10:19:57.233366+0800 app-demo-ios[510:31510] [AMapNaviKit]:Error Domain=AMapFoundationErrorPrivacyShowUnknow Code=555570 "(null)" UserInfo={info=使用AMapNaviKit SDK 功能前请设置隐私权政策是否弹窗告知用户}
- 处理:前面整理工程的时候,把如下隐私弹窗的代码注释掉了,调试的时候卸载了APP,重新安装就没有执行如下步骤,导致高德地图设置车辆信息失败并导致算路和导航无效:
//更新App是否显示隐私弹窗的状态,隐私弹窗是否包含高德SDK隐私协议内容的状态. since 8.1.0
[MAMapView updatePrivacyShow:AMapPrivacyShowStatusDidShow privacyInfo:AMapPrivacyInfoStatusDidContain];
-参考:
https://blog.csdn.net/m0_55124878/article/details/121840608
//www.greatytc.com/p/e94a0e29b88e
路径规划:API
'getNaviGuideList' is deprecated: 已废弃,请使用 AMapNaviRoute 中的 guideGroups 替代 since 7.5.0
Archive打包失败
- 问题:真机调试没有问题,但是通过Archive打包却失败
ld: warning: Could not find or use auto-linked framework 'AMapNaviKit'
Undefined symbols for architecture armv7:
"_OBJC_METACLASS_$_MAPointAnnotation", referenced from:
_OBJC_METACLASS_$_NaviPointAnnotation in NaviPointAnnotation.o
"_OBJC_CLASS_$_AMapNaviDriveView", referenced from:
objc-class-ref in DriveNaviViewController.o
objc-class-ref in GPSTruckNaviViewController.o
objc-class-ref in GPSNaviViewController.o
"_OBJC_METACLASS_$_MABaseOverlay", referenced from:
_OBJC_METACLASS_$_SelectableOverlay in SelectableOverlay.o
"_OBJC_CLASS_$_MAAnnotationView", referenced from:
objc-class-ref in TruckOrderHeatMapViewController.o
"_OBJC_CLASS_$_AMapNaviVehicleInfo", referenced from:
objc-class-ref in AMapNaviVehicleInfo+Get.o
__OBJC_$_CATEGORY_AMapNaviVehicleInfo_$_Get in AMapNaviVehicleInfo+Get.o
objc-class-ref in GPSTruckNaviViewController.o
objc-class-ref in TruckRoutePlanViewController.o
"_OBJC_CLASS_$_AMapNaviPoint", referenced from:
objc-class-ref in TruckOrderHeatMapViewController.o
objc-class-ref in GPSTruckNaviInfo.o
objc-class-ref in GPSNaviViewController.o
objc-class-ref in TruckRoutePlanViewController.o
"_OBJC_CLASS_$_MABaseOverlay", referenced from:
_OBJC_CLASS_$_SelectableOverlay in SelectableOverlay.o
"_OBJC_CLASS_$_MATileOverlay", referenced from:
objc-class-ref in TruckOrderHeatMapViewController.o
"_OBJC_CLASS_$_MAPointAnnotation", referenced from:
objc-class-ref in TruckOrderHeatMapViewController.o
_OBJC_CLASS_$_NaviPointAnnotation in NaviPointAnnotation.o
"_OBJC_CLASS_$_MAHeatMapNode", referenced from:
objc-class-ref in TruckOrderHeatMapData.o
"_OBJC_CLASS_$_MATileOverlayRenderer", referenced from:
objc-class-ref in TruckOrderHeatMapViewController.o
"_OBJC_CLASS_$_MAMapView", referenced from:
objc-class-ref in TruckOrderHeatMapViewController.o
objc-class-ref in AppDelegate.o
"_OBJC_CLASS_$_MAHeatMapTileOverlay", referenced from:
objc-class-ref in TruckOrderHeatMapViewController.o
"_OBJC_CLASS_$_MAUserLocation", referenced from:
objc-class-ref in TruckOrderHeatMapViewController.o
"_OBJC_CLASS_$_AMapNaviDriveManager", referenced from:
objc-class-ref in TruckOrderHeatMapViewController.o
objc-class-ref in GPSTruckNaviViewController.o
objc-class-ref in GPSNaviViewController.o
objc-class-ref in TruckRoutePlanViewController.o
"_OBJC_CLASS_$_MAHeatMapGradient", referenced from:
objc-class-ref in TruckOrderHeatMapViewController.o
ld: symbol(s) not found for architecture armv7
clang: error: linker command failed with exit code 1 (use -v to see invocation)
:通过搜素(ld: symbol(s) not found for architecture armv7)找到如下参考(//www.greatytc.com/p/4f9ae7883643)。这个时候才意识到需要先检查一下AMapNaviKit支持的架构,并检查Xcode工程对于架构支持的配置。
处理:执行命令
lipo -info -XXX
发现确实只支持x86_64 arm64,但是.
hh@hhdeMacBook-Pro ~ % lipo -info /Users/hh/Documents/function/AMap_iOS_Navi_ALL/AMap_iOS_Navi_ALL/officialDemoNavi/Frameworks/AMapNaviKit.framework/AMapNaviKit
Architectures in the fat file: /Users/hh/Documents/function/AMap_iOS_Navi_ALL/AMap_iOS_Navi_ALL/officialDemoNavi/Frameworks/AMapNaviKit.framework/AMapNaviKit are: x86_64 arm64
hh@hhdeMacBook-Pro ~ % lipo -info /Users/hh/Documents/function/AMap_iOS_Navi_ALL/AMap_iOS_Navi_ALL/officialDemoNavi/Frameworks/AMapFoundationKit.framework/AMapFoundationKit
Architectures in the fat file: /Users/hh/Documents/function/AMap_iOS_Navi_ALL/AMap_iOS_Navi_ALL/officialDemoNavi/Frameworks/AMapFoundationKit.framework/AMapFoundationKit are: armv7 x86_64 arm64
hh@hhdeMacBook-Pro ~ % lipo -info /Users/hh/Documents/function/AMap_iOS_Navi_ALL/AMap_iOS_Navi_ALL/officialDemoNavi/Frameworks/AMapSearchKit.framework/AMapSearchKit
Architectures in the fat file: /Users/hh/Documents/function/AMap_iOS_Navi_ALL/AMap_iOS_Navi_ALL/officialDemoNavi/Frameworks/AMapSearchKit.framework/AMapSearchKit are: armv7 x86_64 arm64
- 进入高德地图官网(https://lbs.amap.com/api/ios-navi-sdk/changelog/?type=spa)并找到更新日志,赫然发现:。
- 处理:由于uniapp离线工程是默认配置的,找到Build Settings--User-Defined,修改VALID_ARCHS,去掉armv7即可。
- 参考:
//www.greatytc.com/p/c37831cef020
https://blog.csdn.net/weixin_34060741/article/details/93774980
//www.greatytc.com/p/4f9ae7883643
https://lbs.amap.com/api/ios-navi-sdk/changelog/?type=spa
支持armv7的iPhone有哪些:
armv7 设备: iPhone3GS, iPhone4, iPhone4S iPad, iPad2, iPad3(The New iPad), iPad mini iPod Touch 3G, iPod Touch4
说明:这样看,去掉armv7架构支持影响不大。
iPad选项也支持arm64的,所以暂时先保留。
真机调试成功和Archive打包失败原因
真机调试,设备支持是iOS Devices,是以具体的手机设备对应的系统版本以及架构支持为基准的,比如iPhone12(arm64架构),所以运行没有问题。
Archive打包,设备支持是Any iOS Device(arm64, armv7),所以就会打包失败。
3 手动部署:遇到的问题
手动部署
- 在上面自动部署未找到解决方案之前,尝试了进行手动部署。没想到更坑!
(1)根据uniapp官方离线文档导入高德地图SDK:编译报错
Showing Recent Messages
/Users/hh/Documents/ios-pro/iOSSDK-3.4.15/app-demo-ios/Pods/Pods.xcodeproj The iOS deployment target 'IPHONEOS_DEPLOYMENT_TARGET' is set to 7.0, but the range of supported deployment target versions is 9.0 to 15.5.99.
That command depends on command in Target '/app-demo-ios' (project '/app-demo-ios'): script phase “[CP] Copy Pods Resources”
- 原因:在项目PROJECT下找到Deployment--iOS Deployment Target
可以看到设置为6.0,这太低了,而且和TARGETS下的Deployment--iOS Deployment Target(设置为9.0)不匹配。改成一致即可(9.0)。
(2)资源重复引入问题
Multiple commands produce '/Users/hh/Library/Developer/Xcode/DerivedData/app-demo-ios-bqoygcrtkhrstcchfqexahmzlfhh/Build/Intermediates.noindex/ArchiveIntermediatesapp-demo-ios/InstallationBuildProductsLocation/Applications/app-demo-ios.app/AMap.bundle'
Target 'app-demo-ios' (project 'app-demo-ios') has copy command from '/Users/hh/Documents/ios-pro/iOSSDK-3.4.15/app-demo-ios/AMap.bundle' to '/Users/hh/Library/Developer/Xcode/DerivedData/app-demo-ios-bqoygcrtkhrstcchfqexahmzlfhh/Build/Intermediates.noindex/ArchiveIntermediates/app-demo-ios/InstallationBuildProductsLocation/Applications/app-demo-ios.app/AMap.bundle'
That command depends on command in Target 'app-demo-ios' (project 'app-demo-ios'): script phase “[CP] Copy Pods Resources”
- 原因:由于额外导入了AMapNavi库,这个库内自引入了Amap.bundle资源文件。而根据uniapp官方离线文档介绍,需要引入Amap.bundle资源文件(因为uniapp的定位和地图功能不需要导入AMapNavi库),导致资源文件重复引入了。在Build Phases里的Copy Bundle Resources里去掉AMap.bundle资源文件即可。
导航SDK引入问题
- 导入AMapNavi.framework库
(1)首先是重复引入库错误:
duplicate symbol '_utils_convert_writeShort' in:
/Users/hh/Documents/ios-pro/iOSSDK-3.4.15/SDK/Libs/MAMapKit.framework/MAMapKit(MAMapKit-arm64-master.o)
/Users/hh/Documents/ios-pro/iOSSDK-3.4.15/app-demo-ios/Frameworks/AMapNaviKit.framework/AMapNaviKit(AMapNaviKit-arm64-master.o)
duplicate symbol '_xxteakey' in:
/Users/hh/Documents/ios-pro/iOSSDK-3.4.15/SDK/Libs/MAMapKit.framework/MAMapKit(MAMapKit-arm64-master.o)
/Users/hh/Documents/ios-pro/iOSSDK-3.4.15/app-demo-ios/Frameworks/AMapNaviKit.framework/AMapNaviKit(AMapNaviKit-arm64-master.o)
ld: 848 duplicate symbols for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
处理:去掉原有的MAMapKit库。
如果之前有引入导航SDK和地图SDK,需要删除MAMapKit和资源文件(比如AMap.bundle)。
再重新从AMapNavi SDK中添加两个资源文件。参考:官方文档:
https://lbs.amap.com/api/ios-navi-sdk/guide/create-project/manual-configuration
(2)编译成功,运行崩溃:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[AMapServices checkPrivacyStatus:component:]: unrecognized selector sent to instance 0x281508e10'
terminating with uncaught exception of type NSException
- 处理:AppDelegate添加相应的高德地图代码后,编译报错:
/Users/hh/Documents/ios-pro/iOSSDK-3.4.15/app-demo-ios/Frameworks/AMapNavikit.framework/Headers/MAMapVersion.h:20:2: "The AMapFoundationKit version is less than minimum required, please update! Any questions please to visit http://lbs.amap.com"
处理:难!
手动部署:总结
考虑到uniapp自引入的高德地图SDK和额外引入的AMapNavi.framework库版本可能不统一,这边做了统一版本的尝试,包括统一使用官网下载的SDK版本,以及统一使用之前Pods文件夹下的版本。但仍然报错(The AMapFoundationKit version is less than minimum required, please update!)。后续这边又切回到Pod方式并找到了解决方案,所以这边就没再尝试了。
目前该问题未解决。
4 其他
腾讯地图
- TencentMapDemo_Android-master
github
参考:
https://github.com/TencentLBS/TencentMapDemo_Android
https://github.com/orgs/TencentLBS/repositories?type=all
https://github.com/TencentLBS/TencentMapDemo_iOS