Настройка Google Maps для Flutter iOS - PullRequest
0 голосов
/ 15 декабря 2018

Инструкции по настройке официального плагина Google Maps для Flutter включают добавление ключа API Google в файл AppDelegate.m:

Укажите свой ключ API в делегате приложения ios / Runner / AppDelegate.m:

#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

Мой проект флаттера содержит файл 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)
  }
}

Кто-нибудь может мне помочь?

Ответы [ 2 ]

0 голосов
/ 25 июля 2019

Еще одна вещь, не забудьте добавить строку ниже ios / Runner / Info.plist

<key>io.flutter.embedded_views_preview</key>
<true/>
0 голосов
/ 15 декабря 2018

Вы можете добавить свой ключ API следующим образом:

AppDelegate.swift:

import UIKit
import Flutter
import GoogleMaps // Add this line!

@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate {
  override func application(
    _ application: UIApplication,
    didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?
  ) -> Bool {
    GeneratedPluginRegistrant.register(with: self)
    GMSServices.provideAPIKey("YOUR_API_KEY")  // Add this line!
    return super.application(application, didFinishLaunchingWithOptions: launchOptions)
  }
}
...