1)新建桥接头文件(放在工程路径下),这里命名为bnaviswiftdemo-bridging-header.h,在该头文件中import需要的库文件,代码如下:
#import//引入base相关所有的头文件 #import//引入地图功能所有的头文件 #import//只引入所需的单个头文件 #import "bnaviservice.h"#import "bnrouteplanmodel.h"#import "bmtruckinfomodel.h"#import "bndriverouteprotocol.h"#import "bncarroutedata.h"#import "bnavimodel.h"#import "bnlocationmanagerprotocol.h"
2)左侧目录中选中工程名,在targets->build settings-> swift compiler - code generation -> objective-c briding header中输入桥接文件的路径, 如下图所示:
在appdelegate.swift的didfinishlaunchingwithoptions方法的最前面配置百度导航key。示例代码如下:
func application(_ application:uiapplication, didfinishlaunchingwithoptions launchoptions:[uiapplication.launchoptionskey:any]?)->bool{// override point for customization after application launch.initmapsdk()initnavisdk()returntrue}func initmapsdk(){bmkmapmanager.setagreeprivacy(true);let mapmanager =bmkmapmanager()// 启动引擎并设置ak并设置delegateif!(mapmanager.start("在此处输入您的授权ak",generaldelegate: self)){}}func initnavisdk(){bnaviservice.setagreeprivacy(true)bnaviservice.getinstance().initnaviservice(dictionary()){bnaviservice.getinstance().authorizenaviappkey("你的key"){ succ in}bnaviservice.getinstance().authorizettsappid("appid",apikey:"apikey",secretkey:"secretkey"){ issuc in}} fail:{}}
算路请参考文档:驾车路线规划
导航请参考文档: 实时导航与模拟导航
上一篇
下一篇
本篇文章对您是否有帮助?