diff --git a/pages/SDKIntegration/TencentLocation/TencentLocation.vue b/pages/SDKIntegration/TencentLocation/TencentLocation.vue
index 67423e9e0b965b8bb83de8d66b57bb4f3273e1af..474f730770461b070e3b3e0fcc7ca5e7b6614f2b 100644
--- a/pages/SDKIntegration/TencentLocation/TencentLocation.vue
+++ b/pages/SDKIntegration/TencentLocation/TencentLocation.vue
@@ -1,69 +1,99 @@
-
-
-
-
-
- 1. 腾讯定位sdk需在腾讯地图官网申请key。https://lbs.qq.com/mobile/androidMapSDK/
- developerGuide/getKey。
-
-
- 2. 将key配置在uts插件uts-tencentgeolocation/utssdk/app-android/AndroidManifest.xml中。
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/uni_modules/uts-screenshot-listener/utssdk/app-ios/index.uts b/uni_modules/uts-screenshot-listener/utssdk/app-ios/index.uts
index 1151d9e520c6da0284812eac14f2147aa243919f..a1d2abec3d34e4040b42552341901dea3863fb2c 100644
--- a/uni_modules/uts-screenshot-listener/utssdk/app-ios/index.uts
+++ b/uni_modules/uts-screenshot-listener/utssdk/app-ios/index.uts
@@ -20,17 +20,15 @@ class CaptureScreenTool {
// 捕获截屏回调的方法
// target-action 的方法前需要添加 @objc 前缀
@objc static userDidTakeScreenshot() {
- const obj = new UTSJSONObject()
// 回调
- this.listener?.(obj)
+ this.listener?.({})
}
// 移除监听事件
static removeListen(callback?: UTSCallback) {
this.listener = null
NotificationCenter.default.removeObserver(this)
- const obj = new UTSJSONObject()
- callback?.(obj)
+ callback?.({})
}
}
diff --git a/uni_modules/uts-tencentgeolocation/utssdk/app-ios/index.uts b/uni_modules/uts-tencentgeolocation/utssdk/app-ios/index.uts
index 837e8de65c6684d779185cfa652d479cbed1d73f..4fba1348e63803e7e58015a474643563362ef269 100644
--- a/uni_modules/uts-tencentgeolocation/utssdk/app-ios/index.uts
+++ b/uni_modules/uts-tencentgeolocation/utssdk/app-ios/index.uts
@@ -1,5 +1,5 @@
import { CLLocationManager, CLAuthorizationStatus } from "CoreLocation"
-import { TencentLBSLocationManager, TencentLBSLocation, Error, TencentLBSRequestLevel} from "TencentLBS"
+import { TencentLBSLocationManager, TencentLBSLocation, Error, TencentLBSRequestLevel, TencentLBSLocationManagerDelegate} from "TencentLBS"
import Bundle from "Foundation"
@@ -25,13 +25,15 @@ type LocationResponse = {
/**
* 定位 LBSLocation 类,封装定位相关方法
*/
-class LBSLocation {
+class LBSLocation implements TencentLBSLocationManagerDelegate {
// 定义 locationManager 属性,类型为 TencentLBSLocationManager
- static locationManager: TencentLBSLocationManager
+ locationManager: TencentLBSLocationManager
+
+ locationOptions?: LocationOptions
// 初始化 locationManager 方法
- static configLocationManager(): boolean {
+ configLocationManager(): boolean {
if (this.locationManager == null) {
// 从 info.plist 中读取 apiKey
@@ -48,13 +50,14 @@ class LBSLocation {
this.locationManager = new TencentLBSLocationManager()
// 设置 apiKey (因为 apiKey 是 any?类型,需要转成 string 类型赋值)
this.locationManager.apiKey = apiKey! as string;
+ this.locationManager.delegate = this
}
return true
}
// 请求定位权限
- static requestPremission() {
+ requestPremission() {
if (this.configLocationManager()) {
const status = CLLocationManager.authorizationStatus()
// 如果未获取过定位权限,则发起权限请求
@@ -64,8 +67,8 @@ class LBSLocation {
}
}
- // 获取位置信息
- static getLocation(locationOptions: LocationOptions): boolean {
+ // 获取单次位置信息
+ getLocation(locationOptions: LocationOptions): boolean {
// 初始化 locationManager
if (!this.configLocationManager()) {
@@ -95,18 +98,74 @@ class LBSLocation {
return true
}
+
+ // 监听位置变化
+ watchPosition(locationOptions: LocationOptions) {
+ // 初始化 locationManager
+ if (!this.configLocationManager()) {
+ return
+ }
+ if (locationOptions.geocode) {
+ this.locationManager.requestLevel = TencentLBSRequestLevel.name
+ } else {
+ this.locationManager.requestLevel = TencentLBSRequestLevel.geo
+ }
+ this.locationOptions = locationOptions
+ this.locationManager.startUpdatingLocation()
+ }
+
+ // 清除监听
+ clearWatch() {
+ // 初始化 locationManager
+ if (!this.configLocationManager()) {
+ return
+ }
+ this.locationManager.stopUpdatingLocation()
+ }
+
+ // 实现定位出错的 delegate 方法
+ tencentLBSLocationManager(manager: TencentLBSLocationManager, error: Error) {
+ this.locationOptions?.fail(error.localizedDescription)
+ }
+
+ // 实现位置更新的 delegate 方法
+ tencentLBSLocationManager(manager: TencentLBSLocationManager, @argumentLabel("didUpdate") location: TencentLBSLocation) {
+ let response = new LocationResponse();
+ response.name = location.name;
+ response.address = location.address;
+ response.latitude = Number(location.location.coordinate.latitude);
+ response.longitude = Number(location.location.coordinate.longitude);
+ this.locationOptions?.success(response)
+ }
+
}
+const LBSLocationTool: LBSLocation = new LBSLocation()
+
/**
- * 导出请求权限方法
+ * 请求定位权限方法
*/
export function requestPremission() {
- LBSLocation.requestPremission()
+ LBSLocationTool.requestPremission()
}
/*
- * 导出请求位置信息方法
+ * 获取位置信息方法(单次定位)
*/
export function getLocation(locationOptions: LocationOptions): boolean {
- return LBSLocation.getLocation(locationOptions)
+ return LBSLocationTool.getLocation(locationOptions)
+}
+
+/**
+ * 持续监听位置变化
+ */
+export function watchPosition(locationOptions: LocationOptions) {
+ LBSLocationTool.watchPosition(locationOptions)
+}
+
+/**
+ * 关闭监听位置变化
+ */
+export function clearWatch() {
+ LBSLocationTool.clearWatch()
}
\ No newline at end of file