首先需要說的是我不使用CocoaPods。這是我第一次使用Google API。
在谷歌指南說,我需要配置GIDSignIn
在application:didFinishLaunchingWithOptions:
方法,但我也使用Facebook API,這是在這種方法配置。此外,當我嘗試在此方法中配置G API時,我收到錯誤:Type 'AppDelegate' does not conform to protocol 'GIDSignInDelegate'
和Value of type 'GIDSignIn' has no member 'configureWithError'
。
如何配置GIDSignIn
不在AppDelegate中?Google登錄API
Bridging Header
#ifndef Bridging_Header_h
#define Bridging_Header_h
#import <FBSDKCoreKit/FBSDKCoreKit.h>
#import <FBSDKLoginKit/FBSDKLoginKit.h>
#import <Bolts/Bolts.h>
#import <GoogleSignIn/GoogleSignIn.h>
#endif
AppDelegate
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
// var configureError: NSError?
// GGLContext.sharedInstance().configureWithError(&configureError)
// assert(configureError == nil, "Error configuring Google services: \(configureError)")
//
// GIDSignIn.sharedInstance().delegate = self
return FBSDKApplicationDelegate.sharedInstance().application(application, didFinishLaunchingWithOptions: launchOptions)
}
func application(application: UIApplication, openURL url: NSURL, sourceApplication: String?, annotation: AnyObject) -> Bool {
return FBSDKApplicationDelegate.sharedInstance().application(
application,
openURL: url,
sourceApplication: sourceApplication,
annotation: annotation)
}
func applicationDidBecomeActive(application: UIApplication) {
FBSDKAppEvents.activateApp()
}
}
ViewController
func signIn(signIn: GIDSignIn!, didSignInForUser user: GIDGoogleUser!, withError error: NSError!) {
if (error == nil) {
// Perform any operations on signed in user here.
let userId = user.userID // For client-side use only!
let idToken = user.authentication.idToken // Safe to send to the server
let fullName = user.profile.name
let givenName = user.profile.givenName
let familyName = user.profile.familyName
let email = user.profile.email
print(userId)
print(idToken)
print(fullName)
print(givenName)
print(familyName)
print(email)
} else {
print("\(error.localizedDescription)")
}
}
@IBAction func gPlusLoginButtonPressed(sender: AnyObject) {
var googleSignIn: GIDSignIn!
googleSignIn = GIDSignIn.sharedInstance();
googleSignIn.delegate = self
googleSignIn.uiDelegate = self
googleSignIn.shouldFetchBasicProfile = true;
googleSignIn.clientID = "24189713900-d5i1fokf9eubmb03thavk7ht371210ji.apps.googleusercontent.com"
googleSignIn.scopes.append("https://www.googleapis.com/auth/plus.login")
googleSignIn.scopes.append("https://www.googleapis.com/auth/plus.me")
googleSignIn.scopes.append("profile")
// googleSignIn.signInSilently()
googleSignIn.signIn();
}
在此處張貼一些代碼..... –
我已更新我的問題。 – Ookey