Skip to content

Commit 70b5c90

Browse files
committed
chore(ios): 升级 iOS 依赖 AMapLocation 2.6.7 to ~> 2.9.0
1 parent 01bc093 commit 70b5c90

File tree

6 files changed

+74
-13
lines changed

6 files changed

+74
-13
lines changed

README.md

Lines changed: 51 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
----
33

44
[![NPM Version](https://img.shields.io/npm/v/@uiw/react-native-amap-geolocation.svg)](https://npmjs.org/package/@uiw/react-native-amap-geolocation)
5+
![SDK-6.2.0](https://shields.io/badge/SDK-6.2.0-green?logo=android&style=flat)
6+
![AMapLocation-2.9.0](https://shields.io/badge/AMapLocation-2.9.0-green?logo=apple&style=flat)
57
![David](https://img.shields.io/david/peer/uiwjs/react-native-amap-geolocation)
68

79
React Native 高德地图定位模块,支持 Android/iOS。提供尽可能完善的原生接口,同时提供符合 Web 标准的 Geolocation API 以及 [完整的接口文档](https://uiwjs.github.io/react-native-amap-geolocation/)
@@ -81,6 +83,44 @@ nehelper sent invalid result code [1] for Wi-Fi information request
8183

8284
</details>
8385

86+
<details>
87+
<summary>Android:获取 apikey 失败 errorCode : 10001</summary>
88+
89+
```bash
90+
原因:***确保调用SDK任何接口前先调用更新隐私合规updatePrivacyShow、updatePrivacyAgree两个接口并且参数值都为true,若未正确设置有崩溃风险***
91+
使用loc SDK 功能使用前请确保已经正确设置apiKey,如有疑问请在高德开放平台官网中搜索【INVALID_USER_KEY】相关内容进行解决。
92+
```
93+
94+
解决方法:重新申请 `apikey`
95+
96+
</details>
97+
98+
99+
<details>
100+
<summary>Android:new NativeEventEmitter()` was called with a non-null argument without the required `addListener` method</summary>
101+
102+
```bash
103+
WARN `new NativeEventEmitter()` was called with a non-null argument without the required `addListener` method.
104+
WARN `new NativeEventEmitter()` was called with a non-null argument without the required `removeListeners` method.
105+
```
106+
107+
解决方法:重新申请 `apikey`
108+
109+
</details>
110+
111+
<details>
112+
<summary>Android:请在高德开放平台官网中搜索"SERVICE_NOT_EXIST"相关内容进行解决</summary>
113+
114+
```bash
115+
请在高德开放平台官网中搜索"SERVICE_NOT_EXIST"相关内容进行解决
116+
```
117+
118+
解决方法:[重新申请 `apikey`](https://lbs.amap.com/cooperation/technical_advisory/?tab=4)
119+
120+
![](./imgs/SERVICE_NOT_EXIST.png)
121+
122+
</details>
123+
84124
## 安装依赖
85125

86126
```bash
@@ -92,9 +132,15 @@ $ cd ios && pod install
92132
## 基本用法
93133

94134
```javascript
135+
import { PermissionsAndroid } from "react-native";
95136
import { Platform } from 'react-native';
96137
import AMapGeolocation from '@uiw/react-native-amap-geolocation';
97138

139+
await PermissionsAndroid.requestMultiple([
140+
PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION,
141+
PermissionsAndroid.PERMISSIONS.ACCESS_COARSE_LOCATION,
142+
]);
143+
98144
let apiKey = '';
99145

100146
if (Platform.OS === 'ios') {
@@ -152,8 +198,11 @@ const listener = AMapGeolocation.addLocationListener((location) => {
152198
this.setState({
153199
location: JSON.stringify(location, null, 2),
154200
});
155-
listener.remove();
156201
});
202+
// 移除监听事件
203+
listener.remove();
204+
// 开启监听
205+
AMapGeolocation.start();
157206
```
158207

159208
## 逆地理编码
@@ -511,7 +560,7 @@ nehelper sent invalid result code [1] for Wi-Fi information request
511560
当前工程基于 [@brodybits/create-react-native-module](https://github.com/brodybits/create-react-native-module) 初始化。
512561

513562
```bash
514-
npx create-react-native-module --package-identifier com.uiwjs.react.geolocation --object-class-name RNAMapGeolocation --generate-example AMapGeolocation --example-react-native-version 0.63.0 --module-name @uiw/react-native-amap-geolocation --github-account uiwjs --author-name "Kenny Wong" --author-email "wowohoo@qq.com"
563+
npx create-react-native-module --package-identifier com.uiwjs.example.geolocation --object-class-name RNAMapGeolocation --generate-example AMapGeolocation --example-react-native-version 0.63.0 --module-name @uiw/react-native-amap-geolocation --github-account uiwjs --author-name "Kenny Wong" --author-email "wowohoo@qq.com"
515564
```
516565

517566
## 开发

imgs/SERVICE_NOT_EXIST.png

230 KB
Loading

index.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import { NativeModules, NativeEventEmitter } from 'react-native';
22

3-
const eventEmitter = new NativeEventEmitter(NativeModules.RNAMapGeolocation);
3+
const { RNAMapGeolocation } = NativeModules;
4+
5+
const eventEmitter = new NativeEventEmitter(RNAMapGeolocation);
46

57
export default class AMapGeolocation {
68
/**
@@ -267,7 +269,7 @@ export default class AMapGeolocation {
267269
static addLocationListener(listener) {
268270
return eventEmitter.addListener('AMapGeolocation', (info) => {
269271
let errorInfo = undefined;
270-
if (info.errorCode || info.errorInfo) {
272+
if (info && (info.errorCode || info.errorInfo)) {
271273
errorInfo = {
272274
code: info.errorCode,
273275
message: info.errorInfo
@@ -276,6 +278,12 @@ export default class AMapGeolocation {
276278
listener && listener(info, errorInfo);
277279
});
278280
}
281+
/**
282+
* 要删除其注册侦听器的事件的名称
283+
*/
284+
static removeAllListeners() {
285+
return eventEmitter.removeAllListeners('AMapGeolocation');
286+
}
279287
/**
280288
* 设置是否gps优先-wx
281289
* @default false

ios/RNAMapGeolocation.m

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ + (BOOL)requiresMainQueueSetup {
2020
- (instancetype)init {
2121
self = [super init];
2222
if (self) {
23+
// https://lbs.amap.com/api/ios-location-sdk/guide/create-project/ios-location-privacy
24+
[AMapLocationManager updatePrivacyAgree:AMapPrivacyAgreeStatusDidAgree];
25+
[AMapLocationManager updatePrivacyShow:AMapPrivacyShowStatusDidShow privacyInfo:AMapPrivacyInfoStatusDidContain];
2326
_manager = [[AMapLocationManager alloc] init];
2427
_manager.delegate = self;
2528
// https://lbs.amap.com/api/ios-location-sdk/guide/get-location/singlelocation
@@ -196,6 +199,7 @@ - (instancetype)init {
196199
RCT_EXPORT_METHOD(getCurrentLocation: (RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) {
197200
CLAuthorizationStatus status = [CLLocationManager authorizationStatus];
198201
[_clManager requestWhenInUseAuthorization];
202+
NSLog(@"reGeocode:逆地理信息");
199203
// - kCLAuthorizationStatusAuthorizedWhenInUse 用户已授权仅在使用您的应用程序时使用其位置。
200204
// - kCLAuthorizationStatusAuthorizedAlways 用户已授权在任何时间使用其位置。
201205
// - kCLAuthorizationStatusNotDetermined 用户尚未对此应用做出选择

package.json

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
"main": "index.js",
77
"typings": "index.d.ts",
88
"files": [
9-
"android/libs",
109
"android/src",
1110
"android/build.gradle",
1211
"ios/RNAMapGeolocation.xcodeproj/project.pbxproj",
@@ -44,9 +43,9 @@
4443
"react-native": ">=0.60.0-rc.0 <1.0.x"
4544
},
4645
"devDependencies": {
47-
"react": "16.13.1",
48-
"react-native": "0.63.0",
49-
"typedoc": "0.18.0",
50-
"typescript": "3.9.7"
46+
"react": "18.2.0",
47+
"react-native": "0.71.4",
48+
"typedoc": "0.23.26",
49+
"typescript": "4.8.4"
5150
}
5251
}

ios/RNAMapGeolocation.podspec renamed to react-native-amap-geolocation.podspec

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
require "json"
22

3-
package = JSON.parse(File.read(File.join(__dir__, "..", "package.json")))
3+
package = JSON.parse(File.read(File.join(__dir__, "package.json")))
44

55
Pod::Spec.new do |s|
6-
s.name = "RNAMapGeolocation"
6+
# s.name = package["name"]
7+
s.name = "react-native-amap-geolocation"
78
s.version = package["version"]
89
s.summary = package["description"]
910
s.homepage = "https://github.com/uiwjs/react-native-amap-geolocation"
@@ -16,11 +17,11 @@ Pod::Spec.new do |s|
1617
s.platforms = { :ios => "9.0" }
1718
s.source = { :git => "https://github.com/uiwjs/react-native-amap-geolocation.git", :tag => "#{s.version}" }
1819

19-
s.source_files = "**/*.{h,c,m,swift}"
20+
s.source_files = "*.{h,m,mm}"
2021
s.requires_arc = true
2122

2223
s.dependency "React"
23-
s.dependency "AMapLocation", "2.6.7"
24+
s.dependency "AMapLocation", "~> 2.9.0"
2425
# ...
2526
# s.dependency "..."
2627
end

0 commit comments

Comments
 (0)