ios 百度鷹眼整合
百度鷹眼整合遇到的坑
下面說一下整合步驟很全
1,使用cocoapods匯入百度地圖的基礎的SDK: pod ‘BaiduMapKit’
2,登入百度地圖開放平臺,找到iOS的鷹眼軌跡的SDK,下載,然後把BaiduTraceSDK.framework匯入工程(選擇工程->General ,把SDK拖到Embedded Baniaries)
3,設定標頭檔案路徑(選擇剛剛匯入的SDK,Show in Finder,選擇工程->Build Settings ,搜尋框輸入search,找到Header Serach Paths ,雙擊這行的右邊,彈出一個大的輸入框,把剛才Show in Finder的資料夾裡面的Headers資料夾直接拖到大輸入框裡)
4,匯入類庫CoreLocation.framework,QuartzCore.framework,OpenGLES.framework,
SystemConfiguration.framework,CoreGraphics.framework,
Security.framework,libsqlite3.0.tbd,CoreTelephony.framework,libstdc++.6.0.9.tbd
5…. 所謂開啟後臺位置定位
6,解決 230 image not found 的問題(有時候工程無緣無故地在還沒有進入的時候就崩了,很可能也是這裡的問題,有一次我明明之前已經設定好了,沒動過它,它也會自動地變成了NO,坑了好久)注意:Xcode 8 把這項改了名字: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:你在百度開放平臺建立的AK generalDelegate:self];
if (!ret) {
NSLog(@"manager start failed!");
}
return YES;
}
- (void)onGetNetworkState:(int)iError
{
if (0 == iError) {
NSLog(@"聯網成功");
}
else{
NSLog(@"onGetNetworkState %d",iError);
}
}
- (void)onGetPermissionState:(int)iError
{
if (0 == iError) {
NSLog(@"授權成功");
}
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 {
//把裝置的uuid作為entityName
entityName = [[[UIDevice currentDevice] identifierForVendor] UUIDString];
traceInstance = [[BTRACE alloc] initWithAk:AK mcode:MCODE serviceId:serviceID entityName: entityName operationMode: 2];
_mapView.delegate = self; // 此處記得不用的時候需要置nil,否則影響記憶體的釋放
_mapView.mapType = BMKMapTypeStandard;
//檢視載入之後就請求實時位置
[self queryEntityList];
}
//請求實時位置
- (void)queryEntityList {
[[BTRACEAction shared] queryEntityList:self serviceId:serviceID entityNames:entityName columnKey:nil activeTime:0 returnType:0 pageSize:0 pageIndex:0];
}
#pragma mark - Entity相關的回撥方法
- (void)onQueryEntityList:(NSData *)data {
NSString *entityListResult = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
NSLog(@"實時位置查詢結果: %@", 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];
}
}
//新增當前位置的標註
-(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];
// 設定顏色
annotationView.pinColor = BMKPinAnnotationColorPurple;
// 從天上掉下效果
annotationView.animatesDrop = YES;
// 設定可拖拽
annotationView.draggable = YES;
}
return annotationView;
}
return nil;
}
注意:1.bundle id ,工程裡的mode,和百度開發者中心的安全碼要保持一致,否則會出現只有白色網格的情況。
- “230 image not found” Build Options->Enabled Content Contains Swift Code(Xcode 8 的是Always Embed Swift Standard Libraries)->YES
- “指定track不存在” 去到百度開發者官網的service_id那裡,點選相應的ID的專案,建立一個entityName,或者選擇某個entityName(如果有的話)去替換你工程裡的 entityName
如果跑步起來看這裡看這裡
相關文章
- 鷹眼智客營銷系統
- openlayers3 自定義鷹眼縮圖S3
- 精密的“鷹眼” 華碩ZenFone Zoom拆解圖賞OOM
- 獨具慧眼 華碩鷹眼ZenFone Zoom圖賞OOM
- 華碩鷹眼ZenFone Zoom:纖薄的3倍光變OOM
- 華碩沈振來:顛覆行業 鷹眼敢為天下先行業
- 百度iOS面試iOS面試
- iOS 持續整合iOS
- 百度地圖-簡單整合地圖
- 百度地圖整合_定位功能地圖
- Zoho CRM整合整合微信、呼叫中心、百度地圖等地圖
- PayPal-iOS-整合攻略iOS
- 百度 iOS 面試總結iOS面試
- iOS 9.3:增加護眼模式 備忘錄可加密iOS模式加密
- iOS環信整合(附demo)iOS
- iOS整合個推小結iOS
- iOS整合Fabric & Crashlytics (2)iOS
- 百度雲學習資源整合
- cacti+nagios 之cacti整合nagios(四)iOS
- 百度流行音樂-資源資料整合
- iOS持續整合(一)——fastlane 使用iOSAST
- iOS CallKit與PushKit的整合(一)iOS
- iOS自動整合打包釋出iOS
- iOS 持續整合系列 – 開篇iOS
- iOS開發 iOS整合FFmpeg及視訊格式轉碼iOS
- iOS整合 Flutter 混合工程開發一iOSFlutter
- 混合開發:flutter整合進iOS工程FlutteriOS
- iOS使用fastlane實現持續整合iOSAST
- 玩轉iOS開發:Touch ID整合iOS
- 為現有iOS專案整合FlutteriOSFlutter
- Unity3D整合到iOS工程Unity3DiOS
- iOS--支付寶環境整合iOS
- iOS 極光推送整合與開發iOS
- iOS 8 中如何整合 Touch ID 功能iOS
- [Jenkins]IOS持續整合外掛JenkinsiOS
- 日本iOS 9月暢銷榜觀察,“中國製造”表現搶眼iOS
- iOS整合FFmpeg及視訊格式轉碼iOS
- iOS使用Stripe整合支付寶Alipay支付iOS