使用 google 帐户登录,使用电子邮件,然后为应用 iOS 创建密码
log in with google account,using email and then creating password for app iOS
我是 iOS 开发新手,我想在我的应用程序中使用 Google 登录,其中电子邮件来自 Google 帐户,但密码是为应用程序创建的应用程序的新帐户并将其存储在服务器上。如何做到这一点?
以下是从 Google 登录获取电子邮件的步骤:
第 1 步:使用 Pod pod 'Google/SignIn
第 2 步:导入 #import <Google/SignIn.h>
(此导入在 Swift
的 Bridging-Header 或 Objective c
的控制器中)
添加GIDSignInUIDelegate
第 3 步:加载您想要电子邮件的登录视图或屏幕
=== 对于 Swift ===
GIDSignIn.sharedInstance().signIn()
=== 对于 Objective C ===
[[GIDSignIn sharedInstance] signIn];
第 4 步:实现 GIDSignIn
的委托方法
=== 对于 Swift ===
func signIn(signIn: GIDSignIn!, didSignInForUser user: GIDGoogleUser!,
withError error: NSError!) {
if (error == nil) {
// Perform any operations on signed in user here.
let name = user.profile.name
let email = user.profile.email
} else {
print("\(error.localizedDescription)")
}
}
=== 对于 Objective C ===
- (void)signIn:(GIDSignIn *)signIn
didSignInForUser:(GIDGoogleUser *)user
withError:(NSError *)error{
if(error == nil){
NSLog(@"%@",user.profile.name);
NSLog(@"%@",user.profile.email);
}else{
NSLog(@"%@",error.localizedDescription);
}
}
第 5 步:在您的登录视图中使用获取电子邮件地址作为预填,并根据您的要求添加其他字段,例如密码、确认密码、联系电话等。
注意:您还可以使用 GIDSignIn 共享实例中的 currentUser 对象。
=== 对于 Swift ===
GIDSignIn.sharedInstance()?.currentUser.profile.email
=== 对于 Objective C ===
[[GIDSignIn sharedInstance] currentUser].profile.email
希望对您有所帮助。
如果您有任何疑问,请告诉我。
我是 iOS 开发新手,我想在我的应用程序中使用 Google 登录,其中电子邮件来自 Google 帐户,但密码是为应用程序创建的应用程序的新帐户并将其存储在服务器上。如何做到这一点?
以下是从 Google 登录获取电子邮件的步骤:
第 1 步:使用 Pod pod 'Google/SignIn
第 2 步:导入 #import <Google/SignIn.h>
(此导入在 Swift
的 Bridging-Header 或 Objective c
的控制器中)
添加GIDSignInUIDelegate
第 3 步:加载您想要电子邮件的登录视图或屏幕
=== 对于 Swift ===
GIDSignIn.sharedInstance().signIn()
=== 对于 Objective C ===
[[GIDSignIn sharedInstance] signIn];
第 4 步:实现 GIDSignIn
=== 对于 Swift ===
func signIn(signIn: GIDSignIn!, didSignInForUser user: GIDGoogleUser!,
withError error: NSError!) {
if (error == nil) {
// Perform any operations on signed in user here.
let name = user.profile.name
let email = user.profile.email
} else {
print("\(error.localizedDescription)")
}
}
=== 对于 Objective C ===
- (void)signIn:(GIDSignIn *)signIn
didSignInForUser:(GIDGoogleUser *)user
withError:(NSError *)error{
if(error == nil){
NSLog(@"%@",user.profile.name);
NSLog(@"%@",user.profile.email);
}else{
NSLog(@"%@",error.localizedDescription);
}
}
第 5 步:在您的登录视图中使用获取电子邮件地址作为预填,并根据您的要求添加其他字段,例如密码、确认密码、联系电话等。
注意:您还可以使用 GIDSignIn 共享实例中的 currentUser 对象。
=== 对于 Swift ===
GIDSignIn.sharedInstance()?.currentUser.profile.email
=== 对于 Objective C ===
[[GIDSignIn sharedInstance] currentUser].profile.email
希望对您有所帮助。
如果您有任何疑问,请告诉我。