├── .gitignore ├── src ├── android │ ├── libs │ │ ├── BaiduTraceSDK_v2_1_15.jar │ │ ├── x86 │ │ │ └── libBaiduTraceSDK_v2_1_15.so │ │ ├── armeabi │ │ │ └── libBaiduTraceSDK_v2_1_15.so │ │ ├── x86_64 │ │ │ └── libBaiduTraceSDK_v2_1_15.so │ │ ├── arm64-v8a │ │ │ └── libBaiduTraceSDK_v2_1_15.so │ │ └── armeabi-v7a │ │ │ └── libBaiduTraceSDK_v2_1_15.so │ ├── JsonUtil.java │ └── BaiduTrace.java └── ios │ ├── libs │ └── BaiduTraceSDK.framework │ │ ├── Info.plist │ │ ├── BaiduTraceSDK │ │ ├── baidu.com.cer │ │ ├── Modules │ │ ├── BaiduTraceSDK.swiftmodule │ │ │ ├── arm.swiftdoc │ │ │ ├── arm.swiftmodule │ │ │ ├── arm64.swiftdoc │ │ │ └── arm64.swiftmodule │ │ └── module.modulemap │ │ ├── Headers │ │ ├── SqliteBriding.h │ │ ├── BaiduTraceSDK.h │ │ ├── CppInterface.h │ │ └── BaiduTraceSDK-Swift.h │ │ └── _CodeSignature │ │ └── CodeResources │ ├── BaiduTrace.h │ └── BaiduTrace.m ├── hooks ├── npmInstall.js └── addEmbedded.js ├── package.json ├── www └── Trace.js ├── plugin.xml └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | node_modules 3 | *.log 4 | -------------------------------------------------------------------------------- /src/android/libs/BaiduTraceSDK_v2_1_15.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/njleonzhang/cordova-baidu-yingyan/HEAD/src/android/libs/BaiduTraceSDK_v2_1_15.jar -------------------------------------------------------------------------------- /src/ios/libs/BaiduTraceSDK.framework/Info.plist: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/njleonzhang/cordova-baidu-yingyan/HEAD/src/ios/libs/BaiduTraceSDK.framework/Info.plist -------------------------------------------------------------------------------- /src/android/libs/x86/libBaiduTraceSDK_v2_1_15.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/njleonzhang/cordova-baidu-yingyan/HEAD/src/android/libs/x86/libBaiduTraceSDK_v2_1_15.so -------------------------------------------------------------------------------- /src/android/libs/armeabi/libBaiduTraceSDK_v2_1_15.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/njleonzhang/cordova-baidu-yingyan/HEAD/src/android/libs/armeabi/libBaiduTraceSDK_v2_1_15.so -------------------------------------------------------------------------------- /src/android/libs/x86_64/libBaiduTraceSDK_v2_1_15.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/njleonzhang/cordova-baidu-yingyan/HEAD/src/android/libs/x86_64/libBaiduTraceSDK_v2_1_15.so -------------------------------------------------------------------------------- /src/ios/libs/BaiduTraceSDK.framework/BaiduTraceSDK: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/njleonzhang/cordova-baidu-yingyan/HEAD/src/ios/libs/BaiduTraceSDK.framework/BaiduTraceSDK -------------------------------------------------------------------------------- /src/ios/libs/BaiduTraceSDK.framework/baidu.com.cer: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/njleonzhang/cordova-baidu-yingyan/HEAD/src/ios/libs/BaiduTraceSDK.framework/baidu.com.cer -------------------------------------------------------------------------------- /src/android/libs/arm64-v8a/libBaiduTraceSDK_v2_1_15.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/njleonzhang/cordova-baidu-yingyan/HEAD/src/android/libs/arm64-v8a/libBaiduTraceSDK_v2_1_15.so -------------------------------------------------------------------------------- /src/android/libs/armeabi-v7a/libBaiduTraceSDK_v2_1_15.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/njleonzhang/cordova-baidu-yingyan/HEAD/src/android/libs/armeabi-v7a/libBaiduTraceSDK_v2_1_15.so -------------------------------------------------------------------------------- /hooks/npmInstall.js: -------------------------------------------------------------------------------- 1 | module.exports = function (context) { 2 | var shell = context.requireCordovaModule('shelljs'); 3 | shell.cd(context.opts.plugin.dir); 4 | shell.exec('npm install'); 5 | }; 6 | -------------------------------------------------------------------------------- /src/ios/libs/BaiduTraceSDK.framework/Modules/BaiduTraceSDK.swiftmodule/arm.swiftdoc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/njleonzhang/cordova-baidu-yingyan/HEAD/src/ios/libs/BaiduTraceSDK.framework/Modules/BaiduTraceSDK.swiftmodule/arm.swiftdoc -------------------------------------------------------------------------------- /src/ios/libs/BaiduTraceSDK.framework/Modules/BaiduTraceSDK.swiftmodule/arm.swiftmodule: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/njleonzhang/cordova-baidu-yingyan/HEAD/src/ios/libs/BaiduTraceSDK.framework/Modules/BaiduTraceSDK.swiftmodule/arm.swiftmodule -------------------------------------------------------------------------------- /src/ios/libs/BaiduTraceSDK.framework/Modules/BaiduTraceSDK.swiftmodule/arm64.swiftdoc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/njleonzhang/cordova-baidu-yingyan/HEAD/src/ios/libs/BaiduTraceSDK.framework/Modules/BaiduTraceSDK.swiftmodule/arm64.swiftdoc -------------------------------------------------------------------------------- /src/ios/libs/BaiduTraceSDK.framework/Modules/BaiduTraceSDK.swiftmodule/arm64.swiftmodule: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/njleonzhang/cordova-baidu-yingyan/HEAD/src/ios/libs/BaiduTraceSDK.framework/Modules/BaiduTraceSDK.swiftmodule/arm64.swiftmodule -------------------------------------------------------------------------------- /src/ios/libs/BaiduTraceSDK.framework/Headers/SqliteBriding.h: -------------------------------------------------------------------------------- 1 | // 2 | // SqliteBriding.h 3 | // BaiduTraceSDK 4 | // 5 | // Created by Daniel Bey on 8/15/16. 6 | // Copyright © 2016 Daniel Bey. All rights reserved. 7 | // 8 | 9 | @import Foundation; 10 | #import "sqlite3.h" -------------------------------------------------------------------------------- /src/ios/libs/BaiduTraceSDK.framework/Modules/module.modulemap: -------------------------------------------------------------------------------- 1 | framework module BaiduTraceSDK { 2 | umbrella header "BaiduTraceSDK.h" 3 | 4 | export * 5 | module * { export * } 6 | } 7 | 8 | module BaiduTraceSDK.Swift { 9 | header "BaiduTraceSDK-Swift.h" 10 | } 11 | -------------------------------------------------------------------------------- /src/ios/libs/BaiduTraceSDK.framework/Headers/BaiduTraceSDK.h: -------------------------------------------------------------------------------- 1 | // 2 | // BaiduTraceSDK.h 3 | // BaiduTraceSDK 4 | // 5 | // Created by Daniel Bey on 8/1/16. 6 | // Copyright © 2016 Daniel Bey. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | //! Project version number for BaiduTraceSDK. 12 | FOUNDATION_EXPORT double BaiduTraceSDKVersionNumber; 13 | 14 | //! Project version string for BaiduTraceSDK. 15 | FOUNDATION_EXPORT const unsigned char BaiduTraceSDKVersionString[]; 16 | 17 | #import 18 | 19 | #ifndef __BaiduTraceSDK__Umbrella__ 20 | #define __BaiduTraceSDK__Umbrella__ 21 | #include "CppInterface.h" 22 | #endif 23 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "cordova-baidu-yingyan", 3 | "version": "0.1.6", 4 | "description": "百度鹰眼的cordova plugin", 5 | "main": "www/Trace.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "repository": { 10 | "type": "git", 11 | "url": "git+https://github.com/njleonzhang/cordova-baidu-yingyan.git" 12 | }, 13 | "keywords": [ 14 | "ecosystem:cordova", 15 | "baiduyingyan", 16 | "baiduTrace", 17 | "cordova-android", 18 | "cordova-ios" 19 | ], 20 | "author": "njleonzhang", 21 | "license": "MIT", 22 | "dependencies": { 23 | "xcode": "^0.8.3" 24 | }, 25 | "bugs": { 26 | "url": "https://github.com/njleonzhang/cordova-baidu-yingyan/issues" 27 | }, 28 | "homepage": "https://github.com/njleonzhang/cordova-baidu-yingyan#readme" 29 | } 30 | -------------------------------------------------------------------------------- /src/ios/BaiduTrace.h: -------------------------------------------------------------------------------- 1 | #import 2 | #import 3 | 4 | @interface BaiduTrace : CDVPlugin { 5 | @protected 6 | NSString* _AK; 7 | NSString* _MCode; 8 | BTRACE * _traceInstance; 9 | NSMutableDictionary* _customAttr; 10 | NSString* startTraceCallbackId; 11 | CDVPluginResult* startTraceResult; 12 | NSString* stopTraceCallbackId; 13 | CDVPluginResult* stopTraceResult; 14 | } 15 | 16 | - (void)startTrace:(CDVInvokedUrlCommand*)command; 17 | - (void)stopTrace:(CDVInvokedUrlCommand*)command; 18 | - (void)setInterval:(CDVInvokedUrlCommand*)command; 19 | - (void)setLocationMode:(CDVInvokedUrlCommand*)command; 20 | - (void)setProtocolType:(CDVInvokedUrlCommand*)command; 21 | @end 22 | -------------------------------------------------------------------------------- /src/ios/libs/BaiduTraceSDK.framework/Headers/CppInterface.h: -------------------------------------------------------------------------------- 1 | #ifndef __BaiduTraceSDK__CppInterface__ 2 | #define __BaiduTraceSDK__CppInterface__ 3 | 4 | #include 5 | 6 | #ifdef __cplusplus 7 | extern "C" { 8 | #endif 9 | 10 | void set_device_info(char*, int, char*, int, char*, int, char*, int, char*, int, char*, int, char*, int, char*, int); 11 | void set_gps_info(unsigned char, unsigned short, unsigned char, unsigned short, short, int, int); 12 | void add_custom_data(char*, int, char*, int); 13 | void clear_custom_data(); 14 | void build_request_data(char* , unsigned long *, unsigned short, int); 15 | void build_location_data(char*, unsigned long *); 16 | void set_app_info(char*, int, char*, int, long long, char*, int, char*, int); 17 | void parse_response_data(unsigned char *, unsigned long *, unsigned char *, int); 18 | void set_pack_data(unsigned char, char*, int); 19 | void set_push_result_data(unsigned int, unsigned char); 20 | 21 | #ifdef __cplusplus 22 | } 23 | #endif 24 | 25 | 26 | #endif 27 | -------------------------------------------------------------------------------- /src/android/JsonUtil.java: -------------------------------------------------------------------------------- 1 | package com.cordovaPlugin; 2 | /** 3 | * Created by leon on 16/6/20. 4 | */ 5 | 6 | import org.json.JSONArray; 7 | import org.json.JSONException; 8 | import org.json.JSONObject; 9 | 10 | import java.util.ArrayList; 11 | import java.util.HashMap; 12 | import java.util.Iterator; 13 | import java.util.List; 14 | import java.util.Map; 15 | 16 | public class JsonUtil { 17 | public static Map json2Map(JSONObject json) throws JSONException { 18 | Map retMap = new HashMap(); 19 | 20 | if(json != JSONObject.NULL) { 21 | retMap = toMap(json); 22 | } 23 | return retMap; 24 | } 25 | 26 | private static Map toMap(JSONObject object) throws JSONException { 27 | Map map = new HashMap(); 28 | 29 | Iterator keysItr = object.keys(); 30 | while(keysItr.hasNext()) { 31 | String key = keysItr.next(); 32 | Object value = object.get(key); 33 | 34 | if(value instanceof JSONArray) { 35 | value = toList((JSONArray) value); 36 | } 37 | 38 | else if(value instanceof JSONObject) { 39 | value = toMap((JSONObject) value); 40 | } 41 | map.put(key, value); 42 | } 43 | return map; 44 | } 45 | 46 | private static List toList(JSONArray array) throws JSONException { 47 | List list = new ArrayList(); 48 | for(int i = 0; i < array.length(); i++) { 49 | Object value = array.get(i); 50 | if(value instanceof JSONArray) { 51 | value = toList((JSONArray) value); 52 | } 53 | 54 | else if(value instanceof JSONObject) { 55 | value = toMap((JSONObject) value); 56 | } 57 | list.add(value); 58 | } 59 | return list; 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /www/Trace.js: -------------------------------------------------------------------------------- 1 | // baidu yingyan 2 | var exec = require('cordova/exec'); 3 | var SERVICE_NAME = 'BaiduTrace'; 4 | var ACTION_START_TRACE = 'startTrace'; 5 | var ACTION_STOP_TRACE = 'stopTrace'; 6 | var ACTION_SET_INTERVAL = 'setInterval'; 7 | var ACTION_SET_LOCATION_MODE = 'setLocationMode'; 8 | var ACTION_SET_PROTOCOL_TYPE = 'setProtocolType'; 9 | 10 | var baiduTrace = {}; 11 | 12 | // Returns a jQuery or AngularJS deferred object, or pass a success and fail callbacks if you don't want to use jQuery or AngularJS 13 | var getPromisedCordovaExec = function (command, entity, success, fail) { 14 | var toReturn, deferred, injector, $q; 15 | if (success === undefined) { 16 | if (window.jQuery) { 17 | deferred = jQuery.Deferred(); 18 | success = deferred.resolve; 19 | fail = deferred.reject; 20 | toReturn = deferred; 21 | } else if (window.angular) { 22 | injector = angular.injector(["ng"]); 23 | $q = injector.get("$q"); 24 | deferred = $q.defer(); 25 | success = deferred.resolve; 26 | fail = deferred.reject; 27 | toReturn = deferred.promise; 28 | } else if (window.Promise) { 29 | toReturn = new Promise(function(c, e) { 30 | success = c; 31 | fail = e; 32 | }); 33 | } else if (window.WinJS && window.WinJS.Promise) { 34 | toReturn = new WinJS.Promise(function(c, e) { 35 | success = c; 36 | fail = e; 37 | }); 38 | } else { 39 | return console.error('AppVersion either needs a success callback, or jQuery/AngularJS/Promise/WinJS.Promise defined for using promises'); 40 | } 41 | } 42 | 43 | cordova.exec(success, fail, SERVICE_NAME, command, [entity]); 44 | return toReturn; 45 | }; 46 | 47 | baiduTrace.startTrace = function(entityName, serviceId, operationMode, customAttr, success, fail) { 48 | var entity = { 49 | entityName: entityName, 50 | serviceId: serviceId, 51 | operationMode: operationMode, 52 | customAttr: customAttr || {} 53 | } 54 | return getPromisedCordovaExec(ACTION_START_TRACE, entity, success, fail); 55 | }; 56 | baiduTrace.stopTrace = function(success, fail) { 57 | return getPromisedCordovaExec(ACTION_STOP_TRACE, {}, success, fail); 58 | }; 59 | baiduTrace.setInterval = function(gatherInterval, packInterval, success, fail) { 60 | var entity = { 61 | 'gatherInterval': gatherInterval, 62 | 'packInterval': packInterval 63 | }; 64 | return getPromisedCordovaExec(ACTION_SET_INTERVAL, entity, success, fail); 65 | }; 66 | 67 | baiduTrace.setLocationMode = function(mode, success, fail) { 68 | var entity = { 69 | 'locationMode': mode 70 | }; 71 | return getPromisedCordovaExec(ACTION_SET_LOCATION_MODE, entity, success, fail); 72 | }; 73 | 74 | baiduTrace.setProtocolType = function(type, success, fail) { 75 | var entity = { 76 | 'protocolType': type 77 | }; 78 | return getPromisedCordovaExec(ACTION_SET_PROTOCOL_TYPE, entity, success, fail); 79 | }; 80 | 81 | module.exports = baiduTrace; 82 | -------------------------------------------------------------------------------- /plugin.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | BaiduTrace 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | NSAllowsArbitraryLoads 81 | 82 | 83 | 84 | 85 | 86 | 需要持续定位 87 | 88 | 89 | 90 | 91 | location 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # 百度鹰眼cordova插件 cordova-baidu-yingyan (停止维护了,请参考代码自己实现。) 2 | 3 | > 很久没有更新了现在不能用,需要使用的朋友可以自己升级一下Ios和Android的native SDK。 4 | 5 | 百度鹰眼是集轨迹追踪、轨迹数据存储、轨迹处理与查询的一套完整轨迹管理开放服务,通过覆盖多平台的SDK、API以及强大的云端服务,帮助开发者轻松开发人员和车辆轨迹追踪系统。 6 | 使用百度鹰眼,您可以轻松开发出一套适用于车队监控、外业人员监管、儿童防丢领域的轨迹管理产品。 7 | 8 | [百度的鹰眼系统](http://lbsyun.baidu.com/index.php?title=yingyan) 9 | 10 | # 下载安装 11 | `cordova plugin add cordova-baidu-yingyan` 12 | 13 | # 配置 14 | 15 | ## config.xml 16 | 17 | 1. 添加 `xmlns:android="http://schemas.android.com/apk/res/android"` 到config.xml`widget`tag 18 | 19 | 否则当你编译android app时候,你可能遇到 `AAPT: Error parsing XML: unbound prefix` 20 | 21 | 22 | 2. 添加``到config.xml 23 | 24 | 从而支持swift2.3,因为百度的SDK使用的是swift 2.3。 25 | 26 | 3. 添加``到config.xml 27 | 28 | 如果不做此设置,你的app在android 6.0上运行时,可能无法主动获取权限。 29 | 30 | ## 设置ak和mcode 31 | 32 | ### android 33 | 34 | 需要在config.xml里添加下面的配置来配置您的AK: 35 | 36 | ``` 37 | config.xml: 38 | 39 | 40 | 41 | 44 | 45 | 46 | ``` 47 | 48 | ### ios 49 | config.xml里添加如下代码,配置AK和Mcode: 50 | ``` 51 | 52 | 53 | ``` 54 | 55 | # js API 56 | 57 | * 设置打包间隔和传间隔 58 | 59 | ``` 60 | cordova.baiduTrace.setInterval(gatherInterval, packInterval).then(successCb, errorCb) 61 | 62 | gatherInterval:打包间隔,单位:秒 63 | packInterval:上传间隔,单位:秒 64 | 65 | ios限制: 66 | - gatherInterval 最小为2, 最大为60秒 67 | - packInterval 最小为2, 最大为60秒 68 | - 打包周期必须比采集周期大,且必须是采集周期的整数倍 69 | 70 | android限制: 71 | - gatherInterval 最小为2秒,最大为5分钟,否则设置不成功,默认值为5s。 72 | - packInterval 打包时间间隔必须为采集时间间隔的整数倍,且最大不能超过5分钟,否则设置不成功,默认值为30s。 73 | - 受打包数据协议最多支持10个轨迹数据的限制,请尽量控制一个打包周期内的轨迹点数量在10个以内,也就是打包周期不要超过采集周期的10倍。 74 | ``` 75 | 76 | * 设置定位方式(只有android支持) 77 | ``` 78 | cordova.baiduyingyan.setLocationMode(locationMode).then(successCb, errorCb) 79 | 80 | locationMode: 81 | * 0:高精度定位模式,GPS与网络综合定位 82 | * 1:低功耗定位模式,仅使用网络定位(WiFi和基站定位) 83 | * 2:仅使用设备(GPS)定位 84 | ``` 85 | 86 | 87 | * 设置上传用的协议(只有android支持) 88 | ``` 89 | cordova.baiduTrace.setProtocolType(type).then(successCb, errorCb) 90 | 91 | type: 获取定位的方式 92 | * 0:https类型 93 | * 1:http类型 94 | ``` 95 | 96 | * 开始采集 97 | ``` 98 | cordova.baiduTrace.startTrace(entityName, serviceId, operationMode, customAttr) 99 | .then(successCb, errorCb) 100 | 101 | entityName: 实例名 102 | serviceId: 服务ID 103 | operationMode: 操作模式 104 | * 0 : 不上传位置数据,也不接收报警信息 105 | * 1 : 不上传位置数据,但接收报警信息 106 | * 2 : 上传位置数据,且接收报警信息 107 | customAttr: 自定义属性, 见下面的栗子 108 | ``` 109 | 110 | * 停止采集 111 | 112 | ``` 113 | cordova.baiduTrace.stopTrace().then(successCb, errorCb) 114 | ``` 115 | 116 | # 栗子: 117 | 118 | ``` 119 | cordova.baiduTrace.setInterval(2, 10).then(function() { 120 | console.log('setInterval OK'); 121 | }); 122 | 123 | cordova.baiduTrace.setLocationMode(0).then(function(){ 124 | console.log('setLocationMode OK'); 125 | }); 126 | 127 | cordova.baiduTrace.setProtocolType(0).then(function(){ 128 | console.log('setProtocolType OK'); 129 | }); 130 | 131 | cordova.baiduTrace.startTrace('cordova-test', '118XXX', '2', 132 | { 133 | 'type': 'system', 134 | 'workerId': 'senior' 135 | }).then(function () { 136 | // 调用成功 137 | console.log('leon', '开始') 138 | alert('开始收集') 139 | }, function (error) { 140 | // 调用 141 | alert('收集失败' + error); 142 | }); 143 | 144 | cordova.baiduTrace.stopTrace().then(function(msg) { 145 | alert('停止收集成功:'+msg) 146 | }, function(error) { 147 | alert('停止收集失败:'+error) 148 | }); 149 | ``` 150 | 151 | # 重试机制 152 | app刚起来的时候如果调用鹰眼的这些api,可以会由于sdk还没有完全初始化导致,调用失败,所以最好给api都加入重试机制,这里是一个简单的angular版的例子: 153 | 154 | ``` 155 | angular.module('retryCall') 156 | .service('retryCall', function($q) { 157 | this.run = function(fn, ...params) { 158 | let defer = $q.defer() 159 | let retryTimes = 3 160 | let count = 0 161 | 162 | function doSafeCall() { 163 | fn.apply(null, params).then((value) => { 164 | defer.resolve(value) 165 | }, (error) => { 166 | if(count++ < 3) { 167 | console.log(`will retry ${fn} in 10 second`) 168 | window.setTimeout(() => { 169 | doSafeCall() 170 | }, 10000) 171 | } else { 172 | defer.reject() 173 | } 174 | }) 175 | } 176 | 177 | doSafeCall() 178 | return defer.promise 179 | } 180 | }) 181 | ``` 182 | 183 | 调用的api的时候,这样写: 184 | 185 | ``` 186 | retryCall.run(cordova.baiduTrace.startTrace, entityName, serviceId, operationMode).then(() => { 187 | console.log('startTrace OK') 188 | }, (error) => { 189 | console.error(`startTrace for ${cellphone} fail`, error) 190 | }) 191 | ``` 192 | 193 | # Next 194 | 提供更多接口 195 | 用swift重写ios代码 196 | -------------------------------------------------------------------------------- /src/ios/BaiduTrace.m: -------------------------------------------------------------------------------- 1 | #import "BaiduTrace.h" 2 | #import 3 | 4 | @implementation BaiduTrace 5 | 6 | - (void)pluginInitialize 7 | { 8 | _AK = [self.commandDelegate.settings objectForKey: [@"BaiduTraceIOSAK" lowercaseString]]; 9 | _MCode = [self.commandDelegate.settings objectForKey: [@"BaiduTraceIOSMCode" lowercaseString]]; 10 | NSLog(@"_AK: %@, _Mcode %@", _AK, _MCode); 11 | } 12 | 13 | - (void)initResult:(CDVPluginResult*)result status:(CDVCommandStatus)status 14 | { 15 | result = [CDVPluginResult resultWithStatus:status]; 16 | [result setKeepCallbackAsBool:YES]; 17 | } 18 | 19 | - (void)initResult:(CDVPluginResult*)result status:(CDVCommandStatus)status msg:(NSString*)msg { 20 | result = [CDVPluginResult resultWithStatus:CDVCommandStatus_NO_RESULT messageAsString:msg]; 21 | [result setKeepCallbackAsBool:YES]; 22 | } 23 | 24 | - (void)startTrace:(CDVInvokedUrlCommand*)command 25 | { 26 | startTraceCallbackId = command.callbackId; 27 | 28 | NSMutableDictionary *options = [command argumentAtIndex:0]; 29 | _customAttr = [options objectForKey:@"customAttr"]; 30 | 31 | NSLog(@"%@", [_customAttr objectForKey:@"type"]); 32 | 33 | long long serviceId = [[options objectForKey:@"serviceId"] longLongValue]; 34 | NSString* entityName = [options objectForKey:@"entityName"]; 35 | NSInteger operationMode = [[options objectForKey:@"operationMode"] integerValue]; 36 | 37 | 38 | NSLog(@"%lld %@ %ld", serviceId, entityName, (long)operationMode); 39 | 40 | _traceInstance = [[BTRACE alloc] initWithAk: _AK mcode: _MCode serviceId: serviceId entityName: entityName operationMode: operationMode]; 41 | 42 | dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ 43 | [[BTRACEAction shared] startTrace:self trace:_traceInstance]; 44 | }); 45 | } 46 | 47 | - (void)stopTrace:(CDVInvokedUrlCommand*)command 48 | { 49 | NSLog(@"%@", @"stopTrace"); 50 | stopTraceCallbackId = command.callbackId; 51 | 52 | dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ 53 | [[BTRACEAction shared] stopTrace:self trace:_traceInstance]; 54 | }); 55 | } 56 | 57 | -(void)setInterval:(CDVInvokedUrlCommand *)command 58 | { 59 | NSMutableDictionary *options = [command argumentAtIndex:0]; 60 | int32_t gatherInterval = [[options objectForKey:@"gatherInterval"] floatValue]; 61 | int32_t packInterval = [[options objectForKey:@"packInterval"] floatValue]; 62 | CDVPluginResult* intervalResult; 63 | 64 | NSLog(@"%d %d", gatherInterval, packInterval); 65 | BOOL intervalRet = [_traceInstance setInterval:gatherInterval packInterval:packInterval]; 66 | if (intervalRet) { 67 | intervalResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:@"OK"]; 68 | } else { 69 | intervalResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:@"fail"]; 70 | } 71 | [self.commandDelegate sendPluginResult:intervalResult callbackId:command.callbackId]; 72 | } 73 | 74 | -(void)setLocationMode:(CDVInvokedUrlCommand *)command 75 | { 76 | NSLog(@"IOS SDK 不支持 setLocationMode"); 77 | CDVPluginResult* result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:@"not surpport"]; 78 | [self.commandDelegate sendPluginResult:result callbackId:command.callbackId]; 79 | } 80 | 81 | -(void)setProtocolType:(CDVInvokedUrlCommand *)command 82 | { 83 | NSLog(@"IOS SDK 不支持 setProtocolType"); 84 | CDVPluginResult* result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:@"not surpport"]; 85 | [self.commandDelegate sendPluginResult:result callbackId:command.callbackId]; 86 | } 87 | 88 | - (NSDictionary*)trackAttr 89 | { 90 | NSMutableDictionary *glossary = [NSMutableDictionary dictionary]; 91 | NSString *key, *value; 92 | 93 | NSEnumerator * enumeratorKey = [_customAttr keyEnumerator]; 94 | for (NSObject *object in enumeratorKey) { 95 | key = (NSString *)object; 96 | // 下面这句支持自定义属性的值为中文,但是会向server发送encoding之后的值。 97 | // 还是不支持中文了。 98 | // value = [[_customAttr objectForKey:key] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; 99 | value = [_customAttr objectForKey:key]; 100 | 101 | [glossary setObject:value forKey: key]; 102 | } 103 | 104 | return glossary; 105 | } 106 | 107 | #pragma mark - Trace服务相关的回调方法 108 | 109 | - (void)onStartTrace:(NSInteger)errNo errMsg:(NSString *)errMsg 110 | { 111 | NSLog(@"startTrace: %ld, %@", (long)errNo, errMsg); 112 | if(errNo == 0) { 113 | startTraceResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:errMsg]; 114 | } else { 115 | startTraceResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:errMsg]; 116 | } 117 | [self.commandDelegate sendPluginResult:startTraceResult callbackId:startTraceCallbackId]; 118 | } 119 | 120 | - (void)onStopTrace:(NSInteger)errNo errMsg:(NSString *)errMsg 121 | { 122 | NSLog(@"onStopTrace: %ld, %@", (long)errNo, errMsg); 123 | if(errNo == 0) { 124 | stopTraceResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:errMsg]; 125 | } else { 126 | stopTraceResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:errMsg]; 127 | } 128 | [self.commandDelegate sendPluginResult:stopTraceResult callbackId:stopTraceCallbackId]; 129 | } 130 | 131 | // 没有用到, 但是必须实现 132 | - (void)onPushTrace:(uint8_t)msgType msgContent:(NSString *)msgContent 133 | { 134 | NSLog(@"收到推送消息: 类型[%d] 内容[%@]", msgType, msgContent); 135 | } 136 | 137 | @end 138 | -------------------------------------------------------------------------------- /hooks/addEmbedded.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const xcode = require('xcode'), 4 | fs = require('fs'), 5 | path = require('path'); 6 | 7 | module.exports = function(context) { 8 | if (process.length >= 5 && process.argv[1].indexOf('cordova') == -1) { 9 | if (process.argv[4] != 'ios') { 10 | return; // plugin only meant to work for ios platform. 11 | } 12 | } 13 | 14 | function fromDir(startPath, filter, rec, multiple) { 15 | if (!fs.existsSync(startPath)) { 16 | console.log("no dir ", startPath); 17 | console.log('cwd is:', process.cwd()) 18 | process.chdir('../../'); // rescu for after_plugin_install 19 | if (!fs.existsSync(startPath)) { 20 | console.log("no dir ", startPath); 21 | return; 22 | } 23 | } 24 | 25 | const files = fs.readdirSync(startPath); 26 | var resultFiles = [] 27 | for (var i = 0; i < files.length; i++) { 28 | var filename = path.join(startPath, files[i]); 29 | var stat = fs.lstatSync(filename); 30 | if (stat.isDirectory() && rec) { 31 | fromDir(filename, filter); //recurse 32 | } 33 | 34 | if (filename.indexOf(filter) >= 0) { 35 | if (multiple) { 36 | resultFiles.push(filename); 37 | } else { 38 | return filename; 39 | } 40 | } 41 | } 42 | if (multiple) { 43 | return resultFiles; 44 | } 45 | } 46 | 47 | function getFileIdAndRemoveFromFrameworks(myProj, fileBasename) { 48 | var fileId = ''; 49 | const pbxFrameworksBuildPhaseObjFiles = myProj.pbxFrameworksBuildPhaseObj(myProj.getFirstTarget().uuid).files; 50 | for (var i = 0; i < pbxFrameworksBuildPhaseObjFiles.length; i++) { 51 | var frameworkBuildPhaseFile = pbxFrameworksBuildPhaseObjFiles[i]; 52 | if (frameworkBuildPhaseFile.comment && frameworkBuildPhaseFile.comment.indexOf(fileBasename) != -1) { 53 | fileId = frameworkBuildPhaseFile.value; 54 | pbxFrameworksBuildPhaseObjFiles.splice(i, 1); // MUST remove from frameworks build phase or else CodeSignOnCopy won't do anything. 55 | break; 56 | } 57 | } 58 | return fileId; 59 | } 60 | 61 | function getFileRefFromName(myProj, fName) { 62 | const fileReferences = myProj.hash.project.objects['PBXFileReference']; 63 | var fileRef = ''; 64 | for (var ref in fileReferences) { 65 | if (ref.indexOf('_comment') == -1) { 66 | var tmpFileRef = fileReferences[ref]; 67 | if (tmpFileRef.name && tmpFileRef.name.indexOf(fName) != -1) { 68 | fileRef = ref; 69 | break; 70 | } 71 | } 72 | } 73 | return fileRef; 74 | } 75 | 76 | const xcodeProjPath = fromDir('platforms/ios', '.xcodeproj', false); 77 | console.log(xcodeProjPath) 78 | 79 | const projectPath = xcodeProjPath + '/project.pbxproj'; 80 | const myProj = xcode.project(projectPath); 81 | 82 | function addRunpathSearchBuildProperty(proj, build) { 83 | const LD_RUNPATH_SEARCH_PATHS = proj.getBuildProperty("LD_RUNPATH_SEARCH_PATHS", build); 84 | if (!LD_RUNPATH_SEARCH_PATHS) { 85 | proj.addBuildProperty("LD_RUNPATH_SEARCH_PATHS", "\"$(inherited) @executable_path/Frameworks\"", build); 86 | } else if (LD_RUNPATH_SEARCH_PATHS.indexOf("@executable_path/Frameworks") == -1) { 87 | var newValue = LD_RUNPATH_SEARCH_PATHS.substr(0, LD_RUNPATH_SEARCH_PATHS.length - 1); 88 | newValue += ' @executable_path/Frameworks\"'; 89 | proj.updateBuildProperty("LD_RUNPATH_SEARCH_PATHS", newValue, build); 90 | } 91 | } 92 | 93 | myProj.parseSync(); 94 | addRunpathSearchBuildProperty(myProj, "Debug"); 95 | addRunpathSearchBuildProperty(myProj, "Release"); 96 | 97 | // unquote (remove trailing ") 98 | var projectName = myProj.getFirstTarget().firstTarget.name.substr(1); 99 | projectName = projectName.substr(0, projectName.length - 1); //Removing the char " at beginning and the end. 100 | 101 | const groupName = 'Embed Frameworks ' + context.opts.plugin.id; 102 | const pluginPathInPlatformIosDir = projectName + '/Plugins/' + context.opts.plugin.id; 103 | 104 | console.log('current w f', process.cwd()) 105 | process.chdir('./platforms/ios'); 106 | const frameworkFilesToEmbed = fromDir(pluginPathInPlatformIosDir, '.framework', false, true); 107 | process.chdir('../../'); 108 | 109 | if (!frameworkFilesToEmbed.length) return; 110 | 111 | myProj.addBuildPhase(frameworkFilesToEmbed, 'PBXCopyFilesBuildPhase', groupName, myProj.getFirstTarget().uuid, 'frameworks'); 112 | 113 | for (var frmFileFullPath of frameworkFilesToEmbed) { 114 | var justFrameworkFile = path.basename(frmFileFullPath); 115 | var fileRef = getFileRefFromName(myProj, justFrameworkFile); 116 | var fileId = getFileIdAndRemoveFromFrameworks(myProj, justFrameworkFile); 117 | 118 | // Adding PBXBuildFile for embedded frameworks 119 | var file = { 120 | uuid: fileId, 121 | basename: justFrameworkFile, 122 | settings: { 123 | ATTRIBUTES: ["CodeSignOnCopy", "RemoveHeadersOnCopy"] 124 | }, 125 | 126 | fileRef: fileRef, 127 | group: groupName 128 | }; 129 | myProj.addToPbxBuildFileSection(file); 130 | 131 | // Adding to Frameworks as well (separate PBXBuildFile) 132 | var newFrameworkFileEntry = { 133 | uuid: myProj.generateUuid(), 134 | basename: justFrameworkFile, 135 | fileRef: fileRef, 136 | group: "Frameworks" 137 | }; 138 | myProj.addToPbxBuildFileSection(newFrameworkFileEntry); 139 | myProj.addToPbxFrameworksBuildPhase(newFrameworkFileEntry); 140 | } 141 | 142 | fs.writeFileSync(projectPath, myProj.writeSync()); 143 | console.log('Embedded Frameworks In ' + context.opts.plugin.id); 144 | }; 145 | -------------------------------------------------------------------------------- /src/android/BaiduTrace.java: -------------------------------------------------------------------------------- 1 | package com.bsy.cordovaPlugin; 2 | 3 | import org.apache.cordova.CallbackContext; 4 | import org.apache.cordova.CordovaInterface; 5 | import org.apache.cordova.CordovaPlugin; 6 | import org.apache.cordova.CordovaWebView; 7 | import org.json.JSONArray; 8 | import org.json.JSONException; 9 | import org.json.JSONObject; 10 | 11 | import android.content.Context; 12 | import android.util.Log; 13 | 14 | import com.baidu.trace.LBSTraceClient; 15 | import com.baidu.trace.OnStartTraceListener; 16 | import com.baidu.trace.OnStopTraceListener; 17 | import com.baidu.trace.OnTrackListener; 18 | import com.baidu.trace.Trace; 19 | import com.baidu.trace.LocationMode; 20 | import com.cordovaPlugin.JsonUtil; 21 | 22 | import android.widget.Toast; 23 | 24 | import java.util.Map; 25 | 26 | import static com.baidu.trace.LocationMode.Battery_Saving; 27 | import static com.baidu.trace.LocationMode.Device_Sensors; 28 | import static com.baidu.trace.LocationMode.High_Accuracy; 29 | 30 | public class BaiduTrace extends CordovaPlugin { 31 | private LBSTraceClient client; 32 | private Trace trace; 33 | static String debugTag = "BaiduTrace"; 34 | private Context ctx; 35 | 36 | @Override 37 | public void initialize(CordovaInterface cordova, CordovaWebView webView) { 38 | super.initialize(cordova, webView); 39 | // your init code here 40 | ctx = cordova.getActivity().getApplicationContext(); 41 | //实例化轨迹服务客户端 42 | client = new LBSTraceClient(ctx); 43 | } 44 | 45 | private void setInterval(final JSONObject options, final CallbackContext callbackContext) { 46 | try { 47 | //鹰眼服务ID 48 | int gatherInterval = options.getInt("gatherInterval"); 49 | //entity标识 50 | int packInterval = options.getInt("packInterval"); 51 | client.setInterval(gatherInterval, packInterval); 52 | callbackContext.success(); 53 | } catch (JSONException e) { 54 | Log.v(debugTag, "设置上传间隔失败"); 55 | callbackContext.error(e.getMessage()); 56 | } 57 | } 58 | 59 | private void setLocationMode(final JSONObject options, final CallbackContext callbackContext) { 60 | try { 61 | LocationMode lm = High_Accuracy; 62 | int mode = options.getInt("locationMode"); 63 | switch (mode) { 64 | case 0: 65 | lm = High_Accuracy; 66 | break; 67 | case 1: 68 | lm = Battery_Saving; 69 | break; 70 | case 2: 71 | lm = Device_Sensors; 72 | } 73 | client.setLocationMode(lm); 74 | callbackContext.success(); 75 | 76 | } catch (Exception e) { 77 | Log.v(debugTag, "设置上传间隔失败"); 78 | callbackContext.error(e.getMessage()); 79 | } 80 | } 81 | 82 | private void setProtocolType(final JSONObject options, final CallbackContext callbackContext) { 83 | try { 84 | int protocolType = options.getInt("protocolType"); 85 | client.setProtocolType(protocolType); 86 | callbackContext.success(); 87 | } catch (Exception e) { 88 | Log.v(debugTag, "设置协议失败"); 89 | callbackContext.error(e.getMessage()); 90 | } 91 | } 92 | 93 | private boolean startTrace(final JSONObject options, final CallbackContext callbackContext) { 94 | long serviceId; 95 | String entityName; 96 | int traceType; 97 | 98 | try { 99 | //鹰眼服务ID 100 | serviceId = options.getLong("serviceId"); //开发者创建的鹰眼服务ID 101 | //entity标识 102 | entityName = options.getString("entityName"); 103 | 104 | //轨迹服务类型(0 : 不上传位置数据,也不接收报警信息; 1 : 不上传位置数据,但接收报警信息;2 : 上传位置数据,且接收报警信息) 105 | traceType = options.getInt("operationMode"); 106 | 107 | } catch (JSONException e) { 108 | Log.v(debugTag, "不存在参数"); 109 | return false; 110 | } 111 | 112 | trace = new Trace(ctx, serviceId, entityName, traceType); 113 | //实例化轨迹服务 114 | 115 | client.setOnTrackListener(new OnTrackListener() { 116 | @Override 117 | public void onRequestFailedCallback(String s) { 118 | Log.v(debugTag, "请求失败, 请求查询历史?"); 119 | } 120 | 121 | @Override 122 | public Map onTrackAttrCallback() { 123 | try { 124 | // 配置返回的自定义属性 125 | JSONObject customAttr = options.getJSONObject("customAttr"); 126 | Log.v(debugTag, customAttr.toString()); 127 | return JsonUtil.json2Map(customAttr); 128 | } catch (JSONException e) { 129 | Log.v(debugTag, "customAttr 参数"); 130 | } 131 | return super.onTrackAttrCallback(); 132 | } 133 | }); 134 | 135 | //开启轨迹服务 136 | client.startTrace(trace, new OnStartTraceListener() { 137 | //开启轨迹服务回调接口(arg0 : 消息编码,arg1 : 消息内容,详情查看类参考) 138 | @Override 139 | public void onTraceCallback(int arg0, String arg1) { 140 | // TODO Auto-generated method stub 141 | if (0 == arg0 || 10006 == arg0 || 10008 == arg0) { 142 | callbackContext.success(); 143 | } else { 144 | callbackContext.error(arg1); 145 | } 146 | } 147 | 148 | // 轨迹服务推送接口(用于接收服务端推送消息,arg0 : 消息类型,arg1 : 消息内容,详情查看类参考) 149 | @Override 150 | public void onTracePushCallback(byte arg0, String arg1) { 151 | // TODO Auto-generated method stub 152 | Log.v(debugTag, "轨迹服务推送,并未使用"); 153 | } 154 | }); 155 | 156 | return true; 157 | } 158 | 159 | private boolean stopTrace(final CallbackContext callbackContext) { 160 | if (client == null || trace == null) { 161 | return false; 162 | } 163 | 164 | //停止轨迹服务 165 | client.stopTrace(trace, new OnStopTraceListener() { 166 | // 轨迹服务停止成功 167 | @Override 168 | public void onStopTraceSuccess() { 169 | Log.i(debugTag, "onStopTraceSuccess"); 170 | client.onDestroy(); 171 | if(callbackContext != null) { 172 | callbackContext.success(); 173 | } 174 | } 175 | 176 | // 轨迹服务停止失败(arg0 : 错误编码,arg1 : 消息内容,详情查看类参考) 177 | @Override 178 | public void onStopTraceFailed(int arg0, String arg1) { 179 | if(callbackContext != null) { 180 | callbackContext.error(arg1); 181 | } 182 | } 183 | }); 184 | 185 | return true; 186 | } 187 | 188 | @Override 189 | public boolean execute(String action, JSONArray args, final CallbackContext callbackContext) throws JSONException { 190 | Log.i("leon", "插件调用"); 191 | JSONObject options; 192 | 193 | try { 194 | options = args.getJSONObject(0); 195 | Log.v(debugTag, options.toString()); 196 | } catch (JSONException e) { 197 | Log.v(debugTag, "options 未传入"); 198 | return false; 199 | } 200 | 201 | if (action.equals("startTrace")) { 202 | startTrace(options, callbackContext); 203 | return true; 204 | } else if (action.equals("stopTrace")) { 205 | stopTrace(callbackContext); 206 | return true; 207 | } else if(action.equals("setInterval")){ 208 | setInterval(options, callbackContext); 209 | return true; 210 | } else if (action.equals("setLocationMode")) { 211 | setLocationMode(options, callbackContext); 212 | return true; 213 | } else if (action.equals("setProtocolType")) { 214 | setProtocolType(options, callbackContext); 215 | return true; 216 | } 217 | 218 | return false; 219 | } 220 | 221 | private void showMessage(final String message, final Integer errorNo) { 222 | Toast.makeText(cordova.getActivity().getApplicationContext(), message, Toast.LENGTH_LONG).show(); 223 | } 224 | } 225 | -------------------------------------------------------------------------------- /src/ios/libs/BaiduTraceSDK.framework/_CodeSignature/CodeResources: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | files 6 | 7 | .DS_Store 8 | 9 | 76SRYvr1fMmqBDQpK9yeES+WKrc= 10 | 11 | Frameworks/libswiftContacts.dylib 12 | 13 | DHK9b/Nemqn8ufxd3NXxmr4u1Ts= 14 | 15 | Frameworks/libswiftCore.dylib 16 | 17 | rYkRQbrU2xWrZsJQZy3t0+bwtew= 18 | 19 | Frameworks/libswiftCoreGraphics.dylib 20 | 21 | 8cRT6mI4UE04k7jgcuvfLPB8qoY= 22 | 23 | Frameworks/libswiftCoreImage.dylib 24 | 25 | wA71nJrhsUb+F4dbj11HasWWb6I= 26 | 27 | Frameworks/libswiftCoreLocation.dylib 28 | 29 | iFpemjwzMlb3b2CvVdSgbjdFfh4= 30 | 31 | Frameworks/libswiftDarwin.dylib 32 | 33 | N/8ZBPlqmXPNC4xCYJ0V2ukoIAk= 34 | 35 | Frameworks/libswiftDispatch.dylib 36 | 37 | YhXI5Sjiyf18jlKjpavEO4sqmZY= 38 | 39 | Frameworks/libswiftFoundation.dylib 40 | 41 | ejVcRGwUenqATocR1o2U4X/909o= 42 | 43 | Frameworks/libswiftObjectiveC.dylib 44 | 45 | C8OZyUfqPMOwm23u1sXge0rpdDw= 46 | 47 | Frameworks/libswiftUIKit.dylib 48 | 49 | 4GHoV4tDlvx1dtO+2kAUvf/bD5k= 50 | 51 | Headers/BaiduTraceSDK-Swift.h 52 | 53 | TAjnttwFCr10pAzFw7BmlL4kRXE= 54 | 55 | Headers/BaiduTraceSDK.h 56 | 57 | WiDu4MyIwXoTOeZe+qKAd09wIgo= 58 | 59 | Headers/CppInterface.h 60 | 61 | 2XzAQu9Sp96OXPnHaBLX+XXAY14= 62 | 63 | Headers/SqliteBriding.h 64 | 65 | ZsTYj76qOUg3FPabsHmTQ5Emdc0= 66 | 67 | Headers/sqlite3.h 68 | 69 | 8I3ZiQuFQXiMFoatSpI95r7XbPo= 70 | 71 | Info.plist 72 | 73 | yGDj1lNCcmvmdp0MZhLYKrh1i5Q= 74 | 75 | Modules/.DS_Store 76 | 77 | p1M2uf6srCyqFNrcdgvBjCDUMIo= 78 | 79 | Modules/BaiduTraceSDK.swiftmodule/arm.swiftdoc 80 | 81 | MHUpoE4G/ufK6P/iASACYXrVc7g= 82 | 83 | Modules/BaiduTraceSDK.swiftmodule/arm.swiftmodule 84 | 85 | vyuqfUKHUVNgHYaQJ9f6TlPWngE= 86 | 87 | Modules/BaiduTraceSDK.swiftmodule/arm64.swiftdoc 88 | 89 | KcExD0d9vMOrVmhwliNDPOKAwTY= 90 | 91 | Modules/BaiduTraceSDK.swiftmodule/arm64.swiftmodule 92 | 93 | kqNrkbUvfELpYNtDkNNTASqgKZo= 94 | 95 | Modules/module.modulemap 96 | 97 | Q251eeM2ZvQIiva9fXQgSUkZc5Y= 98 | 99 | baidu.com.cer 100 | 101 | tQJDYnXIh08QI9uS4wRy3VlxWeA= 102 | 103 | libswiftRemoteMirror.dylib 104 | 105 | MsIcUqmJN0JaYX6TgW+wYsQpXko= 106 | 107 | 108 | files2 109 | 110 | Frameworks/libswiftContacts.dylib 111 | 112 | hash 113 | 114 | DHK9b/Nemqn8ufxd3NXxmr4u1Ts= 115 | 116 | hash2 117 | 118 | r1XR4BrfvCpWab5U+XW/jc5M5x6S6IZbAybrbZJgh/0= 119 | 120 | 121 | Frameworks/libswiftCore.dylib 122 | 123 | hash 124 | 125 | rYkRQbrU2xWrZsJQZy3t0+bwtew= 126 | 127 | hash2 128 | 129 | gadeIhIJGWnPvkHSzol36TX2gMyrpzr7s5BBfCXixto= 130 | 131 | 132 | Frameworks/libswiftCoreGraphics.dylib 133 | 134 | hash 135 | 136 | 8cRT6mI4UE04k7jgcuvfLPB8qoY= 137 | 138 | hash2 139 | 140 | FoZNvoPSZera0hXTMhA5b00gLrmEqLzX89H8kAWwA3A= 141 | 142 | 143 | Frameworks/libswiftCoreImage.dylib 144 | 145 | hash 146 | 147 | wA71nJrhsUb+F4dbj11HasWWb6I= 148 | 149 | hash2 150 | 151 | SaLWsn5K2LyarLsUpcj9To7dhPCX+kG43fQd5jSqsPA= 152 | 153 | 154 | Frameworks/libswiftCoreLocation.dylib 155 | 156 | hash 157 | 158 | iFpemjwzMlb3b2CvVdSgbjdFfh4= 159 | 160 | hash2 161 | 162 | CCz8kOM4H15MxCINsRzmSyXl8Bj9d52EEG9/94h9QtI= 163 | 164 | 165 | Frameworks/libswiftDarwin.dylib 166 | 167 | hash 168 | 169 | N/8ZBPlqmXPNC4xCYJ0V2ukoIAk= 170 | 171 | hash2 172 | 173 | XIoF9hrA5BXS1RvuVJCDpYxfqJr/4jttpN1qw2KePeY= 174 | 175 | 176 | Frameworks/libswiftDispatch.dylib 177 | 178 | hash 179 | 180 | YhXI5Sjiyf18jlKjpavEO4sqmZY= 181 | 182 | hash2 183 | 184 | HgO95KKJ54LIO9ZtKX2RJerV0iz56HrxCZMie22Wy7Q= 185 | 186 | 187 | Frameworks/libswiftFoundation.dylib 188 | 189 | hash 190 | 191 | ejVcRGwUenqATocR1o2U4X/909o= 192 | 193 | hash2 194 | 195 | YX263/fl8VnaC7D06d6be1RVCb0xS89c5W4BoZ4ZmQc= 196 | 197 | 198 | Frameworks/libswiftObjectiveC.dylib 199 | 200 | hash 201 | 202 | C8OZyUfqPMOwm23u1sXge0rpdDw= 203 | 204 | hash2 205 | 206 | gcWqVIE//372fjWhEuezRR/657m+KGd8jVas3CBz67g= 207 | 208 | 209 | Frameworks/libswiftUIKit.dylib 210 | 211 | hash 212 | 213 | 4GHoV4tDlvx1dtO+2kAUvf/bD5k= 214 | 215 | hash2 216 | 217 | QfO5F/50Sg6wrX3KywWGYr2RlhMp2MrYhb84uz8A0s0= 218 | 219 | 220 | Headers/BaiduTraceSDK-Swift.h 221 | 222 | hash 223 | 224 | TAjnttwFCr10pAzFw7BmlL4kRXE= 225 | 226 | hash2 227 | 228 | bYsaNdzDfjSQ0PSN4tTSqHtTc4GYCrvIuvYg04WDXb4= 229 | 230 | 231 | Headers/BaiduTraceSDK.h 232 | 233 | hash 234 | 235 | WiDu4MyIwXoTOeZe+qKAd09wIgo= 236 | 237 | hash2 238 | 239 | +sLjj5vF09t9H0zbfeSMBQX+uxXrcmqyhJuXpRAtueI= 240 | 241 | 242 | Headers/CppInterface.h 243 | 244 | hash 245 | 246 | 2XzAQu9Sp96OXPnHaBLX+XXAY14= 247 | 248 | hash2 249 | 250 | Vp56DTOS7OoDcKZcEZC3FzG252Z+Y8EX2WbmwT7oLqU= 251 | 252 | 253 | Headers/SqliteBriding.h 254 | 255 | hash 256 | 257 | ZsTYj76qOUg3FPabsHmTQ5Emdc0= 258 | 259 | hash2 260 | 261 | 65IfAy90ycvXlbWz6kX45K0PMWEs19GC7/Kt6Iz8F8U= 262 | 263 | 264 | Headers/sqlite3.h 265 | 266 | hash 267 | 268 | 8I3ZiQuFQXiMFoatSpI95r7XbPo= 269 | 270 | hash2 271 | 272 | on1I9tf6kOQQGMyrO+N/kzJrFft/7XzoAcKJ56pfSEE= 273 | 274 | 275 | Modules/BaiduTraceSDK.swiftmodule/arm.swiftdoc 276 | 277 | hash 278 | 279 | MHUpoE4G/ufK6P/iASACYXrVc7g= 280 | 281 | hash2 282 | 283 | 1Uy0F6NSYhCAYWrP5Z22A19Gg+eEU+wSa68tKDI2F9g= 284 | 285 | 286 | Modules/BaiduTraceSDK.swiftmodule/arm.swiftmodule 287 | 288 | hash 289 | 290 | vyuqfUKHUVNgHYaQJ9f6TlPWngE= 291 | 292 | hash2 293 | 294 | uui4bebTV2lBtHb6SsXQBsZop9zrE5VpvvGqYebkYmc= 295 | 296 | 297 | Modules/BaiduTraceSDK.swiftmodule/arm64.swiftdoc 298 | 299 | hash 300 | 301 | KcExD0d9vMOrVmhwliNDPOKAwTY= 302 | 303 | hash2 304 | 305 | 59wNmdHdnCaN72I9xVl3c/grjGth4J8JR01CPoujQ0o= 306 | 307 | 308 | Modules/BaiduTraceSDK.swiftmodule/arm64.swiftmodule 309 | 310 | hash 311 | 312 | kqNrkbUvfELpYNtDkNNTASqgKZo= 313 | 314 | hash2 315 | 316 | PsOCDWJkHpXIndzYz0Xx7JVRqEZcyxvxV3ywsyHVBzM= 317 | 318 | 319 | Modules/module.modulemap 320 | 321 | hash 322 | 323 | Q251eeM2ZvQIiva9fXQgSUkZc5Y= 324 | 325 | hash2 326 | 327 | 7mq831OEmwlwvlR8hwMPZkSBqt47moyRF3MiT3U5Q70= 328 | 329 | 330 | baidu.com.cer 331 | 332 | hash 333 | 334 | tQJDYnXIh08QI9uS4wRy3VlxWeA= 335 | 336 | hash2 337 | 338 | VWBj1XolpWACGyLeI7Z6WQ/TmMC3fdwzHnnXf0siBxI= 339 | 340 | 341 | libswiftRemoteMirror.dylib 342 | 343 | hash 344 | 345 | MsIcUqmJN0JaYX6TgW+wYsQpXko= 346 | 347 | hash2 348 | 349 | dzXjnO4rfJVgZgswQFCsduPEuiT5n/MQYW9SacYWGKI= 350 | 351 | 352 | 353 | rules 354 | 355 | ^ 356 | 357 | ^.*\.lproj/ 358 | 359 | optional 360 | 361 | weight 362 | 1000 363 | 364 | ^.*\.lproj/locversion.plist$ 365 | 366 | omit 367 | 368 | weight 369 | 1100 370 | 371 | ^Base\.lproj/ 372 | 373 | weight 374 | 1010 375 | 376 | ^version.plist$ 377 | 378 | 379 | rules2 380 | 381 | .*\.dSYM($|/) 382 | 383 | weight 384 | 11 385 | 386 | ^ 387 | 388 | weight 389 | 20 390 | 391 | ^(.*/)?\.DS_Store$ 392 | 393 | omit 394 | 395 | weight 396 | 2000 397 | 398 | ^(Frameworks|SharedFrameworks|PlugIns|Plug-ins|XPCServices|Helpers|MacOS|Library/(Automator|Spotlight|LoginItems))/ 399 | 400 | nested 401 | 402 | weight 403 | 10 404 | 405 | ^.* 406 | 407 | ^.*\.lproj/ 408 | 409 | optional 410 | 411 | weight 412 | 1000 413 | 414 | ^.*\.lproj/locversion.plist$ 415 | 416 | omit 417 | 418 | weight 419 | 1100 420 | 421 | ^Base\.lproj/ 422 | 423 | weight 424 | 1010 425 | 426 | ^Info\.plist$ 427 | 428 | omit 429 | 430 | weight 431 | 20 432 | 433 | ^PkgInfo$ 434 | 435 | omit 436 | 437 | weight 438 | 20 439 | 440 | ^[^/]+$ 441 | 442 | nested 443 | 444 | weight 445 | 10 446 | 447 | ^embedded\.provisionprofile$ 448 | 449 | weight 450 | 20 451 | 452 | ^version\.plist$ 453 | 454 | weight 455 | 20 456 | 457 | 458 | 459 | 460 | -------------------------------------------------------------------------------- /src/ios/libs/BaiduTraceSDK.framework/Headers/BaiduTraceSDK-Swift.h: -------------------------------------------------------------------------------- 1 | // Generated by Apple Swift version 2.3 (swiftlang-800.10.12 clang-800.0.38) 2 | #pragma clang diagnostic push 3 | 4 | #if defined(__has_include) && __has_include() 5 | # include 6 | #endif 7 | 8 | #pragma clang diagnostic ignored "-Wauto-import" 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | #if !defined(SWIFT_TYPEDEFS) 15 | # define SWIFT_TYPEDEFS 1 16 | # if defined(__has_include) && __has_include() 17 | # include 18 | # elif !defined(__cplusplus) || __cplusplus < 201103L 19 | typedef uint_least16_t char16_t; 20 | typedef uint_least32_t char32_t; 21 | # endif 22 | typedef float swift_float2 __attribute__((__ext_vector_type__(2))); 23 | typedef float swift_float3 __attribute__((__ext_vector_type__(3))); 24 | typedef float swift_float4 __attribute__((__ext_vector_type__(4))); 25 | typedef double swift_double2 __attribute__((__ext_vector_type__(2))); 26 | typedef double swift_double3 __attribute__((__ext_vector_type__(3))); 27 | typedef double swift_double4 __attribute__((__ext_vector_type__(4))); 28 | typedef int swift_int2 __attribute__((__ext_vector_type__(2))); 29 | typedef int swift_int3 __attribute__((__ext_vector_type__(3))); 30 | typedef int swift_int4 __attribute__((__ext_vector_type__(4))); 31 | #endif 32 | 33 | #if !defined(SWIFT_PASTE) 34 | # define SWIFT_PASTE_HELPER(x, y) x##y 35 | # define SWIFT_PASTE(x, y) SWIFT_PASTE_HELPER(x, y) 36 | #endif 37 | #if !defined(SWIFT_METATYPE) 38 | # define SWIFT_METATYPE(X) Class 39 | #endif 40 | 41 | #if defined(__has_attribute) && __has_attribute(objc_runtime_name) 42 | # define SWIFT_RUNTIME_NAME(X) __attribute__((objc_runtime_name(X))) 43 | #else 44 | # define SWIFT_RUNTIME_NAME(X) 45 | #endif 46 | #if defined(__has_attribute) && __has_attribute(swift_name) 47 | # define SWIFT_COMPILE_NAME(X) __attribute__((swift_name(X))) 48 | #else 49 | # define SWIFT_COMPILE_NAME(X) 50 | #endif 51 | #if !defined(SWIFT_CLASS_EXTRA) 52 | # define SWIFT_CLASS_EXTRA 53 | #endif 54 | #if !defined(SWIFT_PROTOCOL_EXTRA) 55 | # define SWIFT_PROTOCOL_EXTRA 56 | #endif 57 | #if !defined(SWIFT_ENUM_EXTRA) 58 | # define SWIFT_ENUM_EXTRA 59 | #endif 60 | #if !defined(SWIFT_CLASS) 61 | # if defined(__has_attribute) && __has_attribute(objc_subclassing_restricted) 62 | # define SWIFT_CLASS(SWIFT_NAME) SWIFT_RUNTIME_NAME(SWIFT_NAME) __attribute__((objc_subclassing_restricted)) SWIFT_CLASS_EXTRA 63 | # define SWIFT_CLASS_NAMED(SWIFT_NAME) __attribute__((objc_subclassing_restricted)) SWIFT_COMPILE_NAME(SWIFT_NAME) SWIFT_CLASS_EXTRA 64 | # else 65 | # define SWIFT_CLASS(SWIFT_NAME) SWIFT_RUNTIME_NAME(SWIFT_NAME) SWIFT_CLASS_EXTRA 66 | # define SWIFT_CLASS_NAMED(SWIFT_NAME) SWIFT_COMPILE_NAME(SWIFT_NAME) SWIFT_CLASS_EXTRA 67 | # endif 68 | #endif 69 | 70 | #if !defined(SWIFT_PROTOCOL) 71 | # define SWIFT_PROTOCOL(SWIFT_NAME) SWIFT_RUNTIME_NAME(SWIFT_NAME) SWIFT_PROTOCOL_EXTRA 72 | # define SWIFT_PROTOCOL_NAMED(SWIFT_NAME) SWIFT_COMPILE_NAME(SWIFT_NAME) SWIFT_PROTOCOL_EXTRA 73 | #endif 74 | 75 | #if !defined(SWIFT_EXTENSION) 76 | # define SWIFT_EXTENSION(M) SWIFT_PASTE(M##_Swift_, __LINE__) 77 | #endif 78 | 79 | #if !defined(OBJC_DESIGNATED_INITIALIZER) 80 | # if defined(__has_attribute) && __has_attribute(objc_designated_initializer) 81 | # define OBJC_DESIGNATED_INITIALIZER __attribute__((objc_designated_initializer)) 82 | # else 83 | # define OBJC_DESIGNATED_INITIALIZER 84 | # endif 85 | #endif 86 | #if !defined(SWIFT_ENUM) 87 | # define SWIFT_ENUM(_type, _name) enum _name : _type _name; enum SWIFT_ENUM_EXTRA _name : _type 88 | # if defined(__has_feature) && __has_feature(generalized_swift_name) 89 | # define SWIFT_ENUM_NAMED(_type, _name, SWIFT_NAME) enum _name : _type _name SWIFT_COMPILE_NAME(SWIFT_NAME); enum SWIFT_COMPILE_NAME(SWIFT_NAME) SWIFT_ENUM_EXTRA _name : _type 90 | # else 91 | # define SWIFT_ENUM_NAMED(_type, _name, SWIFT_NAME) SWIFT_ENUM(_type, _name) 92 | # endif 93 | #endif 94 | #if defined(__has_feature) && __has_feature(modules) 95 | @import ObjectiveC; 96 | @import CoreLocation; 97 | @import Foundation; 98 | #endif 99 | 100 | #pragma clang diagnostic ignored "-Wproperty-attribute-mismatch" 101 | #pragma clang diagnostic ignored "-Wduplicate-method-arg" 102 | @class NSData; 103 | 104 | 105 | /// entity相关的协议,包括创建实体对象、更新实体对象、检索实体对象等请求的回调方法 106 | SWIFT_PROTOCOL("_TtP13BaiduTraceSDK25ApplicationEntityDelegate_") 107 | @protocol ApplicationEntityDelegate 108 | @optional 109 | 110 | /// addEntity(_:serviceId:entityName:columnKey:) 方法的回调方法 111 | /// 112 | ///

Note:

113 | /// 按照JSON格式去解析返回的NSData,返回的格式请参考鹰眼WEB-API的entity/add接口的返回值 114 | /// 115 | /// \param data 创建实体对象的结果 116 | - (void)onAddEntity:(NSData * _Nonnull)data; 117 | 118 | /// updateEntity(_:serviceId:entityName:columnKey:) 方法的回调方法 119 | /// 120 | ///

Note:

121 | /// 按照JSON格式去解析返回的NSData,返回的格式请参考鹰眼WEB-API的entity/update接口的返回值 122 | /// 123 | /// \param data 更新实体对象的结果 124 | - (void)onUpdateEntity:(NSData * _Nonnull)data; 125 | 126 | /// queryEntityList(_:serviceId:entityNames:columnKey:activeTime:returnType:pageSize:pageIndex:) 方法的回调方法 127 | /// 128 | ///

Note:

129 | /// 按照JSON格式去解析返回的NSData,返回的格式请参考鹰眼WEB-API的entity/list接口的返回值 130 | /// 131 | /// \param data 查询实体对象的结果 132 | - (void)onQueryEntityList:(NSData * _Nonnull)data; 133 | @end 134 | 135 | 136 | 137 | /// ApplicationFenceDelegate 协议包含服务端地理围栏的增删改查以及围栏状态、历史报警信息等请求的回调方法 138 | SWIFT_PROTOCOL("_TtP13BaiduTraceSDK24ApplicationFenceDelegate_") 139 | @protocol ApplicationFenceDelegate 140 | @optional 141 | 142 | /// createCircularFence(_:serviceId:fenceName:fenceDesc:creator:monitoredPersons:observers:validTimes:validCycle:validDate:validDays:coordType:center:radius:alarmCondition:precision:) 方法和 createVertexesFence(_:serviceId:fenceName:fenceDesc:creator:monitoredPersons:observers:validTimes:validCycle:validDate:validDays:coordType:vertexes:alarmCondition:precision:) 方法的回调方法 143 | /// 144 | ///

Note:

145 | /// 按照JSON格式去解析返回的NSData,返回的格式请参考鹰眼WEB-API的 fence/create 接口的返回值 146 | /// 147 | /// \param data 创建服务端地理围栏的结果 148 | - (void)onCreateFence:(NSData * _Nonnull)data; 149 | 150 | /// createLocalFence(_:fence:) 方法的回调方法 151 | /// 152 | ///

Note:

153 | /// 按照JSON格式去解析返回的NSData,创建成功会返回fence_id 154 | /// 155 | /// \param data 创建客户端地理围栏的结果 156 | - (void)onCreateLocalFence:(NSData * _Nonnull)data; 157 | 158 | /// deleteLocalFence(_:fenceId:) 方法的回调方法 159 | /// 160 | ///

Note:

161 | /// 按照JSON格式去解析返回的NSData 162 | /// 163 | /// \param data 删除客户端地理围栏的结果 164 | - (void)onDeleteLocalFence:(NSData * _Nonnull)data; 165 | 166 | /// updateFence(_:serviceId:fenceId:fenceName:fenceDesc:monitoredPersons:observers:validTimes:validCycle:validDate:validDays:shape:coordType:center:radius:vertexes:alarmCondition:precision:) 方法的回调方法 167 | /// 168 | ///

Note:

169 | /// 按照JSON格式去解析返回的NSData,返回的格式请参考鹰眼WEB-API的 fence/update 接口的返回值 170 | /// 171 | /// \param data 更新服务端地理围栏的结果 172 | - (void)onUpdateFence:(NSData * _Nonnull)data; 173 | 174 | /// deleteFence(_:serviceId:fenceId:) 方法的回调方法 175 | /// 176 | ///

Note:

177 | /// 按照JSON格式去解析返回的NSData,返回的格式请参考鹰眼WEB-API的 fence/delete 接口的返回值 178 | /// 179 | /// \param data 删除服务端地理围栏的结果 180 | - (void)onDeleteFence:(NSData * _Nonnull)data; 181 | 182 | /// queryFenceList(_:serviceId:creator:fenceIds:) 方法的回调方法 183 | /// 184 | ///

Note:

185 | /// 按照JSON格式去解析返回的NSData,返回的格式请参考鹰眼WEB-API的 fence/list 接口的返回值 186 | /// 187 | /// \param data 查询服务端地理围栏的结果 188 | - (void)onFenceList:(NSData * _Nonnull)data; 189 | 190 | /// queryFenceStatus(_:serviceId:fenceId:monitoredPersons:) 方法的回调方法 191 | /// 192 | ///

Note:

193 | /// 按照JSON格式去解析返回的NSData,返回的格式请参考鹰眼WEB-API的 fence/querystatus 接口的返回值 194 | /// 195 | /// \param data 查询指定的被监控对象的状态的结果 196 | - (void)onQueryFenceStatus:(NSData * _Nonnull)data; 197 | 198 | /// queryFenceHistoryAlarm(_:serviceId:fenceId:monitoredPersons:beginTime:endTime:) 方法的回调方法 199 | /// 200 | ///

Note:

201 | /// 按照JSON格式去解析返回的NSData,返回的格式请参考鹰眼WEB-API的 fence/historyalarm 接口的返回值 202 | /// 203 | /// \param data 查询指定的地理围栏历史报警的结果 204 | - (void)onQueryFenceHistoryAlarm:(NSData * _Nonnull)data; 205 | @end 206 | 207 | 208 | 209 | /// 轨迹服务的协议,包括轨迹服务相关的回调方法 210 | /// 211 | ///

Important Notes

212 | ///
  • 遵守 ApplicationServiceDelegate 213 | /// 的类,可以接收服务开启、服务结束的回调。
  • 遵守 ApplicationServiceDelegate 214 | /// 的类,也可以接收服务运行时修改采集和打包周期的回调。
  • 自定义字段的上传,也需要实现本协议中的 trackAttr() 215 | /// 回调方法。
216 | SWIFT_PROTOCOL("_TtP13BaiduTraceSDK26ApplicationServiceDelegate_") 217 | @protocol ApplicationServiceDelegate 218 | @optional 219 | 220 | /// 开始轨迹服务的回调方法 221 | /// 222 | ///

状态码和状态信息的对应关系如下

223 | ///
  • 0代表开始追踪成功,当前已登陆到服务器
  • 1代表内部错误
  • 10002代表参数错误
  • 10003代表当前模式为不建立长连接,不能开启追踪服务
  • 10007代表开始追踪成功,当前未登陆到服务器,当前模式为UPLOADLOCATION, 已经开始缓存数据
  • 10008代表开始追踪成功,当前未登陆到服务器,当前模式为NOUPLOADLOCATION, 当网络连接正常时会自动重新登陆
  • 10010代表正在开启服务
  • 10011代表正在结束服务
224 | ///

Note

225 | ///
  • 轨迹服务的开启过程需要一定的时间
  • 由于历史原因,状态码和状态信息分别采用Int和String类型。v3.0版本的SDK可能会改为泛型枚举等标准Swift的方式来提供异步API的状态,具体实现方式依赖未来版本的Swift和OC的桥接支持程度
226 | /// \param errNo 开始轨迹服务的状态码 227 | /// 228 | /// \param errMsg 开始轨迹服务的状态信息 229 | - (void)onStartTrace:(NSInteger)errNo errMsg:(NSString * _Nonnull)errMsg; 230 | 231 | /// 获取自定义字段的值的回调方法,SDK会在每个采集周期回调此方法,将其返回值作为当前采集周期的轨迹点的自定义字段。 232 | /// 233 | ///

Note

234 | ///
  • 在轨迹服务运行期间,此方法将在每个采集周期被SDK调用一次,遵循 ApplicationServiceDelegate 235 | /// 协议的类,只有需要为轨迹点附加自定义数据时,才需要实现此方法。
  • 每个采集周期对应轨迹点的速度、方向、高度、定位精度的值,作为轨迹数据的一部分,SDK会自动采集,不需要额外实现此方法去指定。
  • SDK会解析此方法返回的字典,将key认为是自定义字段的名称,将value认为是自定义字段的值。需要注意的是,字典中的key必须先通过鹰眼webapi的 track/addcolumn 接口添加过才有效。
236 | ///

最佳实践

237 | /// 每个轨迹点都可能有一些和具体业务相关的数据,可以通过此方法将这些数据作为轨迹点的自定义数据“附加”到这个轨迹点上。比如当前在开发一款跑步类的APP,可能需要记录每个轨迹点所对应的心率信息,那么可以通过以下几个步骤实现这一点。 238 | /// 239 | ///
  1. 通过鹰眼webapi的 track/addcolumn 接口添加一个叫做heart_rate 240 | /// 的字段.
  2. 通过心率带或带有心率检测功能的外部设备获取心率,并通过其相应的接口将心率数据传入APP
  3. 定义一个字典类型的变量,包含一个名为heart_rate 241 | /// 的键,并设置其初始值。假设为additional_data['heart_rate'] = 60。
  4. 每当APP获取到最新的心率数据时,更新这个字典中heart_rate 242 | /// 的值为最新的心率数据。
  5. trackAttr() 243 | /// 方法的实现非常简单,只需要return这个字典即可。
  6. 通过以上步骤,SDK在每个采集周期回调这个方法时,就获取到了最新的心率数据,并将此心率数据“附加”在了当前的轨迹点上。无论是通过 queryEntityList(_:serviceId:entityNames:columnKey:activeTime:returnType:pageSize:pageIndex:) 244 | /// 方法查询实时位置,还是通过getTrackHistory 245 | /// 方法查询历史轨迹,这些心率数据都会作为轨迹的“附加”数据呈现出来。
246 | /// \returns 自定义字段的字典 247 | - (NSDictionary * _Nullable)trackAttr; 248 | 249 | /// 结束轨迹服务的回调方法 250 | /// 251 | ///

状态码和状态信息的对应关系如下

252 | ///
  • 0 代表停止成功
  • 11002 代表还没开始,无法停止
  • 11004 代表正在开始,无法停止
  • 11005 代表正在结束服务
  • 10006 代表当前类型为不建立长连接, 无法停止追踪
253 | ///

Note

254 | ///
  • 轨迹服务的结束过程需要一定的时间。
  • 若当前没有缓存数据需要上传,或者当前有缓存数据待上传,但网络不通,服务的结束最多需要等待一个采集周期的时间。
  • 若当前有较多的缓存数据待上传,且当前网络畅通,会把所有的缓存数据上传完毕后才能结束,因此需要的时间可能比较久。
  • 由于历史原因,状态码和状态信息分别采用Int和String类型。v3.0版本的SDK可能会改为泛型枚举等标准Swift的方式来提供异步API的状态,具体实现方式依赖未来版本的Swift和OC的桥接支持程度
255 | /// \param errNo 开始轨迹服务的状态码 256 | /// 257 | /// \param errMsg 开始轨迹服务的状态信息 258 | - (void)onStopTrace:(NSInteger)errNo errMsg:(NSString * _Nonnull)errMsg; 259 | 260 | /// 推送信息的回调方法,当收到来自服务端的推送消息(比如地理围栏的触发消息)时,SDK会回调此方法 261 | /// 262 | ///

msgType字段的值代表的推送消息类型

263 | ///
  • 0x01:配置下发;
  • 0x02:语音消息;
  • 0x03:服务端地理围栏报警消息;
  • 0x04:客户端地理围栏报警消息;
  • 0x05~0x40:系统预留;
  • 0x41~0xFF:开发者自定义;
264 | ///

msgType为报警推送时,msgContent字段中JSON字段的说明

265 | ///
  • fence_id 触发报警的服务端地理围栏的唯一标识
  • fence 触发报警的服务端地理围栏的名称
  • monitored_person 触发报警的地理围栏所监控的entity的名称
  • action 被监控对象进出围栏的动作 1代表进入围栏 2代表离开围栏
  • time 代表地理围栏被触发的时间
266 | /// \param msgType 推送消息的类型 267 | /// 268 | /// \param msgContent 推送消息的内容,JSON格式的字符串类型 269 | - (void)onPushTrace:(uint8_t)msgType msgContent:(NSString * _Nonnull)msgContent; 270 | 271 | /// 轨迹服务开始后调用 changeGatherAndPackIntervalsAfterStartTrace(_:gatherInterval:packInterval:) 方法改变采集和打包周期后的回调方法 272 | /// 273 | ///

状态码和状态信息的对应关系如下

274 | ///
  • 0 设置成功
  • 1 设置失败
  • 2 参数错误
  • 3 当前模式为不采集和上传位置数据
  • 4 本方法需要先startTrace再调用
275 | /// \param errNo 改变周期后的状态码 276 | /// 277 | /// \param errMsg 改变周期的状态信息 278 | - (void)onChangeGatherAndPackIntervalsAfterStartTrace:(NSInteger)errNo errMsg:(NSString * _Nonnull)errMsg; 279 | @end 280 | 281 | 282 | 283 | /// ApplicationTrackDelegate 协议包含历史轨迹查询以及里程查询的回调方法 284 | SWIFT_PROTOCOL("_TtP13BaiduTraceSDK24ApplicationTrackDelegate_") 285 | @protocol ApplicationTrackDelegate 286 | @optional 287 | 288 | /// getTrackHistory(_:serviceId:entityName:startTime:endTime:simpleReturn:isProcessed:processOption:supplementMode:sortType:pageSize:pageIndex:) 方法以及 getTrackHistory(_:serviceId:entityName:startTime:endTime:simpleReturn:isProcessed:pageSize:pageIndex:) 方法的回调方法 289 | /// 290 | ///

Note:

291 | /// 按照JSON格式去解析返回的NSData,返回的格式请参考鹰眼WEB-API的 track/gethistory 接口的返回值 292 | /// 293 | /// \param data 查询指定实体对象的历史轨迹的结果 294 | - (void)onGetHistoryTrack:(NSData * _Nonnull)data; 295 | 296 | /// queryDistance(_:serviceId:entityName:isProcessed:processOption:supplementMode:startTime:endTime:) 方法的回调方法 297 | /// 298 | ///

Note:

299 | /// 按照JSON格式去解析返回的NSData,返回的格式请参考鹰眼WEB-API的 track/gethistory 接口当指定isProcessed=2时的返回值 300 | /// 301 | /// \param data 查询指定实体对象在指定时间短内的里程的结果 302 | - (void)onQueryDistance:(NSData * _Nonnull)data; 303 | @end 304 | 305 | 306 | 307 | /// 客户端地理围栏信息类,使用客户端地理围栏之前需要先实例化BLocalFence类。 308 | /// 309 | ///

Note:

310 | ///
  • 目前客户端地理围栏仅支持圆形围栏。
  • 客户端地理围栏的创建、删除、触发计算、报警推送都在客户端进行,不受网络连通状态的限制。
  • 由于客户端地理围栏的运行完全都在客户端进行,和服务端地理围栏没有任何关系。所以即使设置了圆心和半径以及去燥精度完全相同的客户端和服务端地理围栏,完全有可能一个报警,另一个不报警。
  • 客户端地理围栏是为了对服务端地理围栏进行补充,有的情况下,设备可能在较长时间都处于离线状态,此时SDK虽然会对轨迹进行缓存,但由于无法讲轨迹数据上传回服务端,所以无法触发服务端的地理围栏。客户端地理围栏在断网状态下仍然可以正常计算及推送报警。
  • 用户可以既创建客户端地理围栏,又创建服务端地理围栏。接收到它们的报警推送后,根据自身的业务场景,决定以客户端地理围栏的报警为准,还是服务端围栏的报警为准,或者综合考虑作出判断。
311 | SWIFT_CLASS("_TtC13BaiduTraceSDK11BLocalFence") 312 | @interface BLocalFence : NSObject 313 | 314 | /// BLocalFence类的构造函数,目前客户端地理围栏只支持圆形地理围栏,通过此构造函数创建出来的客户端地理围栏是圆形的。 315 | /// 316 | ///

Usage Example

317 | ///
Swift
318 | /// let loc = CLLocationCoordinate2D(latitude: 40.0, longitude: 116.0) 319 | /// let lf = BLocalFence(name: "fenceA", center: loc, coordType: 3, radius: 10, accuracy: 10) 320 | /// 321 | /// 322 | ///
Objective-C
323 | /// CLLocationCoordinate2D center = CLLocationCoordinate2DMake(40.0, 116.0); 324 | /// BLocalFence* localFence = [[BLocalFence alloc] initWithName:@"fenceA" center:center coordType:3 radius:50 accuracy: 50]; 325 | /// 326 | /// 327 | /// \param name 圆形地理围栏的名称 328 | /// 329 | /// \param center 圆形地理围栏的圆心 330 | /// 331 | /// \param coordType 圆心的坐标类型 332 | /// 333 | /// \param radius 圆形地理围栏的半径,单位为米 334 | /// 335 | /// \param accuracy 地理围栏去燥的精度,若采集到的轨迹点的定位精度大于此值,则不会进行客户端围栏的计算,也就不会触发客户端地理围栏的报警。如果希望所有采集到的轨迹点都进行客户端围栏的计算,将此字段的值设为0。 336 | /// 337 | /// \returns BLocalFence 338 | /// 类的对象 339 | - (nonnull instancetype)initWithName:(NSString * _Nonnull)name center:(CLLocationCoordinate2D)center coordType:(uint8_t)coordType radius:(double)radius accuracy:(NSInteger)accuracy OBJC_DESIGNATED_INITIALIZER; 340 | @end 341 | 342 | 343 | 344 | /// 轨迹服务信息类 345 | /// 346 | ///

Important Notes

347 | ///
  • BTRACE 348 | /// 类包含了SDK运行所需要的重要信息,是使用SDK的基础
  • 访问SDK的任何方法前,都必需先实例化 BTRACE 349 | ///
350 | SWIFT_CLASS("_TtC13BaiduTraceSDK6BTRACE") 351 | @interface BTRACE : NSObject 352 | 353 | /// BTRACE类的构造函数\Warning 354 | /// 355 | /// 356 | /// 357 | ///
  • 使用SDK的任何方法之前,都必须先实例化 BTRACE 358 | /// 类。如果在实例化 BTRACE 359 | /// 类之前调用SDK中的其他方法,会导致开启轨迹服务失败,查询轨迹、创建围栏等操作报错等各种问题
  • BTRACE 360 | /// 类初始化失败只可能有一种原因,就是SDK没有被正确的导入。如果出现BTRACE 361 | /// 类初始化后的结果为nil的情况,请检查SDK的导入步骤是否正确。
362 | ///

Notes:

363 | ///
  1. 此处的ak必须是在 API控制台 申请的iOS类型的ak
  2. serviceId参数并非申请ak时的应用编号,而是在 鹰眼轨迹管理台 创建鹰眼服务之后,分配的service_id
  3. 开始轨迹服务后,SDK所采集到的轨迹都属于此处的entityName名下
364 | ///

Usage Example

365 | ///
Swift
366 | /// let traceInstance = BTRACE(ak: "aa", mcode: "bb", serviceId: 123, entityName: "aa", operationMode: 2) 367 | /// 368 | /// 369 | ///
Objective-C
370 | /// BTRACE * traceInstance = NULL; 371 | /// traceInstance = [[BTRACE alloc] initWithAk: @"aa" mcode: @"bb" serviceId: 123 entityName: @"aa" operationMode: 2]; 372 | /// 373 | /// 374 | /// \param ak 从API控制台申请应用时分配的ak 375 | /// 376 | /// \param mcode 申请ak时填写的安全码 377 | /// 378 | /// \param serviceId 鹰眼轨迹管理台创建鹰眼服务时分配的service_id 379 | /// 380 | /// \param entityName 被监控对象的名称 381 | /// 382 | /// \param operationMode 轨迹服务的类型 0 383 | /// :不建立长连接 1 384 | /// :建立长连接但不采集数据 2 385 | /// :建立长连接并采集数据 386 | /// 387 | /// \returns BTRACE 388 | /// 类的对象 389 | - (nonnull instancetype)initWithAk:(NSString * _Nonnull)ak mcode:(NSString * _Nonnull)mcode serviceId:(long long)serviceId entityName:(NSString * _Nonnull)entityName operationMode:(NSInteger)operationMode OBJC_DESIGNATED_INITIALIZER; 390 | 391 | /// 设置轨迹服务的采集周期和打包周期 392 | /// 393 | ///

Notes

394 | ///
  • 轨迹服务会在每个采集周期采集当前的位置数据,并在每个打包周期将这些轨迹打包、压缩、加密之后上传至服务端
  • 实例化 BTRACE 395 | /// 类之后,在调用 startTrace(_:trace:) 396 | /// 方法之前,通过此方法设置轨迹服务的采集周期和打包周期
  • 在startTrace开始轨迹服务之后,若想改变采集和打包周期,调用 BTRACEAction 397 | /// 中的 changeGatherAndPackIntervalsAfterStartTrace(_:gatherInterval:packInterval:) 398 | /// 方法
399 | ///

Requires

400 | ///
  • 采集周期最小为2秒,最大为60秒
  • 打包周期最小为2秒,最大为60秒
  • 打包周期必须比采集周期大,且必须是采集周期的整数倍
401 | ///

Usage Example

402 | ///
Swift
403 | /// //先实例化BTRACE类得到traceInstance对象 404 | /// traceInstance.setInterval(2, packInterval: 10) 405 | /// 406 | /// 407 | ///
Objective-C
408 | /// //先实例化 `BTRACE` 类得到traceInstance对象 409 | /// BOOL intervalSetRet = [traceInstance setInterval:2 packInterval:10]; 410 | /// 411 | /// 412 | ///
  • requires 打包周期必须比采集周期大,且必须是采集周期的整数倍
413 | /// \param gatherInterval 轨迹服务的采集周期 414 | /// 415 | /// \param packInterval 轨迹服务的打包周期 416 | /// 417 | /// \returns 设置成功或失败。true代表成功,false代表失败。 418 | - (BOOL)setInterval:(int32_t)gatherInterval packInterval:(int32_t)packInterval; 419 | @end 420 | 421 | 422 | 423 | /// BTRACEAction 类中提供了SDK中所有方法的全局访问点,在实例化 BTRACE 类之后,才可以使用 BTRACEAction 类中的方法 424 | SWIFT_CLASS("_TtC13BaiduTraceSDK12BTRACEAction") 425 | @interface BTRACEAction : NSObject 426 | 427 | /// BTRACEAction 类的全局访问点 428 | + (BTRACEAction * _Nonnull)shared; 429 | 430 | /// 获取当前SDK的版本号 431 | /// 432 | ///

Usage Example

433 | ///
Swift
434 | /// BTRACEAction.shared.getCurrentVersion() 435 | /// 436 | /// 437 | ///
Objective-C
438 | /// [[BTRACEAction shared] getCurrentVersion]; 439 | /// 440 | /// 441 | /// \returns 当前SDK的版本号 442 | - (NSString * _Nonnull)getCurrentVersion; 443 | 444 | /// 开始轨迹服务 445 | /// 446 | ///

Usage Example

447 | ///
Swift
448 | /// BTRACEAction.shared.startTrace(self, trace: traceInstance) 449 | /// 450 | /// 451 | ///
Objective-C
452 | /// [[BTRACEAction shared] startTrace:self trace:traceInstance]; 453 | /// 454 | /// 455 | /// \param delegate 遵循 ApplicationServiceDelegate 456 | /// 协议的对象。开启轨迹服务的结果会通过 onStartTrace(_:errMsg:) 457 | /// 方法进行回调 458 | /// 459 | /// \param trace BTRACE 460 | /// 类的对象 461 | /// 462 | /// \returns 本方法为异步方法,执行结果通过 ApplicationServiceDelegate 463 | /// 协议中的 onStartTrace(_:errMsg:) 464 | /// 回调方法获取 465 | - (void)startTrace:(id _Nonnull)delegate trace:(BTRACE * _Nonnull)trace; 466 | 467 | /// 结束轨迹服务 468 | /// 469 | ///

Usage Example

470 | ///
Swift
471 | /// BTRACEAction.shared.stopTrace(self, trace: traceInstance) 472 | /// 473 | /// 474 | ///
Objective-C
475 | /// [[BTRACEAction shared] stopTrace:self trace:traceInstance]; 476 | /// 477 | /// 478 | /// \param delegate 遵循 ApplicationServiceDelegate 479 | /// 协议的对象。结束轨迹服务的结果会通过 onStopTrace(_:errMsg:) 480 | /// 方法进行回调 481 | /// 482 | /// \param trace BTRACE 483 | /// 类的对象 484 | /// 485 | /// \returns 本方法为异步方法,执行结果通过 ApplicationServiceDelegate 486 | /// 协议中的 onStopTrace(_:errMsg:) 487 | /// 回调方法获取 488 | - (void)stopTrace:(id _Nonnull)delegate trace:(BTRACE * _Nonnull)trace; 489 | 490 | /// 在轨迹服务开启后改变采集和打包周期。在轨迹服务开启之前设置采集和打包周期,使用 BTRACE 类中的 setInterval 方法 491 | /// 492 | ///

Usage Example

493 | ///
Swift
494 | /// BTRACEAction.shared.changeGatherAndPackIntervalsAfterStartTrace(self, gatherInterval:5, packInterval:30) 495 | /// 496 | /// 497 | ///
Objective-C
498 | /// [[BTRACEAction shared] changeGatherAndPackIntervalsAfterStartTrace:self gatherInterval:5 packInterval:10]; 499 | /// 500 | /// 501 | ///

Note:

502 | /// 新的采集周期和打包周期仍然需要满足 BTRACE 503 | /// 类中的 setInterval(_:packInterval:) 504 | /// 方法中对采集和打包周期大小的限制条件 505 | /// 506 | /// \param delegate 遵循 ApplicationServiceDelegate 507 | /// 协议的对象。更改周期的结果会通过 onChangeGatherAndPackIntervalsAfterStartTrace(_:errMsg:) 508 | /// 方法进行回调 509 | /// 510 | /// \param gatherInterval 新的采集周期 511 | /// 512 | /// \param packInterval 新的打包周期 513 | /// 514 | /// \returns 本方法为异步方法,执行结果通过 ApplicationServiceDelegate 515 | /// 协议中的 onChangeGatherAndPackIntervalsAfterStartTrace(_:errMsg:) 516 | /// 回调方法获取 517 | - (void)changeGatherAndPackIntervalsAfterStartTrace:(id _Nonnull)delegate gatherInterval:(int32_t)gatherInterval packInterval:(int32_t)packInterval; 518 | 519 | /// 设置定位相关的属性 520 | /// 521 | ///

Usage Example

522 | ///
Swift
523 | /// BTRACEAction.shared.setAttributeOfLocation(1, desiredAccuracy:1, distanceFilter:10) 524 | /// 525 | /// 526 | ///
Objective-C
527 | /// [[BTRACEAction shared] setAttributeOfLocation:1 desiredAccuracy:1 distanceFilter:10]; 528 | /// 529 | /// 530 | ///

Note:

531 | ///
  • 本方法应该在开始轨迹服务之前调用,开启轨迹服务之后调用不会起作用
  • 本方法没有返回值,可以认为设置后一定会成功
  • 需要的定位精度越高、触发定位的距离阈值越低,电量消耗越大。
  • 绝大部分情况下不需要调用此方法
532 | /// \param activityType 定位设备的活动类型 0代表步行,1代表汽车,2代表火车高铁等,3代表其他 533 | /// 534 | /// \param desiredAccuracy 需要的定位精度 0代表最高定位精度,此选项定位最为精确,适用于导航等场景,只有手机插上电源才有效; 1代表米级别的定位精度,是不插电源情况下的最高定位精度;2代表十米级别的定位精度;3代表百米级别的定位精度;4代表千米级别的定位精度;5代表最低定位精度,偏移可能达到几公里以上 535 | /// 536 | /// \param distanceFilter 触发定位的距离阈值, 单位是米 537 | - (void)setAttributeOfLocation:(NSInteger)activityType desiredAccuracy:(NSInteger)desiredAccuracy distanceFilter:(double)distanceFilter; 538 | 539 | /// 查询所有符合条件的entity信息及其实时位置,查询结果会通过 ApplicationEntityDelegate 协议的 onQueryEntityList(_:) 回调方法得到 540 | /// 541 | ///

Usage Example

542 | ///
Swift
543 | /// BTRACEAction.shared.queryEntityList(self, serviceId:100001, entityNames:"entity1,entity2", columnKey:"k1=v1,k2=v2", activeTime:1442824667, returnType:0, pageSize:20, pageIndex:1) 544 | /// 545 | /// 546 | ///
Objective-C
547 | /// [[BTRACEAction shared] queryEntityList:self serviceId:100001 entityNames:@"entity1,entity2" columnKey:@"k1=v1,k2=v2" activeTime:1442824667 returnType:0 pageSize:20 pageIndex:1]; 548 | /// 549 | /// 550 | ///

Note:

551 | ///
  • 由于activeTime, pageSize, pageIndex字段中0没有意义,所以都以0作为默认值
  • String类型的字段使用Optional(String)类型
  • 如果需要查询多个entity,则entity_names字段的格式为:"entity1,entity2,entity3" entity_name之间用英文逗号分开
  • 如果查询时不需要通过自定义属性进行检索,columnKey字段的值为nil;如果要通过多个自定义属性进行检索,columnKey字段的格式为"k1=v1,k2=v2",其中k1和k2必须是事先通过鹰眼webapi的entity/addcolumn接口添加好的可检索的属性字段
552 | /// \param delegate 遵循 ApplicationEntityDelegate 553 | /// 协议的对象 554 | /// 555 | /// \param serviceId 鹰眼轨迹管理台创建鹰眼服务时分配的service_id 556 | /// 557 | /// \param entityNames 要检索的entity_name集合, 如果要同时检索多个entity,写成"entity1,entity2,entity3"的形式,entity之间用英文逗号分开 558 | /// 559 | /// \param columnKey 开发者自定义的entity属性字段 560 | /// 561 | /// \param activeTime 活跃时间(UNIX时间戳),检索在此之间点之后还有轨迹上传的entity。不需要指定时传入0 562 | /// 563 | /// \param returnType 返回结果的类型。0代表返回完整的结果,1代表只返回entity_name字段。默认值为0 564 | /// 565 | /// \param pageSize 分页大小,指定返回的每页中包含几条结果,最大值为1000。不需要指定时传入0,目前会返回100条结果 566 | /// 567 | /// \param pageIndex 分页索引,指定返回全部符合条件的结果的第几页,从1开始。不需要指定时传入0,目前会返回第一页的结果 568 | /// 569 | /// \returns 本方法为异步方法,执行结果通过 ApplicationEntityDelegate 570 | /// 协议中的 onQueryEntityList(_:) 571 | /// 回调方法获取 572 | - (void)queryEntityList:(id _Nonnull)delegate serviceId:(long long)serviceId entityNames:(NSString * _Nullable)entityNames columnKey:(NSString * _Nullable)columnKey activeTime:(NSInteger)activeTime returnType:(NSInteger)returnType pageSize:(NSInteger)pageSize pageIndex:(NSInteger)pageIndex; 573 | 574 | /// 创建一个新的entity(实体对象),结果会通过 ApplicationEntityDelegate 协议的 onAddEntity(_:) 回调方法得到。 575 | /// 576 | ///

Usage Example

577 | ///
Swift
578 | /// BTRACEAction.shared.addEntity(self, serviceId:100001, entityName:"entity1", columnKey:"k1=v1,k2=v2") 579 | /// 580 | /// 581 | ///
Objective-C
582 | /// [[BTRACEAction shared] addEntity:self serviceId:100001 entityName:@"entity1" columnKey:@"k1=v1,k2=v2"]; 583 | /// 584 | /// 585 | ///

Note:

586 | ///
  • entity(实体对象)可以是一个人、一辆车、或任何一个可以被记录轨迹的对象。在查询任何entity的实时位置、历史轨迹之前,都必须先创建这个entity。
  • entity的创建有2种途径,一种是通过调用addEntity 587 | /// 方法主动添加;另一种是在实例化 BTRACE 588 | /// 类时,指定一个名称,调用startTrace后如果网络畅通成功登录到服务端,则会在服务端自动创建一个以这个名称命名的entity,但服务端自动创建的这个entity不包含自定义属性的值。如果需要指定这个entity的自定义属性的值,还需要手动调用 updateEntity(_:serviceId:entityName:columnKey:) 589 | /// 方法,通过其columnKey 590 | /// 字段指定这个entity的自定义属性的值。
  • 通过此方法添加的entity,可以通过iOSSDK,安卓SDK,webapi等方式查询。
  • 如果只是想简单地记录“entity1”的轨迹,那么完全可以以“entity1”作为实体名称实例化BTRACE,然后调用startTrace,利用服务端自动创建的entity,然后在查询实时位置和历史轨迹的时候,指定“entity1”即可。如果只是需要创建一个实体,而暂时不需要记录这个实体的轨迹,可以手动调用本方法,比如创建地理围栏时需要指定的creator 591 | /// 参数和monitor_person 592 | /// 参数。
  • columnKey字段用于指定新创建的实体的自定义属性的值。假设有一些物流配送人员需要管理,可以设置columnKey字段的值为“region=haidian,gender=male”就是指定新创建的这个实体的地区属性为海淀区,性别属性为男。需要注意的是,这里的region和gender属性必须先通过鹰眼webapi的entity/addcolumn接口进行添加。
  • 如果这两个属性是可检索的,以后调用 queryEntityList(_:serviceId:entityNames:columnKey:activeTime:returnType:pageSize:pageIndex:) 593 | /// 方法时,columnKey字段指定为“gender=male”时,这个entity就会被检索出来。如果不是可检索的,只会在 queryEntityList(_:serviceId:entityNames:columnKey:activeTime:returnType:pageSize:pageIndex:) 594 | /// 方法的返回中展示出来而已,并不能用来检索。
595 | /// \param delegate 遵循 ApplicationEntityDelegate 596 | /// 协议的对象 597 | /// 598 | /// \param serviceId 鹰眼轨迹管理台创建鹰眼服务时分配的service_id 599 | /// 600 | /// \param entityName 要添加的实体对象的名称 601 | /// 602 | /// \param columnKey 新添加的这个实体对象的属性及其值 603 | /// 604 | /// \returns 本方法为异步方法,执行结果通过 ApplicationEntityDelegate 605 | /// 协议中的 onAddEntity(_:) 606 | /// 回调方法获取 607 | - (void)addEntity:(id _Nonnull)delegate serviceId:(long long)serviceId entityName:(NSString * _Nonnull)entityName columnKey:(NSString * _Nullable)columnKey; 608 | 609 | /// 更新一个entity(实体对象)的一个或多个属性的值,结果会通过 ApplicationEntityDelegate 协议的 onUpdateEntity(_:) 回调方法得到。 610 | /// 611 | ///

Usage Example

612 | ///
Swift
613 | /// BTRACEAction.shared.updateEntity(self, serviceId:100001, entityName:"entity1", columnKey:"k1=v1,k2=v2") 614 | /// 615 | /// 616 | ///
Objective-C
617 | /// [[BTRACEAction shared] updateEntity:self serviceId:100001 entityName:@"entity1" columnKey:@"k1=v1,k2=v2"]; 618 | /// 619 | /// 620 | ///

Note:

621 | ///
  • entityName字段对应的实体对象,必须是已经存在的。要么是通过开启轨迹服务后服务端自动创建的,要么是通过addEntity方法自己手动创建的。
  • columnKey字段用于指定需要修改的自定义属性的值,仍以addEntity中的物流配送场景为例,如果将这里的columnKey字段设置为“region=chaoyang”就是将这个实体的地区属性修改为朝阳区。这里的region必须是已有的属性字段,要么是在addEntity时创建的属性字段,要么是通过webapi的entity/addcolumn接口添加的属性字段。
622 | /// \param delegate 遵循ApplicationEntityDelegate 623 | /// 协议的对象 624 | /// 625 | /// \param serviceId 鹰眼轨迹管理台创建鹰眼服务时分配的service_id 626 | /// 627 | /// \param entityName 要更新的实体对象的名称 628 | /// 629 | /// \param columnKey 需要更新的这个实体对象的属性及其值 630 | /// 631 | /// \returns 本方法为异步方法,执行结果通过 ApplicationEntityDelegate 632 | /// 协议中的 onUpdateEntity(_:) 633 | /// 回调方法获取 634 | - (void)updateEntity:(id _Nonnull)delegate serviceId:(long long)serviceId entityName:(NSString * _Nonnull)entityName columnKey:(NSString * _Nullable)columnKey; 635 | 636 | /// 查询某个实体对象在指定时间段内的历史轨迹数据,结果会通过 ApplicationTrackDelegate 协议的 onGetHistoryTrack(_:) 回调方法得到。 637 | /// 638 | ///

Usage Example

639 | ///
Swift
640 | /// BTRACEAction.shared.getTrackHistory(self, serviceId:100001, entityName:"entity1", startTime:1442119825, endTime:1442159825, simpleReturn:1, isProcessed:0, pageSize:1000, pageIndex:1) 641 | /// 642 | /// 643 | ///
Objective-C
644 | /// [[BTRACEAction shared] getTrackHistory:self serviceId:100001 entityName:@"entity1" startTime:1442119825 endTime:1442159825 simpleReturn:1 isProcessed:0 pageSize:1000 pageIndex:1]; 645 | /// 646 | /// 647 | ///

Note:

648 | ///
  • endTime不得小于startTime,且endTime最大不得超过startTime+86400
  • 历史轨迹的查询只能指定唯一的entityName,无法同时查询多个entity的历史轨迹。
  • 本方法中无法指定轨迹纠偏选项、排序方式等,建议使用重载过的getTrackHistory(_:serviceId:entityName:startTime:endTime:simpleReturn:isProcessed:processOption:supplementMode:sortType:pageSize:pageIndex:) 649 | /// 方法
650 | /// \param delegate 遵循 ApplicationTrackDelegate 651 | /// 协议的对象 652 | /// 653 | /// \param serviceId 鹰眼轨迹管理台创建鹰眼服务时分配的service_id 654 | /// 655 | /// \param entityName 要查询的实体对象的名称 656 | /// 657 | /// \param startTime 起始时间(UNIX时间戳) 658 | /// 659 | /// \param endTime 结束时间(UNIX时间戳) 660 | /// 661 | /// \param simpleReturn 是否返回精简结果 0代表返回原始结果,1代表返回精简结果,2代表只返回本段轨迹的里程。 662 | /// 663 | /// \param isProcesed 是否返回纠偏后轨迹 0为返回原始轨迹,1为返回纠偏后的轨迹。 664 | /// 665 | /// \param pageSize 返回结果中每页有几条数据。0代表不指定,最大值为5000,默认返回100条。 666 | /// 667 | /// \param pageIndex 返回结果的第几页。0代表不指定,默认返回第1页。 668 | /// 669 | /// \returns 本方法为异步方法,执行结果通过 ApplicationTrackDelegate 670 | /// 协议中的 onGetHistoryTrack(_:) 671 | /// 回调方法获取 672 | - (void)getTrackHistory:(id _Nonnull)delegate serviceId:(long long)serviceId entityName:(NSString * _Nonnull)entityName startTime:(long long)startTime endTime:(long long)endTime simpleReturn:(NSInteger)simpleReturn isProcessed:(NSInteger)isProcessed pageSize:(NSInteger)pageSize pageIndex:(NSInteger)pageIndex; 673 | 674 | /// 重载的历史轨迹查询方法,可以指定轨迹纠偏的选项、里程补偿方式、结果排序方式。结果会通过 ApplicationTrackDelegate 协议的 onGetHistoryTrack(_:) 回调方法得到。 675 | /// 676 | ///

Usage Example

677 | ///
Swift
678 | /// BTRACEAction.shared.getTrackHistory(self, serviceId:100001, entityName:"entity1", startTime:1442119825, endTime:1442159825, simpleReturn:1, isProcessed:0, processOption: "need_denoise=1,need_vacuate=1,need_mapmatch=0", supplementMode: "driving", sortType: 0, pageSize:1000, pageIndex:1) 679 | /// 680 | /// 681 | ///
Objective-C
682 | /// [[BTRACEAction shared] getTrackHistory:self serviceId:100001 entityName:@"entity1" startTime:1442119825 endTime:1442159825 simpleReturn:1 isProcessed:0 processOption: @"need_denoise=1,need_vacuate=1,need_mapmatch=0" supplementMode: @"driving" sortType: 0 pageSize:1000 pageIndex:1]; 683 | /// 684 | /// 685 | ///

轨迹纠偏选项的说明

686 | /// 轨迹纠偏选项的设置,仅在isProcessed=1时生效,通过为纠偏选项中各项赋1(需要)或0(不需要)来设置是否需要该项数据处理,支持的纠偏选项如下: 687 | /// 688 | ///
  • need_denoise:去噪,默认为1
  • need_vacuate:抽稀,默认为1
  • need_mapmatch:绑路(仅适用于驾车),之前未开通绑路的service,默认值为0;之前已开通绑路的service,默认值为1 689 | /// 多选项设置时用英文逗号","分割,若不设置某选项则按默认值处理。 690 | /// 如果想设置本段轨迹去燥、抽稀但是不绑路,可以指定本字段的值为:"need_denoise=1,need_vacuate=1,need_mapmatch=0"
691 | ///

里程补偿方式的说明

692 | /// 在里程计算时,两个轨迹点定位时间间隔5分钟以上,被认为是中断。 693 | /// 中断轨迹提供以下5种里程估算方式: 694 | /// 695 | ///
  • no_supplement不补充,中断两点间距离不记入里程;
  • straight:使用直线距离补充;
  • driving:使用最短驾车路线距离补充;
  • riding:使用最短骑行路线距离补充;
  • walking:使用最短步行路线距离补充; 696 | /// 如果传入nil代表不进行里程补充。
697 | ///

Note:

698 | ///
  • endTime不得小于startTime,且endTime最大不得超过startTime+86400
  • 历史轨迹的查询只能指定唯一的entityName,无法同时查询多个entity的历史轨迹。
  • processOption 699 | /// 轨迹纠偏选项只有当isProcessed 700 | /// 字段的值为1时才有效
  • supplementMode 701 | /// 里程补充方式的生效不依赖于isProcessed 702 | /// 字段的值,如果要求返回全部结果,而且需要里程补充,那么返回的历史轨迹结果中,只有distance 703 | /// 字段的值是进行里程补充过的,不会添加具体的轨迹点到历史轨迹中去。
704 | /// \param delegate 遵循 ApplicationTrackDelegate 705 | /// 协议的对象 706 | /// 707 | /// \param serviceId 鹰眼轨迹管理台创建鹰眼服务时分配的service_id 708 | /// 709 | /// \param entityName 要查询的实体对象的名称 710 | /// 711 | /// \param startTime 起始时间(UNIX时间戳) 712 | /// 713 | /// \param endTime 结束时间(UNIX时间戳) 714 | /// 715 | /// \param simpleReturn 是否返回精简结果 0代表返回原始结果,1代表返回精简结果,2代表只返回本段轨迹的里程。 716 | /// 717 | /// \param isProcesed 是否返回纠偏后轨迹 0为返回原始轨迹,1为返回纠偏后的轨迹。 718 | /// 719 | /// \param processOption 轨迹纠偏选项。 720 | /// 721 | /// \param supplementMode 里程补偿方式。 722 | /// 723 | /// \param sortType 结果排序方式。0代表返回的轨迹点按loc_time从大到小排序,1代表从小到大排序。 724 | /// 725 | /// \param pageSize 返回结果中每页有几条数据。0代表不指定,最大值为5000,默认返回100条。 726 | /// 727 | /// \param pageIndex 返回结果的第几页。0代表不指定,默认返回第1页。 728 | /// 729 | /// \returns 本方法为异步方法,执行结果通过 ApplicationTrackDelegate 730 | /// 协议中的 onGetHistoryTrack(_:) 731 | /// 回调方法获取 732 | - (void)getTrackHistory:(id _Nonnull)delegate serviceId:(long long)serviceId entityName:(NSString * _Nonnull)entityName startTime:(long long)startTime endTime:(long long)endTime simpleReturn:(NSInteger)simpleReturn isProcessed:(NSInteger)isProcessed processOption:(NSString * _Nullable)processOption supplementMode:(NSString * _Nullable)supplementMode sortType:(NSInteger)sortType pageSize:(NSInteger)pageSize pageIndex:(NSInteger)pageIndex; 733 | 734 | /// 查询指定时间段内的里程(单位:米)。结果会通过 ApplicationTrackDelegate 协议的 onQueryDistance(_:) 回调方法得到。 735 | /// 736 | ///

Usage Example

737 | ///
Swift
738 | /// BTRACEAction.shared.queryDistance(self, serviceId:100001, entityName:"entity1", isProcessed:0, processOption: "need_denoise=1,need_vacuate=1,need_mapmatch=0", supplementMode: "driving", startTime:1442119825, endTime:1442159825) 739 | /// 740 | /// 741 | ///
Objective-C
742 | /// [[BTRACEAction shared] queryDistance:self serviceId:100001 entityName:@"entity1" isProcessed:1 processOption:@"need_denoise=1,need_vacuate=1,need_mapmatch=0" supplementMode:@"driving" startTime:1442119825 endTime:1442159825]; 743 | /// 744 | /// 745 | ///

processOption参数的说明

746 | /// 轨迹纠偏选项的设置,仅在is_processed=1时生效,通过为纠偏选项中各项赋1(需要)或0(不需要)来设置是否需要该项数据处理,支持的纠偏选项如下: 747 | /// 748 | ///
  • need_denoise:去噪,默认为1
  • need_vacuate:抽稀,默认为1
  • need_mapmatch:绑路(仅适用于驾车),之前未开通绑路的service,默认值为0;之前已开通绑路的service,默认值为1 749 | /// 多选项设置时用英文逗号","分割,若不设置某选项则按默认值处理。 750 | /// 如果想设置本段轨迹去燥、抽稀但是不绑路,可以指定本字段的值为:"need_denoise=1,need_vacuate=1,need_mapmatch=0"
751 | ///

supplementMode参数的说明

752 | /// 在里程计算时,两个轨迹点定位时间间隔5分钟以上,被认为是中断。 753 | /// 中断轨迹提供以下5种里程估算方式: 754 | /// 755 | ///
  • no_supplement不补充,中断两点间距离不记入里程;
  • straight:使用直线距离补充;
  • driving:使用最短驾车路线距离补充;
  • riding:使用最短骑行路线距离补充;
  • walking:使用最短步行路线距离补充; 756 | /// 如果传入nil代表不进行里程补充。
757 | ///

Note:

758 | ///
  • endTime不得小于startTime,且endTime最大不得超过startTime+86400
  • 本方法实际是 getTrackHistory(_:serviceId:entityName:startTime:endTime:simpleReturn:isProcessed:processOption:supplementMode:sortType:pageSize:pageIndex:) 759 | /// 方法中simpleReturn=2时的快捷方法,都是查询一段时间短内轨迹的里程
760 | /// \param delegate 遵循 ApplicationTrackDelegate 761 | /// 协议的对象 762 | /// 763 | /// \param serviceId 鹰眼轨迹管理台创建鹰眼服务时分配的service_id 764 | /// 765 | /// \param entityName 要查询的实体对象的名称 766 | /// 767 | /// \param isProcesed 返回的里程是否考虑了轨迹的纠偏 0为原始轨迹的里程,1为纠偏后的轨迹的里程 768 | /// 769 | /// \param processOption 返回的里程是否考虑了轨迹的纠偏 770 | /// 771 | /// \param supplementMode 对里程进行补偿的方式 772 | /// 773 | /// \param startTime 起始时间(UNIX时间戳) 774 | /// 775 | /// \param endTime 结束时间(UNIX时间戳) 776 | /// 777 | /// \returns 本方法为异步方法,执行结果通过 ApplicationTrackDelegate 778 | /// 协议中的 onQueryDistance(_:) 779 | /// 回调方法获取 780 | - (void)queryDistance:(id _Nonnull)delegate serviceId:(long long)serviceId entityName:(NSString * _Nonnull)entityName isProcessed:(NSInteger)isProcessed processOption:(NSString * _Nullable)processOption supplementMode:(NSString * _Nullable)supplementMode startTime:(long long)startTime endTime:(long long)endTime; 781 | 782 | /// 创建一个圆形的服务端地理围栏。结果会通过 ApplicationFenceDelegate 协议的 onCreateFence(_:) 回调方法得到。 783 | /// 784 | ///

Usage Example

785 | ///
Swift
786 | /// BTRACEAction.shared.createCircularFence(self, serviceId: 100001, fenceName: "fenceA", fenceDesc: "围栏A", creator: "entity1", monitoredPersons: "entity2", observers: "entity3", validTimes: "0000,2359", validCycle: 4, validDate: nil, validDays:nil, coordType: 3, center: "116.4321,38.76623", radius: 50.5, alarmCondition: 3, precision: 100) 787 | /// 788 | /// 789 | ///
Objective-C
790 | /// [[BTRACEAction shared] createCircularFence:self serviceId:100001 fenceName:@"fenceA" fenceDesc:@"围栏A" creator:@"entity1" monitoredPersons:@"entity2" observers:@"entity3" validTimes:@"0000,2359" validCycle:4 validDate:nil validDays:nil coordType:3 center:@"116.4321,38.76623" radius:50.5 alarmCondition:3 precision:100]; 791 | /// 792 | /// 793 | ///

Note:

794 | /// 通过本方法创建的服务端地理围栏,当此围栏的被监控对象触发了围栏报警时,报警信息会通过ApplicationServiceDelegate 795 | /// 协议的onPushTrace(_:errMsg:) 796 | /// 方法回调。\See 797 | /// 798 | /// 799 | /// onCreateFence(_:) 800 | /// 801 | /// 802 | /// \param delegate 遵循 ApplicationFenceDelegate 803 | /// 协议的对象 804 | /// 805 | /// \param serviceId 鹰眼轨迹管理台创建鹰眼服务时分配的service_id 806 | /// 807 | /// \param fenceName 地理围栏的名称 808 | /// 809 | /// \param fenceDesc 地理围栏的描述 810 | /// 811 | /// \param creator 地理围栏的创建者,创建者必须是一个已经存在的entity(实体对象) 812 | /// 813 | /// \param monitoredPersons 地理围栏的监控对象,监控对象必须是一个已经存在的entity(实体对象),只有这个监控对象的轨迹才会触发这个地理围栏的报警 814 | /// 815 | /// \param observers 地理围栏的观察者,观察者必须是一个已经存在的entity(实体对象),且只有这个观察者才会收到该地理围栏的报警推送 816 | /// 817 | /// \param validTimes 围栏生效时间列表; 格式为"string,string;string,string;…"; 一天中的几点几分到几点几分生效。至少含有一段生效时间,多个时间段使用分号”;”分隔。比如:“0820,0930;1030,1130” 818 | /// 819 | /// \param validCycle 围栏生效周期; int; 标识validTimes是否周期性生效,可以使用如下数值 1:不重复 2:工作日循环 3:周末循环 4:每天循环 5:自定义 当为5时,需要定义valid_days,标识在周几生效。当validCycle为1时,必须设置validDate字段,当validCycle为5时,必须设置validDays字段。 820 | /// 821 | /// \param validDate 围栏生效日期; 当valid_cycle为1时必须设置此字段的值,例如:20150908。 822 | /// 823 | /// \param validDays 围栏生效日期列表; 格式为"int,int..."; 1到7,分别表示周一到周日,当valid_cycle为5时必须设置此字段的值。 824 | /// 825 | /// \param coordType 圆形地理围栏圆心的坐标类型; 坐标类型定义如下:1:GPS经纬度 2:国测局经纬度 3:百度经纬度 826 | /// 827 | /// \param center 圆形地理围栏圆心的经纬度; 格式为:“经度,纬度”; 示例:"116.4321,38.76623" 828 | /// 829 | /// \param radius 圆形地理围栏的半径; 单位:米。 830 | /// 831 | /// \param alarmCondition 地理围栏报警条件; 1:进入时触发提醒 2:离开时触发提醒 3:进入离开均触发提醒 832 | /// 833 | /// \param precision 地理围栏去燥的精度; 当采集到的轨迹点的定位精度超过此阈值时,将不会触发围栏. 如果需要所有的轨迹点,无论定位精度是多少都去触发围栏计算, 设置为0(可能造成围栏误报警) 834 | /// 835 | /// \returns 本方法为异步方法,执行结果通过 ApplicationFenceDelegate 836 | /// 协议中的 onCreateFence(_:) 837 | /// 回调方法获取 838 | - (void)createCircularFence:(id _Nonnull)delegate serviceId:(long long)serviceId fenceName:(NSString * _Nonnull)fenceName fenceDesc:(NSString * _Nullable)fenceDesc creator:(NSString * _Nonnull)creator monitoredPersons:(NSString * _Nonnull)monitoredPersons observers:(NSString * _Nonnull)observers validTimes:(NSString * _Nonnull)validTimes validCycle:(NSInteger)validCycle validDate:(NSString * _Nullable)validDate validDays:(NSString * _Nullable)validDays coordType:(NSInteger)coordType center:(NSString * _Nonnull)center radius:(double)radius alarmCondition:(NSInteger)alarmCondition precision:(NSInteger)precision; 839 | 840 | /// 创建一个多边形的服务端地理围栏。结果会通过 ApplicationFenceDelegate 协议的 onCreateFence(_:) 回调方法得到。 841 | /// 842 | ///

Usage Example

843 | ///
Swift
844 | /// BTRACEAction.shared.createVertexesFence:self, serviceId:100001, fenceName:"fenceB", fenceDesc:"围栏B", creator:"entity1", monitoredPersons:"entity2", observers:"entity3", validTimes:"0000,2359", validCycle:4, validDate:nil, validDays:nil, coordType:3, vertexes:"119.32,40.38;119.33,40.38;119.33,40.37", alarmCondition:3, precision:100) 845 | /// 846 | /// 847 | ///
Objective-C
848 | /// [[BTRACEAction shared] createVertexesFence:self serviceId:100001 fenceName:@"fenceB" fenceDesc:@"围栏B" creator:@"entity1" monitoredPersons:@"entity2" observers:@"entity3" validTimes:@"0000,2359" validCycle:4 validDate:nil validDays:nil coordType:3 vertexes:@"119.32,40.38;119.33,40.38;119.33,40.37" alarmCondition:3 precision:100]; 849 | /// 850 | /// 851 | ///

Note:

852 | /// 通过本方法创建的服务端地理围栏,当此围栏的被监控对象触发了围栏报警时,报警信息会通过ApplicationServiceDelegate 853 | /// 协议的onPushTrace(_:errMsg:) 854 | /// 方法回调。 855 | /// 856 | /// \param delegate 遵循 ApplicationFenceDelegate 857 | /// 协议的对象 858 | /// 859 | /// \param serviceId 鹰眼轨迹管理台创建鹰眼服务时分配的service_id 860 | /// 861 | /// \param fenceName 地理围栏的名称 862 | /// 863 | /// \param fenceDesc 地理围栏的描述 864 | /// 865 | /// \param creator 地理围栏的创建者,创建者必须是一个已经存在的entity(实体对象) 866 | /// 867 | /// \param monitoredPersons 地理围栏的监控对象,监控对象必须是一个已经存在的entity(实体对象),只有这个监控对象的轨迹才会触发这个地理围栏的报警 868 | /// 869 | /// \param observers 地理围栏的观察者,观察者必须是一个已经存在的entity(实体对象),且只有这个观察者才会收到该地理围栏的报警推送 870 | /// 871 | /// \param validTimes 围栏生效时间列表; 格式为"string,string;string,string;…"; 一天中的几点几分到几点几分生效。至少含有一段生效时间,多个时间段使用分号”;”分隔。比如:“0820,0930;1030,1130” 872 | /// 873 | /// \param validCycle 围栏生效周期; int; 标识validTimes是否周期性生效,可以使用如下数值 1:不重复 2:工作日循环 3:周末循环 4:每天循环 5:自定义 当为5时,需要定义valid_days,标识在周几生效。当validCycle为1时,必须设置validDate字段,当validCycle为5时,必须设置validDays字段。 874 | /// 875 | /// \param validDate 围栏生效日期; 当valid_cycle为1时必须设置此字段的值,例如:20150908。 876 | /// 877 | /// \param validDays 围栏生效日期列表; 格式为"int,int..."; 1到7,分别表示周一到周日,当valid_cycle为5时必须设置此字段的值。 878 | /// 879 | /// \param coordType 多边形地理围栏的顶点坐标的坐标类型; 坐标类型定义如下:1:GPS经纬度 2:国测局经纬度 3:百度经纬度 880 | /// 881 | /// \param vertexes 多边形地理围栏的顶点坐标列表(顶点为多边形顺时针或逆时针顺序,格式: "经度,纬度;....") 882 | /// 883 | /// \param alarmCondition 地理围栏报警条件; 1:进入时触发提醒 2:离开时触发提醒 3:进入离开均触发提醒 884 | /// 885 | /// \param precision 地理围栏去燥的精度; 当采集到的轨迹点的定位精度超过此阈值时,将不会触发围栏. 如果需要所有的轨迹点,无论定位精度是多少都去触发围栏计算, 设置为0(可能造成围栏误报警) 886 | /// 887 | /// \returns 本方法为异步方法,执行结果通过 ApplicationFenceDelegate 888 | /// 协议中的 onCreateFence(_:) 889 | /// 回调方法获取 890 | - (void)createVertexesFence:(id _Nonnull)delegate serviceId:(long long)serviceId fenceName:(NSString * _Nonnull)fenceName fenceDesc:(NSString * _Nullable)fenceDesc creator:(NSString * _Nonnull)creator monitoredPersons:(NSString * _Nonnull)monitoredPersons observers:(NSString * _Nonnull)observers validTimes:(NSString * _Nonnull)validTimes validCycle:(NSInteger)validCycle validDate:(NSString * _Nullable)validDate validDays:(NSString * _Nullable)validDays coordType:(NSInteger)coordType vertexes:(NSString * _Nonnull)vertexes alarmCondition:(NSInteger)alarmCondition precision:(NSInteger)precision; 891 | 892 | /// 创建一个客户端地理围栏。结果会通过 ApplicationFenceDelegate 协议的 onCreateLocalFence(_:) 回调方法得到。 893 | /// 894 | ///

Usage Example

895 | ///
Swift
896 | /// let center = CLLocationCoordinate2D(latitude: 40.0, longitude: 116.0) 897 | /// let localFence = BLocalFence(name: "fenceA", center: center, coordType: 3, radius: 10, accuracy: 10) 898 | /// BTRACEAction.shared.createLocalFence(self, fence: localFence) 899 | /// 900 | /// 901 | ///
Objective-C
902 | /// CLLocationCoordinate2D center = CLLocationCoordinate2DMake(40.0, 116.0); 903 | /// BLocalFence* localFence = [[BLocalFence alloc] initWithName:@"fenceB" center:center coordType:3 radius:50 accuracy: 50]; 904 | /// [[BTRACEAction shared] createLocalFence:self fence:localFence]; 905 | /// 906 | /// 907 | ///

Note:

908 | /// 通过本方法创建的客户端地理围栏,当本设备触发了围栏时,报警信息会通过ApplicationServiceDelegate 909 | /// 协议的onPushTrace(_:errMsg:) 910 | /// 方法回调。 911 | /// 912 | /// \param delegate 遵循 ApplicationFenceDelegate 913 | /// 协议的对象 914 | /// 915 | /// \param fence 客户端地理围栏的对象 916 | /// 917 | /// \returns 本方法为异步方法,执行结果通过 ApplicationFenceDelegate 918 | /// 协议中的 onCreateLocalFence(_:) 919 | /// 回调方法获取 920 | - (void)createLocalFence:(id _Nonnull)delegate fence:(BLocalFence * _Nonnull)fence; 921 | 922 | /// 删除一个客户端地理围栏,结果会通过 ApplicationFenceDelegate 协议的 onDeleteLocalFence(_:) 回调方法得到。 923 | /// 924 | ///

Usage Example

925 | ///
Swift
926 | /// BTRACEAction.shared.deleteLocalFence(self, fenceId: [1,2]) 927 | /// 928 | /// 929 | ///
Objective-C
930 | /// NSArray* fenceIds = [[NSArray alloc] init]; 931 | /// [[BTRACEAction shared] deleteLocalFence:self fenceId:fenceIds]; 932 | /// 933 | /// 934 | /// \param delegate 遵循 ApplicationFenceDelegate 935 | /// 协议的对象 936 | /// 937 | /// \param fenceId 要删除的客户端地理围栏id的数组, 数组中有哪些fenceId就删除对应的本地围栏,若想删除所有的本地围栏,传入空数组即可 938 | /// 939 | /// \returns 本方法为异步方法,执行结果通过 ApplicationFenceDelegate 940 | /// 协议中的 onDeleteLocalFence(_:) 941 | /// 回调方法获取 942 | - (void)deleteLocalFence:(id _Nonnull)delegate fenceId:(NSArray * _Nonnull)fenceId; 943 | 944 | /// 更新服务端地理围栏。结果会通过 ApplicationFenceDelegate 协议的 onUpdateFence(_:) 回调方法得到。 945 | /// 946 | ///

Usage Example

947 | ///
Swift
948 | /// BTRACEAction.shared.updateFence(self, serviceId:100001, fenceId:1, fenceName:"fenceC", fenceDesc:"围栏C", monitoredPersons:"entity3", observers:"entity3", validTimes:"0800,2200", validCycle:4, validDate:nil, validDays:nil, shape:1, coordType:3, center:"119.33,40.37", radius:15.5, vertexes:nil, alarmCondition:3, precision:10) 949 | /// 950 | /// 951 | ///
Objective-C
952 | /// [[BTRACEAction shared] updateFence:self serviceId:100001 fenceId:1 fenceName:@"fenceC" fenceDesc:@"围栏C" monitoredPersons:@"entity3" observers:@"entity3" validTimes:@"0800,2200" validCycle:4 validDate:nil validDays:nil shape:1 coordType:3 center:@"119.33,40.37" radius:15.5 vertexes:nil alarmCondition:3 precision:10]; 953 | /// 954 | /// 955 | /// \param delegate 遵循 ApplicationFenceDelegate 956 | /// 协议的对象 957 | /// 958 | /// \param serviceId 鹰眼轨迹管理台创建鹰眼服务时分配的service_id 959 | /// 960 | /// \param fenceName 修改后的地理围栏的名称,不需要修改传nil 961 | /// 962 | /// \param fenceDesc 修改后的地理围栏的描述,不需要修改传nil 963 | /// 964 | /// \param monitoredPersons 修改后的地理围栏的监控对象不需要修改传nil,监控对象必须是一个已经存在的entity(实体对象),只有这个监控对象的轨迹才会触发这个地理围栏的报警 965 | /// 966 | /// \param observers 修改后的地理围栏的观察者,不需要修改传nil,观察者必须是一个已经存在的entity(实体对象),且只有这个观察者才会收到该地理围栏的报警推送 967 | /// 968 | /// \param validTimes 修改后的围栏生效时间列表,不需要修改传nil; 格式为"string,string;string,string;…"; 一天中的几点几分到几点几分生效。至少含有一段生效时间,多个时间段使用分号”;”分隔。比如:“0820,0930;1030,1130” 969 | /// 970 | /// \param validCycle 修改后的围栏生效周期; int; 标识validTimes是否周期性生效,可以使用如下数值 1:不重复 2:工作日循环 3:周末循环 4:每天循环 5:自定义 当为5时,需要定义valid_days,标识在周几生效。当validCycle为1时,必须设置validDate字段,当validCycle为5时,必须设置validDays字段。 971 | /// 972 | /// \param validDate 修改后的围栏生效日期; 当valid_cycle为1时必须设置此字段的值,例如:20150908。 973 | /// 974 | /// \param validDays 修改后的围栏生效日期列表; 格式为"int,int..."; 1到7,分别表示周一到周日,当valid_cycle为5时必须设置此字段的值。 975 | /// 976 | /// \param shape 修改后的地理围栏类型。 1代表将围栏更新为圆形, 2代表将围栏更新为多边形 977 | /// 978 | /// \param coordType 修改后的地理围栏的坐标类型; 坐标类型定义如下:1:GPS经纬度 2:国测局经纬度 3:百度经纬度 979 | /// 980 | /// \param center 只有shape=1时才有效,代表修改后的地理围栏为圆形,地理围栏圆心的经纬度; 格式为:“经度,纬度”; 示例:"116.4321,38.76623" 981 | /// 982 | /// \param radius 只有shape=1时才有效,代表修改后的地理围栏为圆形,地理围栏的半径; 单位:米。 983 | /// 984 | /// \param vertexes 只有shape=2时才有效,代表修改后的地理围栏为多边形,地理围栏的顶点坐标列表(顶点为多边形顺时针或逆时针顺序,格式: "经度,纬度;....") 985 | /// 986 | /// \param alarmCondition 修改后的地理围栏报警条件; 1:进入时触发提醒 2:离开时触发提醒 3:进入离开均触发提醒 987 | /// 988 | /// \param precision 修改后的地理围栏去燥的精度; 当采集到的轨迹点的定位精度超过此阈值时,将不会触发围栏. 如果需要所有的轨迹点,无论定位精度是多少都去触发围栏计算, 设置为0(可能造成围栏误报警) 989 | /// 990 | /// \returns 本方法为异步方法,执行结果通过 ApplicationFenceDelegate 991 | /// 协议中的 onUpdateFence(_:) 992 | /// 回调方法获取 993 | - (void)updateFence:(id _Nonnull)delegate serviceId:(long long)serviceId fenceId:(long long)fenceId fenceName:(NSString * _Nullable)fenceName fenceDesc:(NSString * _Nullable)fenceDesc monitoredPersons:(NSString * _Nullable)monitoredPersons observers:(NSString * _Nullable)observers validTimes:(NSString * _Nullable)validTimes validCycle:(NSInteger)validCycle validDate:(NSString * _Nullable)validDate validDays:(NSString * _Nullable)validDays shape:(NSInteger)shape coordType:(NSInteger)coordType center:(NSString * _Nullable)center radius:(double)radius vertexes:(NSString * _Nullable)vertexes alarmCondition:(NSInteger)alarmCondition precision:(NSInteger)precision; 994 | 995 | /// 删除指定的服务端地理围栏。结果会通过 ApplicationFenceDelegate 协议的 onDeleteFence(_:) 回调方法得到。 996 | /// 997 | ///

Usage Example

998 | ///
Swift
999 | /// BTRACEAction.shared.deleteFence(self, serviceId:100001, fenceId:1) 1000 | /// 1001 | /// 1002 | ///
Objective-C
1003 | /// [[BTRACEAction shared] deleteFence:self serviceId:100001 fenceId:1]; 1004 | /// 1005 | /// 1006 | /// \param delegate 遵循 ApplicationFenceDelegate 1007 | /// 协议的对象 1008 | /// 1009 | /// \param serviceId 鹰眼轨迹管理台创建鹰眼服务时分配的service_id 1010 | /// 1011 | /// \param fenceId 创建服务端地理围栏时分配的围栏唯一标识符 1012 | /// 1013 | /// \returns 本方法为异步方法,执行结果通过 ApplicationFenceDelegate 1014 | /// 协议中的 onDeleteFence(_:) 1015 | /// 回调方法获取 1016 | - (void)deleteFence:(id _Nonnull)delegate serviceId:(long long)serviceId fenceId:(long long)fenceId; 1017 | 1018 | /// 查询已创建的服务端地理围栏。结果会通过 ApplicationFenceDelegate 协议的 onFenceList(_:) 回调方法得到。 1019 | /// 1020 | ///

Usage Example

1021 | ///
Swift
1022 | /// BTRACEAction.shared.queryFenceList(self, serviceId:100001 creator:nil fenceIds:"1,2") 1023 | /// 1024 | /// 1025 | ///
Objective-C
1026 | /// [[BTRACEAction shared] queryFenceList:self serviceId:100001 creator:@"entityA" fenceIds:nil]; 1027 | /// 1028 | /// 1029 | ///

Require

1030 | ///
  • 查询时creator和fenceIds至少要指定一个
  • 有fenceIds列表时按id列表查找,若没有指定id列表,则按创建者查找
  • fenceIds列表中最多可以有10项
1031 | /// \param delegate 遵循 ApplicationFenceDelegate 1032 | /// 协议的对象 1033 | /// 1034 | /// \param serviceId 鹰眼轨迹管理台创建鹰眼服务时分配的service_id 1035 | /// 1036 | /// \param creator 围栏的创建者 1037 | /// 1038 | /// \param fenceIds 围栏的id列表,格式为"int,int,int" 1039 | /// 1040 | /// \returns 本方法为异步方法,执行结果通过 ApplicationFenceDelegate 1041 | /// 协议中的 onFenceList(_:) 1042 | /// 回调方法获取 1043 | - (void)queryFenceList:(id _Nonnull)delegate serviceId:(long long)serviceId creator:(NSString * _Nullable)creator fenceIds:(NSString * _Nullable)fenceIds; 1044 | 1045 | /// 查询某个服务端地理围栏的某个监控对象,在指定时间短内的历史报警信息。查询结果会通过 ApplicationFenceDelegate 协议的 onQueryFenceHistoryAlarm(_:) 回调方法得到。 1046 | /// 1047 | ///

Usage Example

1048 | ///
Swift
1049 | /// BTRACEAction.shared.queryFenceHistoryAlarm(self, serviceId:100001, fenceId:1, monitoredPersons:"entityA", beginTime:1471239000, endTime:1471249000) 1050 | /// 1051 | /// 1052 | ///
Objective-C
1053 | /// [[BTRACEAction shared] queryFenceHistoryAlarm:self serviceId:100001 fenceId:1 monitoredPersons:@"entityA" beginTime:1471239000 endTime:1471249000]; 1054 | /// 1055 | /// 1056 | /// \param delegate 遵循 ApplicationFenceDelegate 1057 | /// 协议的对象 1058 | /// 1059 | /// \param serviceId 鹰眼轨迹管理台创建鹰眼服务时分配的service_id 1060 | /// 1061 | /// \param fenceId 创建服务端地理围栏时分配的唯一标识符 1062 | /// 1063 | /// \param monitoredPersons 指定地理围栏监控的实体对象的名称列表,格式为“entityA,entityB”,最多设置5个实体对象,如果希望查询所有被监控对象的历史报警,传入nil 1064 | /// 1065 | /// \param beginTime 开始时间(UNIX时间戳) 1066 | /// 1067 | /// \param endTime 结束时间(UNIX时间戳) 1068 | /// 1069 | /// \returns 本方法为异步方法,执行结果通过 ApplicationFenceDelegate 1070 | /// 协议中的 onQueryFenceHistoryAlarm(_:) 1071 | /// 回调方法获取 1072 | - (void)queryFenceHistoryAlarm:(id _Nonnull)delegate serviceId:(long long)serviceId fenceId:(long long)fenceId monitoredPersons:(NSString * _Nullable)monitoredPersons beginTime:(long long)beginTime endTime:(long long)endTime; 1073 | 1074 | /// 查询指定的服务端地理围栏下指定的监控对象当前在围栏内还是围栏外。查询结果会通过 ApplicationFenceDelegate 协议的 onQueryFenceStatus(_:) 回调方法得到。 1075 | /// 1076 | ///

Usage Example

1077 | ///
Swift
1078 | /// BTRACEAction.shared.queryFenceStatus(self, serviceId:100001, fenceId:1, monitoredPersons:"entityA,entityB") 1079 | /// 1080 | /// 1081 | ///
Objective-C
1082 | /// [[BTRACEAction shared] queryFenceStatus:self serviceId:100001 fenceId:1 monitoredPersons:@"entityA,entityB"]; 1083 | /// 1084 | /// 1085 | /// \param delegate 遵循 ApplicationFenceDelegate 1086 | /// 协议的对象 1087 | /// 1088 | /// \param serviceId 鹰眼轨迹管理台创建鹰眼服务时分配的service_id 1089 | /// 1090 | /// \param fenceId 创建服务端地理围栏时分配的唯一标识符 1091 | /// 1092 | /// \param monitoredPersons 指定需要查询的被监控实体对象的名称列表,格式为“entityA,entityB”,最多设置5个实体对象,需要查询此围栏下所有被监控对象的状态时,传入nil 1093 | /// 1094 | /// \returns 本方法为异步方法,执行结果通过 ApplicationFenceDelegate 1095 | /// 协议中的 onQueryFenceStatus(_:) 1096 | /// 回调方法获取 1097 | - (void)queryFenceStatus:(id _Nonnull)delegate serviceId:(long long)serviceId fenceId:(long long)fenceId monitoredPersons:(NSString * _Nullable)monitoredPersons; 1098 | 1099 | /// 假定被监控对象的位置信息,查询此时被监控对象在指定服务端围栏的内部还是外部。查询结果会通过 ApplicationFenceDelegate 协议的 onQueryFenceStatus(_:) 回调方法得到。 1100 | /// 1101 | ///

Usage Example

1102 | ///
Swift
1103 | /// BTRACEAction.shared.queryFenceStatus(self, serviceId:100001, fenceId:1, monitoredPersons:"entityA,entityB") 1104 | /// 1105 | /// 1106 | ///
Objective-C
1107 | /// [[BTRACEAction shared] queryFenceStatusByLocation:self serviceId:100001 fenceId:1 monitoredPersons:@"entityA,entityB" locations:@"116.314461,40.047682,3;116.4321,38.76623,3"]; 1108 | /// 1109 | /// 1110 | ///

Require

1111 | ///
  • locations中可以指定多个位置坐标,分别与monitoredPersons 1112 | /// 中指定的被监控实体对象的名称列表对应
  • locations中坐标之间用英文分号";"分隔,每个坐标内部包含经度、纬度、坐标类型,他们之间用英文逗号','分隔。
  • locations中的坐标类型定义如下:1代表WGS84经纬度 2代表国测局经纬度 3代表百度经纬度
1113 | /// \param delegate 遵循ApplicationFenceDelegate 1114 | /// 协议的对象 1115 | /// 1116 | /// \param serviceId 鹰眼轨迹管理台创建鹰眼服务时分配的service_id 1117 | /// 1118 | /// \param fenceId 创建服务端地理围栏时分配的唯一标识符 1119 | /// 1120 | /// \param monitoredPersons 指定需要查询的被监控实体对象的名称列表,格式为“entityA,entityB”,最多设置5个实体对象 1121 | /// 1122 | /// \param locations 被监控实体对象对应的位置信息,格式为“entityA的经度,entityA的纬度,坐标类型;entityB的经度,entityB的纬度,坐标类型” 1123 | /// 1124 | /// \returns 本方法为异步方法,执行结果通过 ApplicationFenceDelegate 1125 | /// 协议中的 onQueryFenceStatus(_:) 1126 | /// 回调方法获取 1127 | - (void)queryFenceStatusByLocation:(id _Nonnull)delegate serviceId:(long long)serviceId fenceId:(long long)fenceId monitoredPersons:(NSString * _Nullable)monitoredPersons locations:(NSString * _Nullable)locations; 1128 | - (nonnull instancetype)init OBJC_DESIGNATED_INITIALIZER; 1129 | @end 1130 | 1131 | 1132 | @interface NSData (SWIFT_EXTENSION(BaiduTraceSDK)) 1133 | @end 1134 | 1135 | 1136 | @interface NSNull (SWIFT_EXTENSION(BaiduTraceSDK)) 1137 | @end 1138 | 1139 | 1140 | @interface NSNumber (SWIFT_EXTENSION(BaiduTraceSDK)) 1141 | @end 1142 | 1143 | 1144 | @interface NSURL (SWIFT_EXTENSION(BaiduTraceSDK)) 1145 | @end 1146 | 1147 | 1148 | @interface NSURLComponents (SWIFT_EXTENSION(BaiduTraceSDK)) 1149 | @end 1150 | 1151 | 1152 | @interface NSURLRequest (SWIFT_EXTENSION(BaiduTraceSDK)) 1153 | @end 1154 | 1155 | 1156 | @interface NSURLRequest (SWIFT_EXTENSION(BaiduTraceSDK)) 1157 | @end 1158 | 1159 | 1160 | @interface NSURLSession (SWIFT_EXTENSION(BaiduTraceSDK)) 1161 | @end 1162 | 1163 | #pragma clang diagnostic pop 1164 | --------------------------------------------------------------------------------