사용자 관리를 위해 Firebase를 통해 Facebook 및 Google 로그인을 사용하려고합니다.Fireboard가있는 Facebook/Google 로그인 항상 경고
P. 때마다 내가 facebbok 로그인 버튼이나 구글 로그인 버튼 I을 밀어 이유
1. 이해가 안 ... 나는
모두 지금은 잘 작동 중포 기지 문서를 따라하지만 문제가
는 한 번만 경고를 표시 할 수 있나요 ...이 경고를 참조? 무엇을 항상 보여 주어야합니까?
2. 우리는 두 번째 문제에 봉착하게됩니다. 내 앱이 사용자가 로그인하려는 페이지에 도달 할 때마다 사진 맨 위에 표시 한 것과 같은 경고가 나타납니다.이 경우 사용자는 아직 로그인 방법을 선택하지 않았습니다 Google의 경고가 즉시 나타나서는 안됩니다 .
도와 주시겠습니까?
이 앱 위임에서 내 코드는 어디에 Google 버튼과 페이스 북이 페이스 북 버튼 내의 ViewController입니다
#import "AppDelegate.h"
@import Firebase;
@import GoogleSignIn;
@import FBSDKCoreKit;
@interface AppDelegate() <GIDSignInDelegate>
@end
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
[FIRApp configure];
// GOOGLE
[GIDSignIn sharedInstance].clientID = [FIRApp defaultApp].options.clientID;
[GIDSignIn sharedInstance].delegate = self;
// FACEBOOK
[[FBSDKApplicationDelegate sharedInstance] application:application didFinishLaunchingWithOptions:launchOptions];
return YES;
}
- (BOOL)application:(nonnull UIApplication *)application openURL:(nonnull NSURL *)url options:(nonnull NSDictionary<NSString *, id> *)options {
// FACEBOOK
BOOL handled = [[FBSDKApplicationDelegate sharedInstance] application:application openURL:url sourceApplication:options[UIApplicationOpenURLOptionsSourceApplicationKey] annotation:options[UIApplicationOpenURLOptionsAnnotationKey]];
//GOOGLE
[[GIDSignIn sharedInstance] handleURL:url sourceApplication:options[UIApplicationOpenURLOptionsSourceApplicationKey] annotation:options[UIApplicationOpenURLOptionsAnnotationKey]];
return handled;
}
// GOOGLE GIDSignInDelegate
- (void)signIn:(GIDSignIn *)signIn didSignInForUser:(GIDGoogleUser *)user withError:(NSError *)error {
if (error == nil) {
GIDAuthentication *authentication = user.authentication;
FIRAuthCredential *credential = [FIRGoogleAuthProvider credentialWithIDToken:authentication.idToken accessToken:authentication.accessToken];
[[FIRAuth auth] signInWithCredential:credential completion:^(FIRUser * _Nullable user, NSError * _Nullable error) {
if (error) {
NSLog(@"Nessun account registrato su FireBase da Google errore: %@", error);
NSLog(@"%@", credential);
return ;
}
NSLog(@"Registrazione Completata");
}];
} else NSLog(@"LOGIN GOOGLE ERRORE %@", error);
}
설정
#import "KPValidation.h"
@import Firebase;
@import GoogleSignIn;
@import FBSDKLoginKit;
@import FBSDKCoreKit;
@interface KPValidation() <GIDSignInUIDelegate, FBSDKLoginButtonDelegate>
@end
@implementation KPValidation
- (void)viewDidLoad {
[super viewDidLoad];
[self setupGoogleButton];
[self setupFacebookButton];
}
-(void)setupFacebookButton {
FBSDKLoginButton *loginButton = [[FBSDKLoginButton alloc] init];
loginButton.delegate = self;
loginButton.translatesAutoresizingMaskIntoConstraints = NO;
loginButton.readPermissions = @[@"email", @"public_profile"];
[self.view addSubview:loginButton];
[loginButton.bottomAnchor constraintEqualToAnchor:self.view.bottomAnchor constant:-100].active = YES;
[loginButton.leftAnchor constraintEqualToAnchor:self.view.leftAnchor].active = YES;
[loginButton.rightAnchor constraintEqualToAnchor:self.view.rightAnchor].active = YES;
[loginButton.heightAnchor constraintEqualToConstant:50].active = YES;
}
- (void)loginButton:(FBSDKLoginButton *)loginButton didCompleteWithResult:(FBSDKLoginManagerLoginResult *)result error:(NSError *)error {
FIRAuthCredential *credential = [FIRFacebookAuthProvider credentialWithAccessToken:[FBSDKAccessToken currentAccessToken].tokenString];
[[FIRAuth auth] signInWithCredential:credential completion:^(FIRUser *user, NSError *error) {
if (error) {
// ...
return;
}
// User successfully signed in. Get user data from the FIRUser object
// ...
NSLog(@"%@", user.email);
// [self showEmail];
}];
}