ios - Flutter iOS 上每种风味构建的不同 google maps api 密钥
问题描述
正如我从google_maps_flutter文档中了解到的那样,我们需要在内部声明 google maps api 密钥,AppDelegate.swift
如下所示:
GMSServices.provideAPIKey("YOUR KEY HERE")
有没有办法为每个风味构建使用不同的 api 密钥?例如,用于开发和生产的不同 api 密钥
解决方案
我使用主动编译条件来解决这个问题:
在 Xcode 中,转到 PROJECT -> Runner -> Build Settings 并搜索“活动编译条件”。为每种不同的风味添加一个文本值。
在 中
AppDelegate.swift
,添加预处理器条件语句以针对不同的风格执行不同的代码,在我们的例子中提供不同的 API 密钥:import UIKit import Flutter import GoogleMaps @UIApplicationMain @objc class AppDelegate: FlutterAppDelegate { override func application( _ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? ) -> Bool { // Using active compilation conditions to provide the right API key for the right flavor. #if DEV GMSServices.provideAPIKey("<API key for DEV project>") #elseif QA GMSServices.provideAPIKey("<API key for QA project>") #elseif PROD GMSServices.provideAPIKey("<API key for PROD project>") #endif GeneratedPluginRegistrant.register(with: self) return super.application(application, didFinishLaunchingWithOptions: launchOptions) } }
推荐阅读
- css - 多个字体粗细的@font-face 不起作用(SCSS)
- java - 如何向后读取二进制字符串数组,然后转换为十进制 int 变量?(没有解析)
- c# - 向 LDAP 搜索添加多个条件
- python-3.x - 我从 .json 格式的 api 获得的图表/图形/监控数据
- python-2.7 - Tweepy 无法从推文中获取视频剪辑信息
- salesforce - 如何修复 Salesforce 中的“DML operation Delete not allowed on CaseShare”错误?
- asp.net - ASP.NET Core 2.1 显示用户和角色
- path - 如何设置最新 Open MPI 版本的路径?
- haskell - 如何使用可以是两种不同类型之一的 Aeson 解析 JSON 字符串
- linux - 如何在bash中读取两个输入值?