ios 如何安全地存储AppDelegate.swift的api-keys

798qvoo8  于 2024-01-09  发布在  iOS
关注(0)|答案(1)|浏览(136)
import UIKit
import Flutter
import GoogleMaps
import flutter_local_notifications

@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate {
  override func application(
    _ application: UIApplication,
    didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
  ) -> Bool {
    // Todo: Add your API key here
    GMSServices.provideAPIKey("XXXXXXXXXXXXXXXX")

    FlutterLocalNotificationsPlugin.setPluginRegistrantCallback { (registry) in
        GeneratedPluginRegistrant.register(with: registry)
    }

    if #available(iOS 10.0, *) {
      UNUserNotificationCenter.current().delegate = self as UNUserNotificationCenterDelegate
    }
    
    GeneratedPluginRegistrant.register(with: self)
    return super.application(application, didFinishLaunchingWithOptions: launchOptions)
  }
}

字符串
我正在制作一个Flutter移动的应用程序,上面是我的ios/Runner/AppDelegate.swift文件。现在我需要提供它Gmap API密钥,但从另一个文件,这将是.gitignored,所以我的API密钥不发布在我的版本控制。
我在Android上做了类似的事情,将密钥存储在android/app/src/main/res/values/keys.xml下

mpgws1up

mpgws1up1#

在客户端应用程序上没有安全存储的东西。恶意用户总是可以反编译代码并检索您的API密钥。
相反,您可以通过将此Google Maps API密钥限制为仅由具有您定义的应用程序ID(Android)和捆绑包ID(iOS)的应用程序使用,来尽最大努力保护在Google Cloud Console中使用此密钥的安全:API安全最佳做法-为API密钥设置应用程序限制

相关问题