设置官方Google Maps for Flutter插件的说明包括将Google API密钥添加到AppDelegate.m文件中:
在应用程序委托ios/Runner/AppDelegate.m中指定您的API密钥:
#include "AppDelegate.h"
#include "GeneratedPluginRegistrant.h"
#import "GoogleMaps/GoogleMaps.h"
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[GMSServices provideAPIKey:@"YOUR KEY HERE"];
[GeneratedPluginRegistrant registerWithRegistry:self];
return [super application:application didFinishLaunchingWithOptions:launchOptions];
}
@end
Run Code Online (Sandbox Code Playgroud)
我的flutter项目有一个AppDelegate.swift文件而不是AppDelegate.m文件,我不知道如何添加所需的密钥,因为语法不同:
import UIKit
import Flutter
@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate {
override func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?
) -> Bool {
GeneratedPluginRegistrant.register(with: self)
return super.application(application, didFinishLaunchingWithOptions: launchOptions)
}
}
Run Code Online (Sandbox Code Playgroud)
谁能帮我吗?