From fcfcc945beb6a2570450a3f96bbfaacec8b5ef90 Mon Sep 17 00:00:00 2001 From: zaferatli Date: Thu, 13 Jun 2024 16:32:00 +0300 Subject: [PATCH 1/2] ADD react-native-hms-map setAccessToken function and made apiKey optional --- .../main/java/com/huawei/hms/rn/map/HMSMapView.java | 9 +++++++-- react-native-hms-map/src/index.d.ts | 13 ++++++++++--- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/react-native-hms-map/android/src/main/java/com/huawei/hms/rn/map/HMSMapView.java b/react-native-hms-map/android/src/main/java/com/huawei/hms/rn/map/HMSMapView.java index 81b883d7..aa93d989 100644 --- a/react-native-hms-map/android/src/main/java/com/huawei/hms/rn/map/HMSMapView.java +++ b/react-native-hms-map/android/src/main/java/com/huawei/hms/rn/map/HMSMapView.java @@ -1411,13 +1411,18 @@ public String getName() { } @ReactMethod - public void initializer(final String apiKey, final String routePolicy, final Promise promise) { + public void initializer(final String apiKey, final String routePolicy, final String accessToken, final Promise promise) { if (routePolicy != null && !routePolicy.isEmpty()) { MapsInitializer.initialize(context, routePolicy); } else { MapsInitializer.initialize(context); } - MapsInitializer.setApiKey(apiKey); + if (setAccessToken != null && !setAccessToken.isEmpty()) { + MapsInitializer.setAccessToken(accessToken); + } + if (apiKey != null && !apiKey.isEmpty()) { + MapsInitializer.setApiKey(apiKey); + } promise.resolve(null); } diff --git a/react-native-hms-map/src/index.d.ts b/react-native-hms-map/src/index.d.ts index 057ddb3c..6e761586 100644 --- a/react-native-hms-map/src/index.d.ts +++ b/react-native-hms-map/src/index.d.ts @@ -1619,9 +1619,16 @@ declare module "@hmscore/react-native-hms-map" { /** * Initializes the Map SDK. You can set the data routing location. The options for routePolicy are CN (China), DE (Germany), SG (Singapore), and RU (Russia). - * Sets the access token of the Map SDK. - */ - initializer(apiKey: String, routePolicy: String): Promise; + * Sets the apiKey or accessToken of the Map SDK. + * apiKey does not need to be specified if the api_key field in the agconnect-services.json file already specifies an API key. + * If its set its takes precedence. + * If accessToken and apiKey set both, accessToken will be used for authentication + */ + initializer( + apiKey?: String, + routePolicy?: "CN" | "DE" | "SG" | "RU", + accessToken?: String + ): Promise; /** * Obtains all attributes of the Huawei map object From e1a5269f040ebd2378ea3bf6460ef67e05ec7789 Mon Sep 17 00:00:00 2001 From: zaferatli Date: Thu, 13 Jun 2024 16:41:47 +0300 Subject: [PATCH 2/2] ADD react-native-hms-map setAccessToken function and made apiKey optional --- .../android/src/main/java/com/huawei/hms/rn/map/HMSMapView.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/react-native-hms-map/android/src/main/java/com/huawei/hms/rn/map/HMSMapView.java b/react-native-hms-map/android/src/main/java/com/huawei/hms/rn/map/HMSMapView.java index aa93d989..99d60a87 100644 --- a/react-native-hms-map/android/src/main/java/com/huawei/hms/rn/map/HMSMapView.java +++ b/react-native-hms-map/android/src/main/java/com/huawei/hms/rn/map/HMSMapView.java @@ -1417,7 +1417,7 @@ public void initializer(final String apiKey, final String routePolicy, final Str } else { MapsInitializer.initialize(context); } - if (setAccessToken != null && !setAccessToken.isEmpty()) { + if (accessToken != null && !accessToken.isEmpty()) { MapsInitializer.setAccessToken(accessToken); } if (apiKey != null && !apiKey.isEmpty()) {