百度鷹眼集成遇到的坑
下面說(shuō)一下集成步驟很全
1,使用cocoapods導(dǎo)入百度地圖的基礎(chǔ)的SDK: pod ‘BaiduMapKit’
2,登錄百度地圖開放平臺(tái)枫虏,找到iOS的鷹眼軌跡的SDK锅尘,下載结缚,然后把BaiduTraceSDK.framework導(dǎo)入工程(選擇工程->General 耕餐,把SDK拖到Embedded Baniaries)
3,設(shè)置頭文件路徑(選擇剛剛導(dǎo)入的SDK斤程,Show in Finder,選擇工程->Build Settings ,搜索框輸入search寸癌,找到Header Serach Paths ,雙擊這行的右邊榆浓,彈出一個(gè)大的輸入框于未,把剛才Show in Finder的文件夾里面的Headers文件夾直接拖到大輸入框里)
4,導(dǎo)入類庫(kù)CoreLocation.framework,QuartzCore.framework,OpenGLES.framework,
SystemConfiguration.framework,CoreGraphics.framework,
Security.framework,libsqlite3.0.tbd,CoreTelephony.framework,libstdc++.6.0.9.tbd
5…. 所謂開啟后臺(tái)位置定位
6,解決 230 image not found 的問題(有時(shí)候工程無(wú)緣無(wú)故地在還沒有進(jìn)入的時(shí)候就崩了,很可能也是這里的問題陡鹃,有一次我明明之前已經(jīng)設(shè)置好了烘浦,沒動(dòng)過它,它也會(huì)自動(dòng)地變成了NO萍鲸,坑了好久)注意:Xcode 8 把這項(xiàng)改了名字:Always Embed Swift Standard Libraries
7,添加Bundle display name闷叉,并且在使用到百度SDK的文件中,把文件.m后綴改為.mm
8,允許https(在plist添加NSAppTransportSecurity脊阴,類型Dictionary 握侧,在此目錄下添加NSAllowsArbitraryLoads,類型boolean嘿期,值為YES品擎;)
9,在buidsettings輸入bite,選擇Enable bite code备徐,值為NO萄传;
10,在plist添加NSLocationAlwaysUsageDescription
11,在工程的AppDelegate.h
12,在工程的AppDelegate.m
-(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
_mapManager = [[BMKMapManager alloc]init];
BOOL ret = [_mapManager start:你在百度開放平臺(tái)創(chuàng)建的AK generalDelegate:self];
if (!ret) {
NSLog(@"manager start failed!");
}
return YES;
}
- (void)onGetNetworkState:(int)iError
{
if (0 == iError) {
NSLog(@"聯(lián)網(wǎng)成功");
}
else{
NSLog(@"onGetNetworkState %d",iError);
}
}
- (void)onGetPermissionState:(int)iError
{
if (0 == iError) {
NSLog(@"授權(quán)成功");
}
else {
NSLog(@"onGetPermissionState %d",iError);
}
}
13,在需要用到的控制器里
static NSString * entityName;
static BTRACE * traceInstance = NULL;
double latitudeOfEntity;
double longitudeOfEntity;
- (void)viewDidLoad {
[super viewDidLoad];
_mapView=[[BMKMapView alloc] initWithFrame:self.view.frame];
_mapView.backgroundColor=[UIColor redColor];
[_mapView setZoomLevel:19];
pointAnnotation = nil;
[self.view addSubview:_mapView];
[self doWork];
}
-(void) doWork {
//把設(shè)備的uuid作為entityName
entityName = [[[UIDevice currentDevice] identifierForVendor] UUIDString];
traceInstance = [[BTRACE alloc] initWithAk:AK mcode:MCODE serviceId:serviceID entityName: entityName operationMode: 2];
_mapView.delegate = self; // 此處記得不用的時(shí)候需要置nil,否則影響內(nèi)存的釋放
_mapView.mapType = BMKMapTypeStandard;
//視圖加載之后就請(qǐng)求實(shí)時(shí)位置
[self queryEntityList];
}
//請(qǐng)求實(shí)時(shí)位置
- (void)queryEntityList {
[[BTRACEAction shared] queryEntityList:self serviceId:serviceID entityNames:entityName columnKey:nil activeTime:0 returnType:0 pageSize:0 pageIndex:0];
}
#pragma mark - Entity相關(guān)的回調(diào)方法
- (void)onQueryEntityList:(NSData *)data {
NSString *entityListResult = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
NSLog(@"實(shí)時(shí)位置查詢結(jié)果: %@", entityListResult);
NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:[entityListResult dataUsingEncoding:NSUTF8StringEncoding] options:NSJSONReadingMutableLeaves error:nil];
NSNumber *status = [dic objectForKey:@"status"];
if (0 == [status longValue]) {
NSArray *entities = [dic objectForKey:@"entities"];
NSDictionary *entity = [entities objectAtIndex:0];
NSDictionary *realtimePoint = [entity objectForKey:@"realtime_point"];
NSArray *location = [realtimePoint objectForKey:@"location"];
longitudeOfEntity = [[location objectAtIndex:0] doubleValue];
latitudeOfEntity = [[location objectAtIndex:1] doubleValue];
dispatch_async(dispatch_get_main_queue(), ^{
[_mapView removeOverlays:_mapView.overlays];
[_mapView removeAnnotations:_mapView.annotations];
});
[self addPointAnnotation];
}
}
//添加當(dāng)前位置的標(biāo)注
-(void)addPointAnnotation {
CLLocationCoordinate2D coord;
coord.latitude = latitudeOfEntity;
coord.longitude = longitudeOfEntity;
if (nil == pointAnnotation) {
pointAnnotation = [[BMKPointAnnotation alloc] init];
}
pointAnnotation.coordinate = coord;
CLLocationCoordinate2D pt=(CLLocationCoordinate2D){0,0};
pt=(CLLocationCoordinate2D){latitudeOfEntity,longitudeOfEntity};
pointAnnotation.title = @"最新位置";
dispatch_async(dispatch_get_main_queue(), ^{
[_mapView setCenterCoordinate:coord animated:true];
[_mapView addAnnotation:pointAnnotation];
});
}
- (BMKAnnotationView *)mapView:(BMKMapView *)mapView viewForAnnotation:(id <BMKAnnotation>)annotation
{
if (annotation == pointAnnotation) {
NSString *AnnotationViewID = @"renameMark";
BMKPinAnnotationView *annotationView = (BMKPinAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:AnnotationViewID];
if (annotationView == nil) {
annotationView = [[BMKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:AnnotationViewID];
// 設(shè)置顏色
annotationView.pinColor = BMKPinAnnotationColorPurple;
// 從天上掉下效果
annotationView.animatesDrop = YES;
// 設(shè)置可拖拽
annotationView.draggable = YES;
}
return annotationView;
}
return nil;
}
注意:1.bundle id ,工程里的mode,和百度開發(fā)者中心的安全碼要保持一致坦喘,否則會(huì)出現(xiàn)只有白色網(wǎng)格的情況盲再。
- “230 image not found” Build Options->Enabled Content Contains Swift Code(Xcode 8 的是Always Embed Swift Standard Libraries)->YES
- “指定track不存在” 去到百度開發(fā)者官網(wǎng)的service_id那里,點(diǎn)擊相應(yīng)的ID的項(xiàng)目瓣铣,創(chuàng)建一個(gè)entityName,或者選擇某個(gè)entityName(如果有的話)去替換你工程里的 entityName
如果跑步起來(lái)看這里看這里