Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Map APIs not working after adding bundle identifier - iOS

I Google developer console I created an iOS key as below: enter image description here

I want to restrict this key to one app only, so I "Edit allowed iOS application" add my bundle Id to it. My bundle Id is easily found in General tab of my project target as following:

enter image description here

I don't know if it is case-sensitive or not, but I copy exactly the identifier from there to add to the key. As you can see, it cannot be mistaken. I also followed Google's instruction, one bundle Identifier per line (I only input one line):

Accept requests from an iOS application with one of the bundle identifiers listed below (Optional) One bundle identifier per line. Example: com.example.MyApp

Or if you leave this blank, requests will be accepted from any iOS application. Be sure to add bundle identifiers before using this key in production.

This screen show that I enabled all necessary services, to be sure:

enter image description here

The problem with me is that, whenever I added a bundle identifier to the key, my app stops working. But then when I deleted it (now "Any application allowed" as in the picture), everything goes back to work fine.

Could anyone please tell me what could possible cause this?

UPDATE: To clarify more: When I add my bundle ID to the key in Developer Console, now I can still use nearby search in my app. But Autocomplete search and Google URL shortener have stopped working..

like image 715
thomasdao Avatar asked Oct 15 '25 15:10

thomasdao


2 Answers

whatever request that is getting 403 should be sent with additional header X-Ios-Bundle-Identifier, where your bundle id should be set. This seems undocumented, I only found it through jumping between links, see this...

like image 78
zhywu Avatar answered Oct 18 '25 08:10

zhywu


I also ran into this issue and solved it by following @zhywu's answer above

The Swift 5 code that leverages URLSession/URLSessionDataTask looks like this:

if var urlComponents = URLComponents(string: "https://www.googleapis.com/...") {
            ...
            guard let url = urlComponents.url else { return }

            var request = URLRequest(url: url)
            request.setValue(Bundle.main.bundleIdentifier ?? "", forHTTPHeaderField: "X-Ios-Bundle-Identifier")

            dataTask = defaultSession.dataTask(with: request) { ... }
            ...
}
like image 36
Peter Kaminski Avatar answered Oct 18 '25 09:10

Peter Kaminski



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!