我想創建一個類來處理我的項目上的所有登錄服務。除谷歌登錄之外,一切工作都正常。谷歌登錄不在UIVIewController
我想要在Google文檔中提到的Google登錄不在UIVIewController中,您可以使用GIDSignInDelegate
來完成此操作,並在您的類不是UIViewController時使用它。
我的課程從NSObject
延伸,並希望在該服務上處理Google SignIn,之後我只需調用一種方法即可完成此操作。
var ls: LoginService = LoginService.instance
ls.doGoogleLogin()
這裏是我的login服務:
struct LOGIN_URL {
static let LOGIN: String = "login"
}
protocol LoginServiceDelegate: class {
func loginSuccess(loginResponse: User)
func loginFailed(message: String)
}
class LoginService: NSObject, GIDSignInDelegate{
static let instance = LoginService()
weak var delegate: LoginServiceDelegate?
var user: User?
func doGoogleLogin(){
var configureError: NSError?
GGLContext.sharedInstance().configureWithError(&configureError)
assert(configureError == nil, "Error configuring Google services: \(configureError)")
GIDSignIn.sharedInstance().delegate = self
// GIDSignIn.sharedInstance().uiDelegate = self
GIDSignIn.sharedInstance().signIn()
}
public func sign(_ signIn: GIDSignIn!, didSignInFor user: GIDGoogleUser!, withError error: Error!) {
print(user.profile.email)
}
func signIn(signIn: GIDSignIn!,
presentViewController viewController: UIViewController!) {
self.presentViewController(viewController, animated: true, completion: nil)
}
func signIn(signIn: GIDSignIn!,
dismissViewController viewController: UIViewController!) {
self.dismissViewControllerAnimated(true, completion: nil)
}
}
當我使用此代碼我得到一個錯誤 value of type LoginService has no member presentViewController
我應該在這裏做的沒有得到這個錯誤?