提交 8094ab2f 编写于 作者: DCloud_iOS_XHY's avatar DCloud_iOS_XHY

提交 iOS 端 TencentLBS 示例

上级 84c71663
......@@ -49,6 +49,12 @@
title:'执行结果:' + addressDesc,
icon:'none'
});
},
fail:function(msg) {
uni.showToast({
title: msg,
icon:"none"
})
}
})
......
......@@ -12,7 +12,7 @@ export default function getBatteryInfo(options: GetBatteryInfoOptions) {
const res = {
errMsg: "getBatteryInfo:ok",
level: UIDevice.current.batteryLevel * 100,
level: Number(UIDevice.current.batteryLevel * 100),
isCharging: UIDevice.current.batteryState == UIDevice.BatteryState.charging,
};
if (options.success != null) {
......
//
// TencentLBS.h
// TencentLBS
//
// Created by mirantslu on 16/4/19.
// Copyright © 2016年 Tencent. All rights reserved.
//
#import <UIKit/UIKit.h>
//! Project version number for TencentLBS.
FOUNDATION_EXPORT double TencentLBSVersionNumber;
//! Project version string for TencentLBS.
FOUNDATION_EXPORT const unsigned char TencentLBSVersionString[];
// In this header, you should import all the public headers of your framework using statements like #import <TencentLBS/PublicHeader.h>
#import <TencentLBS/TencentLBSLocation.h>
#import <TencentLBS/TencentLBSLocationManager.h>
#import <TencentLBS/TencentLBSLocationUtils.h>
//
// TencentLBSLocation.h
// TencentLBS
//
// Created by mirantslu on 16/4/19.
// Copyright © 2016年 Tencent. All rights reserved.
//
#import <Foundation/Foundation.h>
#import <CoreLocation/CoreLocation.h>
NS_ASSUME_NONNULL_BEGIN
#define TENCENTLBS_DEBUG 0
typedef NS_ENUM(NSInteger, TencentLBSDRProvider) {
TencentLBSDRProviderError = -2, //!< 错误,可能未开启dr
TencentLBSDRProviderUnkown = -1, //!< 定位结果来源未知
TencentLBSDRProviderFusion = 0, //!< 定位结果来源融合的结果
TencentLBSDRProviderGPS = 1, //!< 定位结果来源GPS
TencentLBSDRProviderNetWork = 2, //!< 定位结果来源网络
};
@interface TencentLBSPoi : NSObject<NSSecureCoding, NSCopying>
@property (nonatomic, copy) NSString *uid; //!< 当前POI的uid
@property (nonatomic, copy) NSString *name; //!< 当前POI的名称
@property (nonatomic, copy) NSString *address; //!< 当前POI的地址
@property (nonatomic, copy) NSString *catalog; //!< 当前POI的类别
@property (nonatomic, assign) double longitude; //!< 当前POI的经度
@property (nonatomic, assign) double latitude; //!< 当前POI的纬度
@property (nonatomic, assign) double distance; //!< 当前POI与当前位置的距离
@end
@interface TencentLBSLocation : NSObject<NSSecureCoding, NSCopying>
/**
* 返回当前位置的CLLocation信息
*/
@property (nonatomic, strong) CLLocation *location;
/**
* 返回当前位置的行政区划, 0-表示中国大陆、港、澳, 1-表示其他
*/
@property (nonatomic, assign) NSInteger areaStat;
/**
* 返回室内定位楼宇Id
*/
@property (nonatomic, copy, nullable) NSString *buildingId;
/**
* 返回室内定位楼层
*/
@property (nonatomic, copy, nullable) NSString *buildingFloor;
/**
* 返回室内定位类型,0表示普通定位结果,1表示蓝牙室内定位结果
*/
@property (nonatomic, assign) NSInteger indoorLocationType;
/**
*
*/
@property (nonatomic, assign) TencentLBSDRProvider drProvider;
/**
* 返回当前位置的名称,
* 仅当TencentLBSRequestLevel为TencentLBSRequestLevelName或TencentLBSRequestLevelAdminName或TencentLBSRequestLevelPoi有返回值,否则为空
*/
@property (nonatomic, copy, nullable) NSString *name;
/**
* 返回当前位置的地址
* 仅当TencentLBSRequestLevel为TencentLBSRequestLevelName或TencentLBSRequestLevelAdminName有返回值,否则为空
*/
@property (nonatomic, copy, nullable) NSString *address;
/**
* 返回国家编码,例如中国为156
* <b>注意:该接口涉及到WebService API,请参考https://lbs.qq.com/service/webService/webServiceGuide/webServiceOverview中的配额限制说明,
* 并将申请的有效key通过TencentLBSLocationManager的- (void)setDataWithValue: forKey:方法设置,其中key为固定值@"ReGeoCodingnKey",例如[tencentLocationManager setDataWithValue:@"您申请的key(务必正确)" forKey:@"ReGeoCodingnKey"];,否则将返回默认值0</b>
*/
@property (nonatomic, assign) NSInteger nationCode;
/**
* 返回当前位置的城市编码
* 仅当TencentLBSRequestLevel为TencentLBSRequestLevelAdminName或TencentLBSRequestLevelPoi有返回值,否则为空
*/
@property (nonatomic, copy, nullable) NSString *code;
/**
* 返回当前位置的国家
* 仅当TencentLBSRequestLevel为TencentLBSRequestLevelAdminName或TencentLBSRequestLevelPoi有返回值,否则为空
*/
@property (nonatomic, copy, nullable) NSString *nation;
/**
* 返回当前位置的省份
* 仅当TencentLBSRequestLevel为TencentLBSRequestLevelAdminName或TencentLBSRequestLevelPoi有返回值,否则为空
*/
@property (nonatomic, copy, nullable) NSString *province;
/**
* 返回当前位置的城市固话编码.
* 仅当TencentLBSRequestLevel为TencentLBSRequestLevelAdminName或TencentLBSRequestLevelPoi有返回值,否则为空
*/
@property (nonatomic, copy, nullable) NSString *cityPhoneCode;
/**
* 返回当前位置的城市
* 仅当TencentLBSRequestLevel为TencentLBSRequestLevelAdminName或TencentLBSRequestLevelPoi有返回值,否则为空
*/
@property (nonatomic, copy, nullable) NSString *city;
/**
* 返回当前位置的区县
* 仅当TencentLBSRequestLevel为TencentLBSRequestLevelAdminName或TencentLBSRequestLevelPoi有返回值,否则为空
*/
@property (nonatomic, copy, nullable) NSString *district;
/**
* 返回当前位置的乡镇
* 仅当TencentLBSRequestLevel为TencentLBSRequestLevelAdminName或TencentLBSRequestLevelPoi有返回值,否则为空
*/
@property (nonatomic, copy, nullable) NSString *town;
/**
* 返回当前位置的村
* 仅当TencentLBSRequestLevel为TencentLBSRequestLevelAdminName或TencentLBSRequestLevelPoi有返回值,否则为空
*/
@property (nonatomic, copy, nullable) NSString *village;
/**
* 返回当前位置的街道
* 仅当TencentLBSRequestLevel为TencentLBSRequestLevelAdminName或TencentLBSRequestLevelPoi有返回值,否则为空
*/
@property (nonatomic, copy, nullable) NSString *street;
/**
* 返回当前位置的街道编码
* 仅当TencentLBSRequestLevel为TencentLBSRequestLevelAdminName或TencentLBSRequestLevelPoi有返回值,否则为空
*/
@property (nonatomic, copy, nullable) NSString *street_no;
/**
* 返回当前位置周围的POI
* 仅当TencentLBSRequestLevel为TencentLBSRequestLevelPoi有返回值,否则为空
*/
@property (nonatomic, strong, nullable) NSArray<TencentLBSPoi*> *poiList;
/**
* 返回两个位置之间的横向距离
* @param location
*/
- (double)distanceFromLocation:(const TencentLBSLocation *)location;
// 测试使用
#if TENCENTLBS_DEBUG
@property (nonatomic, copy, nullable) NSString *halleyTime;
#endif
@end
NS_ASSUME_NONNULL_END
//
// TencentLBSLocationManager.h
// TencentLBS
//
// Created by mirantslu on 16/4/19.
// Copyright © 2016年 Tencent. All rights reserved.
//
#import <Foundation/Foundation.h>
#import <CoreLocation/CoreLocation.h>
#import "TencentLBSLocation.h"
NS_ASSUME_NONNULL_BEGIN
typedef NS_ENUM(NSUInteger, TencentLBSRequestLevel) {
TencentLBSRequestLevelGeo = 0,
TencentLBSRequestLevelName = 1,
TencentLBSRequestLevelAdminName = 3,
TencentLBSRequestLevelPoi = 4,
};
typedef NS_ENUM(NSUInteger, TencentLBSLocationCoordinateType) {
TencentLBSLocationCoordinateTypeGCJ02 = 0, //!< 火星坐标,即国测局坐标
TencentLBSLocationCoordinateTypeWGS84 = 1, //!< 地球坐标,注:如果是海外,无论设置的是火星坐标还是地球坐标,返回的都是地球坐标
};
typedef NS_ENUM(NSUInteger, TencentLBSLocationError) {
TencentLBSLocationErrorUnknown = 0, //!< 错误码,表示目前位置未知,但是会一直尝试获取
TencentLBSLocationErrorDenied = 1, //!< 错误码,表示定位权限被禁止
TencentLBSLocationErrorNetwork = 2, //!< 错误码,表示网络错误
TencentLBSLocationErrorHeadingFailure = 3, //!< 错误码,表示朝向无法确认
TencentLBSLocationErrorOther = 4, //!< 错误码,表示未知错误
};
typedef NS_ENUM(NSInteger, TencentLBSDRStartCode) {
TencentLBSDRStartCodeSuccess = 0, //!< 启动成功
TencentLBSDRStartCodeNotSupport = -1, //!< 传感器有缺失或没有GPS芯片
TencentLBSDRStartCodeHasStarted = -2, //!< 已经启动
TencentLBSDRStartCodeSensorFailed = -3, //!< 传感器启动失败
TencentLBSDRStartCodeGpsFailed = -4, //!< GPS启动失败
TencentLBSDRStartCodePermissionFailed = -5, //!< 没有位置权限
TencentLBSDRStartCodeUnkown = -6, //!< 未知
};
typedef NS_ENUM(NSInteger, TencentLBSDRStartMotionType) {
TencentLBSDRStartMotionTypeWalk = 2, //!< 步行
TencentLBSDRStartMotionTypeBike = 3, //!< 骑行
};
typedef NS_ENUM(NSInteger, TencentLBSAccuracyAuthorization) {
// This application has the user's permission to receive accurate location information.
TencentLBSAccuracyAuthorizationFullAccuracy,
// The user has chosen to grant this application access to location information with reduced accuracy.
// Region monitoring and beacon ranging are not available to the application. Other CoreLocation APIs
// are available with reduced accuracy.
// Location estimates will have a horizontalAccuracy on the order of about 5km. To achieve the
// reduction in accuracy, CoreLocation will snap location estimates to a nearby point which represents
// the region the device is in. Furthermore, CoreLocation will reduce the rate at which location
// estimates are produced. Applications should be prepared to receive locations that are up to 20
// minutes old.
TencentLBSAccuracyAuthorizationReducedAccuracy,
};
/**
* TencentLBSLocatingCompletionBlock 单次定位返回Block
*
* @param location 位置信息
* @param error 错误信息 参考 TencentLBSLocationError
*/
typedef void (^TencentLBSLocatingCompletionBlock)(TencentLBSLocation * _Nullable location, NSError * _Nullable error);
@protocol TencentLBSLocationManagerDelegate;
@interface TencentLBSLocationManager : NSObject
/**
* 当前位置管理器定位精度的授权状态
*/
@property(nonatomic, readonly)TencentLBSAccuracyAuthorization accuracyAuthorization;
/**
* 当前位置管理器定位权限的授权状态
*/
@property(nonatomic, readonly)CLAuthorizationStatus authorizationStatus;
/**
* API Key, 在使用定位SDK服务之前需要先绑定key。
*/
@property (nonatomic, copy) NSString* apiKey;
/**
* 实现了 TencentLBSLocationManagerDelegate 协议的类指针。
*/
@property (nonatomic, weak) id<TencentLBSLocationManagerDelegate> delegate;
/**
* 设定定位的最小更新距离。默认为 kCLDistanceFilterNone。
*/
@property (nonatomic, assign) CLLocationDistance distanceFilter;
/**
* 设定定位精度。默认为 kCLLocationAccuracyBest 。
*/
@property (nonatomic, assign) CLLocationAccuracy desiredAccuracy;
/**
* 指定定位是否会被系统自动暂停。默认为 YES 。
*/
@property (nonatomic, assign) BOOL pausesLocationUpdatesAutomatically;
/**
* 是否允许后台定位。默认为 NO。
* iOS 9.0 以上用户需要设置该选项并且在info.list里面Background Modes 中的 Location updates 处于选中状态才可以使用后台定位权限。iOS 9.0之前可以直接申请总是使用的权限来获得后台定位。
*
* 设置为 YES 的时候必须保证 Background Modes 中的 Location updates 处于选中状态,否则会抛出异常。
*/
@property (nonatomic, assign) BOOL allowsBackgroundLocationUpdates;
/**
* 用户的活动类型
*
* 设置用户的活动类型。默认值为 CLActivityTypeOther
*/
@property (nonatomic, assign) CLActivityType activityType;
/**
* 设置当朝向改变时,每隔多少度调用一次
* 只有当设备方向的改变值超过该属性值时才激发delegate的方法。
*/
@property(nonatomic, assign) CLLocationDegrees headingFilter;
/**
* 设置设备当前的朝向
*/
@property(nonatomic, assign) CLDeviceOrientation headingOrientation;
/**
* 连续定位的逆地理信息请求的Level。默认为TencentLBSRequestLevelGeo
*/
@property (nonatomic, assign) TencentLBSRequestLevel requestLevel;
/**
* 返回的TencentLBSLocation的location字段的坐标类型。默认为TencentLBSLocationCoordinateTypeGCJ02。
*
* 在一次定位过程中,只允许设置一次,不允许重复设置
*/
@property (nonatomic, assign) TencentLBSLocationCoordinateType coordinateType;
/**
* 指定POI的更新间隔。 默认是10s
*/
@property(nonatomic, assign) NSInteger poiUpdateInterval;
#pragma mark -
/**
* accuracyAuthorization
*
* Discussion:
* Return the current TencentLBSAccuracyAuthorization of the calling application.
*/
+ (TencentLBSAccuracyAuthorization)accuracyAuthorization;
/**
* 设置用户是否同意隐私协议政策
* <p>调用其他接口前必须首先调用此接口进行用户是否同意隐私政策的设置,传入YES后才能正常使用定位功能,否则TencentLBSLocationManager初始化不成功,返回nil,定位功能均无法使用</p>
* @param isAgree 是否同意隐私政策
*/
+ (void)setUserAgreePrivacy:(BOOL) isAgree;
/**
* 获取用户是否同意隐私政策协议
* <p>设置用户隐私后,可通过该接口判断用户隐私状态</p>
* @return isAgreePrivacy 是否同意隐私政策
*/
+ (BOOL)getUserAgreePrivacy;
#pragma mark -
- (void)requestWhenInUseAuthorization;
- (void)requestAlwaysAuthorization;
/**
* 当前属于模糊定位状态时,通过该接口请求暂时的完全定位精度的权限
* @param purposeKey 需要在info.plist中配置NSLocationTemporaryUsageDescriptionDictionary key值和对应的申请该权限的描述理由
* @param completion 在弹框让用户选择后的用户的反馈,如果用户授予该权限,block中的参数为nil,如果未授予,block中的参数将为PurposeKey对于的key的描述(如PurposeKey=TemporaryPurposKey_1)
*/
- (void)requestTemporaryFullAccuracyAuthorizationWithPurposeKey:(NSString *)purposeKey
completion:(void (^)(NSError *))completion;
/**
* 当前属于模糊定位状态时,通过该接口请求暂时的完全定位精度的权限
* @param purposeKey 需要在info.plist中配置NSLocationTemporaryUsageDescriptionDictionary key值和对应的申请该权限的描述理由
*/
- (void)requestTemporaryFullAccuracyAuthorizationWithPurposeKey:(NSString *)purposeKey;
#pragma mark -
/**
* 获取定位SDK的版本
*/
+(NSString *)getLBSSDKVersion;
/**
* 获取定位SDK的构建日期
*/
+(NSString *)getLBSSDKbuild;
#pragma mark -
/**
* 向SDK内部设置数据,以满足定制的需求
* @param value
* @param key
*/
- (void)setDataWithValue:(NSString *)value forKey:(NSString *)key;
/**
* 单次定位
*
* 该方法为下面方法的一层封装。
* level默认是TencentLBSRequestLevelPoi
* timeout默认是10s
*/
- (BOOL)requestLocationWithCompletionBlock:(TencentLBSLocatingCompletionBlock)completionBlock;
/**
* 单次定位
*
* 注意:不能连续调用该接口,需在上一次返回之后才能再次发起调用。该接口兼容iOS 7.0及以上,因iOS 9.0系统提供单次定位能力,故在9.0以上会调用系统单次定位接口,9.0之前SDK完成封装。可以通过调用cancelRequestLocation来取消。
*
* @param level 可以根据此参数来对应的获取POI信息
* @param timeout 表示获取POI的超时时间。
* @param completionBlock 单次定位完成后的Block
*/
- (BOOL)requestLocationWithRequestLevel:(TencentLBSRequestLevel)level
locationTimeout:(NSTimeInterval)timeout
completionBlock:(TencentLBSLocatingCompletionBlock)completionBlock;
/**
* 取消单次定位
**/
- (void)cancelRequestLocation;
/**
* 开始连续定位
*/
- (void)startUpdatingLocation;
/**
* 停止连续定位
*/
- (void)stopUpdatingLocation;
/**
* 开启更新定位朝向
*/
- (void)startUpdatingHeading;
/**
* 结束更新定位朝向
*/
- (void)stopUpdatingHeading;
/**
* 停止展示定位朝向校准提示
*/
- (void)dismissHeadingCalibrationDisplay;
#pragma mark - PDR 对外接口
/**
* 主动获取DR实时融合位置,调用startDrEngine:成功后才可能有值,业务可根据自己的频率主动获取
* @return DR融合后的定位结果
*/
-(TencentLBSLocation *)getPosition;
/**
* 启动DR引擎。引擎会自动获取传感器和GPS数据,并进行位置计算。
* 启动后DR引擎会主动开启CLLocationManager startUpdatingLocation。
*
* 注意:请确保调用之前已获取位置权限(使用期间或者始终允许)
*
* @param type 运动类型 目前支持,参考TencentLBSDRStartMotionType
* @return 返回码,参考TencentLBSDRStartCode
*/
-(TencentLBSDRStartCode)startDrEngine:(TencentLBSDRStartMotionType)type;
/**
* 停止DR引擎。内部有极短时间延迟,若在此期间调用TencentLBSLocationManager startDrEngine:可能导致启动不成功。
*/
-(void)terminateDrEngine;
/**
* 是否支持DR引擎
* @return
*/
-(BOOL)isSupport;
#pragma mark - test used
// 测试使用
#if TENCENTLBS_DEBUG
+ (void)upLoadData;
+ (NSData *)getLocationLog;
+ (void)newLocationLog;
#endif
@end
#pragma mark - TencentLBSLocationManagerDelegate
/**
* TencentLBSLocationManagerDelegate
* 定义了发生错误时的错误回调方法,连续定位的回调方法等。
*/
@protocol TencentLBSLocationManagerDelegate <NSObject>
@optional
/**
* 当定位发生错误时,会调用代理的此方法
*
* @param manager 定位 TencentLBSLocationManager 类
* @param error 返回的错误,参考 TencentLBSLocationError
*/
- (void)tencentLBSLocationManager:(TencentLBSLocationManager *)manager
didFailWithError:(NSError *)error;
/**
* 连续定位回调函数
*
* @param manager 定位 TencentLBSLocationManager 类
* @param location 定位结果
*/
- (void)tencentLBSLocationManager:(TencentLBSLocationManager *)manager
didUpdateLocation:(TencentLBSLocation *)location;
/**
* 定位权限状态改变时回调函数
* @deprecated 在iOS 14及以上废弃,由tencentLBSDidChangeAuthorization:代替
* @param manager 定位 TencentLBSLocationManager 类
* @param status 定位权限状态
*/
- (void)tencentLBSLocationManager:(TencentLBSLocationManager *)manager
didChangeAuthorizationStatus:(CLAuthorizationStatus)status;
/**
* 定位权限状态改变时回调函数
* @param manager 定位 TencentLBSLocationManager 类,由此访问authorizationStatus,accuracyAuthorization
*/
- (void)tencentLBSDidChangeAuthorization:(TencentLBSLocationManager *)manager;
/**
* 定位朝向改变时回调函数
*
* @param manager 定位 TencentLBSLocationManager 类
* @param newHeading 新的定位朝向
*/
- (void)tencentLBSLocationManager:(TencentLBSLocationManager *)manager
didUpdateHeading:(CLHeading *)newHeading;
/**
* 是否展示定位朝向校准提示的回调函数
*
* @param manager 定位 TencentLBSLocationManager 类
*/
- (BOOL)tencentLBSLocationManagerShouldDisplayHeadingCalibration:(TencentLBSLocationManager *)manager;
/**
* 只是内部调试使用,外部不应实现该接口
*/
- (void)tencentLBSLocationManager:(TencentLBSLocationManager *)manager didThrowLocation:(TencentLBSLocation *)location;
@end
NS_ASSUME_NONNULL_END
//
// TencentLBSLocationUtils.h
// TencentLBS
//
// Created by mirantslu on 16/8/11.
// Copyright © 2016年 Tencent. All rights reserved.
//
#import <Foundation/Foundation.h>
#import <CoreLocation/CoreLocation.h>
@class TencentLBSLocation;
NS_ASSUME_NONNULL_BEGIN
@interface TencentLBSLocationUtils : NSObject
/**
* 计算两个坐标点的距离
*/
+ (double)distanceBetweenTwoCoordinate2D:(const CLLocationCoordinate2D *)coordinate coordinateTwo:(const CLLocationCoordinate2D *)coordinate2;
/**
* 计算两个location的距离
*/
+ (double)distanceBetweenTwoCLLocations:(const CLLocation *)location locationTwo:(const CLLocation *)location2;
/**
* 计算两个TencentLBSLocation的距离
*/
+ (double)distanceBetweenTwoTencentLBSLocations:(const TencentLBSLocation *)location locationTwo:(const TencentLBSLocation *)location2;
/**
* 判断经纬度是否在国内
*
*/
+ (BOOL) isInRegionWithLatitude:(double)latitude longitude:(double)longitude;
/**
* wgs84坐标转成gcj02坐标
*/
+ (CLLocationCoordinate2D)WGS84TOGCJ02:(CLLocationCoordinate2D)coordinate;
@end
@interface TencentLBSServiceManager : NSObject
/**
* 设置ID,如QQ号,微信号或是其他的登录账号,可用在发布前联调使用
*/
@property (atomic, copy) NSString *deviceID;
+ (instancetype)sharedInsance;
@end
NS_ASSUME_NONNULL_END
framework module TencentLBS {
umbrella header "TencentLBS.h"
export *
module * { export * }
}
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>files</key>
<dict>
<key>Headers/TencentLBS.h</key>
<data>
hPC0/pGd4xrqNOXCT59Bc4EZx1o=
</data>
<key>Headers/TencentLBSLocation.h</key>
<data>
NTNAtRb6zd+vtrq8nFcrm/TvTno=
</data>
<key>Headers/TencentLBSLocationManager.h</key>
<data>
CqufUOM9qpXc8PkBQcTH7nFlxHU=
</data>
<key>Headers/TencentLBSLocationUtils.h</key>
<data>
ctiCEOKB25KPpldhCiCitDpWjsc=
</data>
<key>Info.plist</key>
<data>
dF6t7k2l2ACuPcw4w8e+8pX3Ds8=
</data>
<key>Modules/module.modulemap</key>
<data>
jS4bVEIZ8y6+mkDDypFhD0RkQVg=
</data>
</dict>
<key>files2</key>
<dict>
<key>Headers/TencentLBS.h</key>
<dict>
<key>hash</key>
<data>
hPC0/pGd4xrqNOXCT59Bc4EZx1o=
</data>
<key>hash2</key>
<data>
rXSLg9Gmqf/qi8hc0spd2V99ElDyGiIgDgvN30bahIQ=
</data>
</dict>
<key>Headers/TencentLBSLocation.h</key>
<dict>
<key>hash</key>
<data>
NTNAtRb6zd+vtrq8nFcrm/TvTno=
</data>
<key>hash2</key>
<data>
LmWBqRV/iCuLqRmuUPDGqTOz3n2XBrAIRkPpulu9Dms=
</data>
</dict>
<key>Headers/TencentLBSLocationManager.h</key>
<dict>
<key>hash</key>
<data>
CqufUOM9qpXc8PkBQcTH7nFlxHU=
</data>
<key>hash2</key>
<data>
ozYu6o4odbCMlj5n6GijSLmHlND06j8bgS/wHNmwwkI=
</data>
</dict>
<key>Headers/TencentLBSLocationUtils.h</key>
<dict>
<key>hash</key>
<data>
ctiCEOKB25KPpldhCiCitDpWjsc=
</data>
<key>hash2</key>
<data>
clmnufMVF2VLg4uOOY70pixlfbrZK20rr/iOxOF4+E4=
</data>
</dict>
<key>Modules/module.modulemap</key>
<dict>
<key>hash</key>
<data>
jS4bVEIZ8y6+mkDDypFhD0RkQVg=
</data>
<key>hash2</key>
<data>
j/3Yn2sASML4eiVUc877N1Qdw84cRUiapBx3Gc88OUI=
</data>
</dict>
</dict>
<key>rules</key>
<dict>
<key>^.*</key>
<true/>
<key>^.*\.lproj/</key>
<dict>
<key>optional</key>
<true/>
<key>weight</key>
<real>1000</real>
</dict>
<key>^.*\.lproj/locversion.plist$</key>
<dict>
<key>omit</key>
<true/>
<key>weight</key>
<real>1100</real>
</dict>
<key>^Base\.lproj/</key>
<dict>
<key>weight</key>
<real>1010</real>
</dict>
<key>^version.plist$</key>
<true/>
</dict>
<key>rules2</key>
<dict>
<key>.*\.dSYM($|/)</key>
<dict>
<key>weight</key>
<real>11</real>
</dict>
<key>^(.*/)?\.DS_Store$</key>
<dict>
<key>omit</key>
<true/>
<key>weight</key>
<real>2000</real>
</dict>
<key>^.*</key>
<true/>
<key>^.*\.lproj/</key>
<dict>
<key>optional</key>
<true/>
<key>weight</key>
<real>1000</real>
</dict>
<key>^.*\.lproj/locversion.plist$</key>
<dict>
<key>omit</key>
<true/>
<key>weight</key>
<real>1100</real>
</dict>
<key>^Base\.lproj/</key>
<dict>
<key>weight</key>
<real>1010</real>
</dict>
<key>^Info\.plist$</key>
<dict>
<key>omit</key>
<true/>
<key>weight</key>
<real>20</real>
</dict>
<key>^PkgInfo$</key>
<dict>
<key>omit</key>
<true/>
<key>weight</key>
<real>20</real>
</dict>
<key>^embedded\.provisionprofile$</key>
<dict>
<key>weight</key>
<real>20</real>
</dict>
<key>^version\.plist$</key>
<dict>
<key>weight</key>
<real>20</real>
</dict>
</dict>
</dict>
</plist>
import { CLLocationManager, CLAuthorizationStatus } from "CoreLocation"
import { TencentLBSLocationManager, TencentLBSLocation, Error, TencentLBSRequestLevel} from "TencentLBS"
import Bundle from "Foundation"
/**
* 定位请求参数封装
*/
type LocationOptions = {
geocode: boolean,
success: (response: LocationResponse) => void,
fail: (msg: string) => void
};
/**
* 定位返回结果封装
*/
type LocationResponse = {
name: string,
address: string,
latitude: number,
longitude: number
}
class LBSLocation {
// 定义 locationManager 属性,类型为 TencentLBSLocationManager
static locationManager: TencentLBSLocationManager
// 初始化 locationManager 方法
static configLocationManager(): boolean {
if (this.locationManager == null) {
// 从 info.plist 中读取 apiKey
const apiKey = Bundle.main.infoDictionary?.["TencentLBSAPIKey"]
// infoDictionary 获取的值类型为 any?
if (apiKey == null) {
// 如果 apiKey 为 null 返回 false
return false
}
// 调用API前需要设置同意用户隐私协议
TencentLBSLocationManager.setUserAgreePrivacy(true)
// 初始化 locationManager 实例对象
this.locationManager = new TencentLBSLocationManager()
// 设置 apiKey (因为 apiKey 是 any?类型,需要转成 string 类型赋值)
this.locationManager.apiKey = apiKey! as string;
// this.locationManager.apiKey = "LZTBZ-77PCJ-HJAFN-KWXJ2-H357V-DJBK4"
this.locationManager.allowsBackgroundLocationUpdates = true
}
return true
}
static requestPremission() {
this.configLocationManager()
const status = CLLocationManager.authorizationStatus()
if (status == CLAuthorizationStatus.notDetermined) {
this.locationManager.requestWhenInUseAuthorization()
}
}
static getLocation(locationOptions: LocationOptions): boolean {
// 初始化 locationManager
if (!this.configLocationManager()) {
// 初始化失败返回 false
return false
}
let requestLevel = TencentLBSRequestLevel.geo
if (locationOptions.geocode) {
requestLevel = TencentLBSRequestLevel.name
}
this.locationManager.requestLocation(with = requestLevel, locationTimeout = 10, completionBlock = (location?: TencentLBSLocation, err?: Error): void => {
if (location != null) {
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);
locationOptions.success(response);
} else {
locationOptions.fail(err!.localizedDescription)
}
})
return true
}
}
export function requestPremission() {
LBSLocation.requestPremission()
}
export function getLocation(locationOptions: LocationOptions): boolean {
return LBSLocation.getLocation(locationOptions)
}
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>NSLocationAlwaysUsageDescription</key>
<string>访问位置权限</string>
<key>NSLocationWhenInUseUsageDescription</key>
<string>使用期间获取位置权限</string>
<key>TencentLBSAPIKey</key>
<string>LZTBZ-77PCJ-HJAFN-KWXJ2-H357V-DJBK4</string>
<key>UIBackgroundModes</key>
<array>
<string>location</string>
</array>
</dict>
</plist>
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册