Google+ in Swift
I’m working on this top-secret app and one of the requirements is that we include G+ integration using Swift. I haven’t found any good tutorials or explanations about making it work, so I thought I’d share what I’ve found so far. You can find the completed project, here.
Do Step 1: Creating the Google Developers Console Project, then Step 2.1 and then come back here.
2.2 — Drag the three files (GoogleOpenSource.framework, GooglePlus.bundle and GooglePlus.framework) to your project.
2.3 — Make sure the frameworks are added in your project’s Linked Framework and Libraries.
2.4 — Add the URL type
2.5 — Create a new header file and name it Bridging-Header (New File > Header File > Bridging-Header.h), then import both of Google’s frameworks.
2.6 — This Bridging-Header.h file needs to be referenced in your Build Settings. Make sure you point to the correct path, otherwise you’re going to crash. The path is usually projectName/Bridging-Header.h
2.7 — Add the “-ObjC” flag to Other Linker Flags. If you have any problems with this step, make sure to double check it. For some reason, when I added it, it added two separate entries.
2.9 — Your view controller in charge of log in, should implement GPPSignInDelegate and its methods.
2.10 — Import the following libraries: AddressBook, MediaPlayer, AssetsLibrary, CoreLocation and CoreMotion
2.11 — Declare a GPPSignIn variable and set it up in your viewDidLoad method.
2.12 — Finally, in your app delegate, implement the openURL method.
2.13 — After all of this, your app will compile and run but you will hit an error screen if you try to authenticate.
What you need to do is go back to your Developer Console and go to APIs & Auth > Consent Screen and fill that out. Specifically, the product name.
That’s it!
You’ll get a callback to one of your methods in ViewController when you either accept or decline. From this point forward, you would remove the last line in your viewDidLoad method and implement the sign in steps in the Google+ Sign-in for iOS page if you wanted the G+ sign in button.
Good luck!