This example provides a function for generating the URL of signatures required for Google Maps API web service (business account) calls in Objective-C projects.
The original code is available here.
I simply took the necessary code to the URL signature generation and use it in a simple way.
You can test the generated signature with this tool
GMUrlSigner is available through CocoaPods.
- Add
pod 'GMUrlSigner'
to your Podfile. - Run
pod install
- Add all files under
GMUrlSigner/GMUrlSigner
to your project
To run the example project, clone the repo, and run pod install
from the Example directory first.
#import "GMUrlSigner.h"
// ...
GMUrlSigner *urlSigner = [[GMUrlSigner alloc] init];
//for our example
NSString *address = @"New+York";
NSString *clientId = @"YOURCLIENTID";
NSString *privateKey = @"vNIXE0xscrmjlyV-12Nj_BvUPaw=";
NSString *URLPortionToSign = [NSString stringWithFormat:@"/maps/api/geocode/json?address=%@&sensor=true&client=%@", address, clientId];
//get the signature
NSString *signature = [urlSigner signUrl:URLPortionToSign withThisKey:privateKey];
NSString *FullSignedURL = [NSString stringWithFormat:@"https://maps.googleapis.com%@&signature=%@", URLPortionToSign, signature];
- ARC
(If you are having any problems, just select your project -> Build Phases -> Compile Sources, double-click the GMUrlSigner and add -fobjc-arc
)
Feel free to comment (critical, remarks, ...) the code or propose any kind of optimizations/evolutions.
Cheers ! 🍻
youssman, Twitter
GMUrlSigner is available under the MIT license. See the LICENSE file for more info.