Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Google Places API with Alamofire 4.0 and iOS 10 and Swift 3

My project is currently built in Xcode 8 and in Swift 3 with Alamofire 4.0. I use CocoaPods to implement Alamofire.

My podfile is as follows:

# Uncomment the next line to define a global platform for your project
platform :ios, '10.0'
use_frameworks!

target 'WTB’ do
# Comment the next line if you're not using Swift and don't want to use        dynamic frameworks
pod 'Alamofire', :git => 'https://github.com/Alamofire/Alamofire.git', :tag => ’4.0.0’


pod 'SwiftyJSON', git: 'https://github.com/BaiduHiDeviOS/SwiftyJSON.git',     branch: 'swift3'

pod 'GooglePlaces'    #doesn't work when this line is added
pod 'ChameleonFramework'
end        

I get the following error in the terminal when trying to install the googlePlaces pod:

- `Alamofire (from `https://github.com/Alamofire/Alamofire.git`, tag    `4.0.0`)` required by `Podfile`
- `Alamofire (= 4.0.0)` required by `Podfile.lock`
- `Alamofire (~> 3.0)` required by `GooglePlaces (1.0.1)`

Google places works with previous versions of Alamofire (3.4.0) but i cant get it working with 4.0.0+.Am i doing something wrong here? is anyone else having the same problem/ found a fix?

UPDATE: I have still no luck after clean pod install

Matthews-MBP:WTB matthewwyeth$ rm -Rf Pods; pod install
Analyzing dependencies
Pre-downloading: `Alamofire` from    `https://github.com/Alamofire/Alamofire.git`, tag `4.0.0`
Pre-downloading: `SwiftyJSON` from    `https://github.com/BaiduHiDeviOS/SwiftyJSON.git`, commit     `de5dc3b1b421805769590d331178551bbb0e5733`
[!] Unable to satisfy the following requirements:

- `Alamofire (from `https://github.com/Alamofire/Alamofire.git`, tag   `4.0.0`)` required by `Podfile`
- `Alamofire (= 4.0.0)` required by `Podfile.lock`
- `Alamofire (~> 3.0)` required by `GooglePlaces (1.0.1)`

[!] Your Podfile has had smart quotes sanitised. To avoid issues in the            future, you should not use TextEdit for editing it. If you are not using            TextEdit, you should turn off smart quotes in your editor of choice.
like image 685
Matt Wyeth Avatar asked Nov 07 '16 19:11

Matt Wyeth


People also ask

What is Alamofire in Swift?

Alamofire is a networking library written in Swift. You use it to make HTTP(S) requests on iOS, macOS and other Apple platforms. For example, to post data to a web-based REST API or to download an image from a webserver. Alamofire has a convenient API built on top of URLSession (“URL Loading System”).

Where do I get Google Places API key?

Go to the Google Maps Platform > Credentials page. On the Credentials page, click Create credentials > API key. The API key created dialog displays your newly created API key. Click Close.


2 Answers

You should change the version of Google Places to 2.* in your pod file, this dependency requires Alamofire 4.0.

Google Places pod v2.* : https://cocoapods.org/?q=googleplaces

like image 174
AsimRazaKhan Avatar answered Oct 21 '22 08:10

AsimRazaKhan


Actually the problem is when you write

pod 'GooglePlaces'

Inside the PodFile it's not bringing the right Pod but it still fetches the old GooglePlacesAPI Pod First just type pod search GooglePlaces inside terminal and it will fetch many results as the first one should be matched you will notice that it's gonna be THE OLD POD so .. You should update your pod repositories

pod update

And it takes time to finish even though you may not seeing any changes in the terminal but in Activity Monitor -> Network you can monitor it so Be patient until it finishes the update and after that just retype pod search GooglePlaces in terminal and it's gonna be the new one and then just run

pod install 

Again and you're good to go !

*Here is my Podfile in case you need to take a look :

source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '10.0'
use_frameworks!
target 'YOUR-PROJECT' do
pod 'GoogleMaps', '= 2.1.1'
pod 'GooglePlaces', '= 2.1.1'
pod 'Alamofire',
:git => 'https://github.com/Alamofire/Alamofire.git',
:branch => 'master'
end
like image 2
Nour Avatar answered Oct 21 '22 09:10

Nour