步驟基本分為兩個部分:1.百度的步驟的注意點 2.為了應用能跑實際上要額外添加的步驟。
-
按照百度的手動流程走一遍。其中為了方便,將所有要的全部添加了。(圖片是按照官方的流程手動導入百度地圖sdk的注意點)Linked Frameworks and Libraries添加了的內容
Linked Frameworks and Libraries添加了的內容
方法:選中工程名,在右鍵菜單中選擇Add Files to “工程名”…,從BaiduMapAPI_Map.framework||Resources文件中選擇mapapi.bundle文件,并勾選“Copy items if needed”復選框,單擊“Add”按鈕,將資源文件添加到工程中。
Other Linker Flags的定制 -
在百度開發(fā)平臺上面申請到key。填入自己項目的Bundle Identifier,還有自己的項目名。獲得安全碼。
Bundle key的查看。在項目的General那項那里就能看得到 - 新建一個.m文件之后,同意Xcode添加一個"工程名-Bridging-Header.h"的文件。將這個新建好的.m文件改為.mm文件。(其實這一步應該可以算作是百度官方手動導入流程的一部分,那時候官方流程有提到)
- 在"工程名-Bridging-Header.h"文件中添加要用到的百度地圖的頭文件
// 為了方便直接全部都放進去了。
#import <BaiduMapAPI_Base/BMKBaseComponent.h>
#import <BaiduMapAPI_Map/BMKMapComponent.h>
#import <BaiduMapAPI_Location/BMKLocationComponent.h>
#import <BaiduMapAPI_Cloud/BMKCloudSearchComponent.h>
#import <BaiduMapAPI_Radar/BMKRadarComponent.h>
#import <BaiduMapAPI_Search/BMKSearchComponent.h>
#import <BaiduMapAPI_Utils/BMKUtilsComponent.h>
- 在appdelegate中直接初始化自己的MapManager,修改的代碼如下:
var _mapManager:BMKMapManager?
var navigationController:UINavigationController?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
_mapManager = BMKMapManager()
let ret:Bool = (_mapManager?.start("你自己軟件獲取到的安全碼", generalDelegate: nil))!
if (!ret){
print("manager start failed!")
}
// Override point for customization after application launch.
return true
}
在info.plist中添加App Transport Security Settings,再在其中添加Allow的那兩個項,他們兩個的值修改為YES來使得可以連接網絡。
同時呢,還要在info.plist中添加Bundle display name,這個項填入你自己的項目名字。在ViewController這邊寫代碼了可以(這里的代碼僅僅是生成一個全屏幕的百度地圖視圖)
import UIKit
class ViewController: UIViewController {
var mapView:BMKMapView?
override func viewDidLoad() {
super.viewDidLoad()
mapView = BMKMapView(frame: CGRect(x: 0, y: 0, width: self.view.frame.width, height: self.view.frame.height))
self.view.addSubview(mapView!)
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}

最終運行效果
- PodFile方式
直接按照百度的流程改好即可。



