From 0805d1c07cb93aa3ae56421a9ddd70946cb6e841 Mon Sep 17 00:00:00 2001 From: XHY Date: Tue, 22 Nov 2022 13:02:48 +0800 Subject: [PATCH] =?UTF-8?q?=E8=85=BE=E8=AE=AF=E5=AE=9A=E4=BD=8D=E6=A8=A1?= =?UTF-8?q?=E5=9D=97=E5=A2=9E=E5=8A=A0=20=E7=9B=91=E5=90=AC=E4=BD=8D?= =?UTF-8?q?=E7=BD=AE=E5=8F=98=E5=8C=96=EF=BC=8C=E6=B8=85=E9=99=A4=E7=9B=91?= =?UTF-8?q?=E5=90=AC=20=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../TencentLocation/TencentLocation.vue | 166 +++++++++++------- .../utssdk/app-ios/index.uts | 6 +- .../utssdk/app-ios/index.uts | 81 +++++++-- 3 files changed, 170 insertions(+), 83 deletions(-) diff --git a/pages/SDKIntegration/TencentLocation/TencentLocation.vue b/pages/SDKIntegration/TencentLocation/TencentLocation.vue index 67423e9..474f730 100644 --- a/pages/SDKIntegration/TencentLocation/TencentLocation.vue +++ b/pages/SDKIntegration/TencentLocation/TencentLocation.vue @@ -1,69 +1,99 @@ - - - - - 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 1151d9e..a1d2abe 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 837e8de..4fba134 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 -- GitLab