as instructed from a similar problem Hide Google Maps API key from source control in a Flutter app
AppDelegate.m
#include "AppDelegate.h"
#include "GeneratedPluginRegistrant.h"
#import "GoogleMaps/GoogleMaps.h"
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
NSString* mapsApiKey = [[NSProcessInfo processInfo] environment][@"FLUTTER_GMAPS_API_KEY"];
[GMSServices provideAPIKey: mapsApiKey];
[GeneratedPluginRegistrant registerWithRegistry:self];
return [super application:application didFinishLaunchingWithOptions:launchOptions];
}
@end
If i change provideApiKey to @"theApiKeyImTryingToHide" everything works fine.
I found this question by searching answer for the react-native lib maybe for someone it can be useful.
so, to read variable from env in RN you have to add
NSString *mapsApiKey = [ReactNativeConfig envFor:@"GOOGLE_MAPS_API_KEY"];
[GMSServices provideAPIKey: mapsApiKey];
into top of didFinishLaunchingWithOptions method in AppDelegate.m file
and firstly don't forget to import
#import "ReactNativeConfig.h"
ReactNativeConfig provide GOOGLE_MAPS_API_KEY
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With