'Use of Unresolved Identifier 'GMSServices'
I am using Xcode 7.1 and the deployment target is iOS 9.1. The app is "AreaCalculator" and it was written in Swift. I did following to set up the framework and import the map:
$ sudo gem install cocoapods
under "AreaCalculator" $ touch Podfile
in Podfile I put:
source 'https://github.com/CocoaPods/Specs.git' platform :ios, '9.1' pod 'GoogleMaps'
$ pod install
in the terminal:
[!] Unable to load a specification for the plugin
/Library/Ruby/Gems/2.0.0/gems/cocoapods-try-release-fix-0.1.2
Updating local specs repositories Analyzing dependencies Downloading dependencies Installing GoogleMaps (1.10.5) Generating Pods project Integrating client project[!] Please close any current Xcode sessions and use
AreaCalculator.xcworkspace
for this project from now on. Sending stats Pod installation complete! There is 1 dependency from the Podfile and 1 total pod installed.After that, I selected the AreaCalculator folder in the Navigator and select File\New\File…, then choose the iOS\Source\Objective-C File template and created a Bridging file:
"AreaCalculator-Bridging-Header.h".- "#import GoogleMaps/GoogleMaps.h
Then I add "GoogleMaps.framework" in "Link Binary With Libraries". And both "GoogleMaps.framwork" and ""GoogleMaps.bundle" are in the Pods folder.
After all those done, in the AppDelegate.swift, I put:
import UIKit @UIApplicationMain class AppDelegate: UIResponder, UIApplicationDelegate { var window: UIWindow? let googleMapsApiKey = "MY_GOOGLE_IOS_API_KEY" func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { // Override point for customization after application launch. GMSServices.provideAPIKey(googleMapsApiKey) return true } }
However, the compiler showed me an error "Use of Unresolved Identifier 'GMSServices' ".
I have no idea where I did wrong? Anyone can help?
Thanks!
Solution 1:[1]
I have solved the problem by "import GoogleMaps" in the AppDelegate.swift.
Solution 2:[2]
Add this line in AppDelegate.m
#import "GoogleMaps/GoogleMaps.h"
Solution 3:[3]
For react native make sure you are importing from above to #if DEBUG mode.
Put librarries above #if DEBUG
#import "AppDelegate.h"
#import <React/RCTBridge.h>
#import <React/RCTBundleURLProvider.h>
#import <React/RCTRootView.h>
#import "RNSplashScreen.h" // here
#import <GoogleMaps/GoogleMaps.h>
#if DEBUG
#import <FlipperKit/FlipperClient.h>
#import <FlipperKitLayoutPlugin/FlipperKitLayoutPlugin.h>
#import <FlipperKitUserDefaultsPlugin/FKUserDefaultsPlugin.h>
#import <FlipperKitNetworkPlugin/FlipperKitNetworkPlugin.h>
#import <SKIOSNetworkPlugin/SKIOSNetworkAdapter.h>
#import <FlipperKitReactPlugin/FlipperKitReactPlugin.h>```
Found here -> https://github.com/react-native-community/react-native-maps/issues/3453#issuecomment-665475820
Solution 4:[4]
....
#add this line
import GoogleMaps
@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate {
override func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
GMSServices.provideAPIKey("YOUR-API-KEY")
GeneratedPluginRegistrant.register(with: self)
return super.application(application, didFinishLaunchingWithOptions: launchOptions)
}
}
Solution 5:[5]
For react native 0.64.1
Add this line in AppDelegate.m
#import <GoogleMaps/GoogleMaps.h>
above
#ifdef FB_SONARKIT_ENABLED
eg:
#import <React/RCTLinkingManager.h>
#import "ReactNativeConfig.h"
#import <GoogleMaps/GoogleMaps.h>
#ifdef FB_SONARKIT_ENABLED
#import <FlipperKit/FlipperClient.h>
Solution 6:[6]
I experienced this issue with Flutter and solved it by adding import GoogleMaps to the AppDelegate.swift file which is located in ios > Runner>
Here's what it should look like:
import UIKit
import Flutter
import GoogleMaps
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Jun D |
Solution 2 | Ahad Khan |
Solution 3 | Chinedu Ofor |
Solution 4 | bara batta |
Solution 5 | majurageerthan |
Solution 6 | Sharon |