Storyboarder Cannot Read Property '0' of Undefined

Y'all can let your users cosign with Firebase using their Google Accounts by integrating Google Sign-In into your app.

Before you begin

  1. Add Firebase to your Apple projection. Include the following pods in your Podfile:
    pod 'FirebaseAuth' pod 'GoogleSignIn'            
  2. If you haven't yet connected your app to your Firebase project, do so from the Firebase console.
  3. Enable Google Sign-In in the Firebase console:
    1. In the Firebase console, open the Auth department.
    2. On the Sign in method tab, enable the Google sign-in method and click Save.

First, you lot must import the Firebase SDK and Google Sign-In SDK header files into your app.

Swift

import FirebaseCore import GoogleSignIn            

Objective-C

@import FirebaseCore; @import GoogleSignIn;            

ii. Implement Google Sign-In

Implement Google Sign-In by following these steps. See the Google Sign-In developer documentation for details on using Google Sign-In with iOS.

  1. Add custom URL schemes to your Xcode project:
    1. Open your project configuration: double-click the project proper noun in the left tree view. Select your app from the TARGETS section, then select the Info tab, and expand the URL Types section.
    2. Click the + button, and add a URL scheme for your reversed client ID. To detect this value, open the GoogleService-Info.plist configuration file, and look for the REVERSED_CLIENT_ID fundamental. Copy the value of that key, and paste it into the URL Schemes box on the configuration page. Leave the other fields bare.

      When completed, your config should await something similar to the following (but with your application-specific values):

  2. In your app consul's awarding:didFinishLaunchingWithOptions: method, configure the FirebaseApp object.

    Swift

    // Use Firebase library to configure APIs FirebaseApp.configure()                

    Objective-C

    // Use Firebase library to configure APIs [FIRApp configure];                
  3. Implement the application:openURL:options: method of your app consul. The method should telephone call the handleURL method of the GIDSignIn case, which will properly handle the URL that your application receives at the end of the authentication process.

    Swift

    @available(iOS 9.0, *) func application(_ application: UIApplication, open url: URL,                  options: [UIApplication.OpenURLOptionsKey: Any])   -> Bool {   return GIDSignIn.sharedInstance.handle(url) }                

    Objective-C

    - (BOOL)application:(nonnull UIApplication *)application             openURL:(nonnull NSURL *)url             options:(nonnull NSDictionary<NSString *, id> *)options {   return [[GIDSignIn sharedInstance] handleURL:url]; }                
  4. Pass the presenting view controller and customer ID for your app to the Google Sign In sign-in method and create a Firebase auth credential from the resulting Google auth token:

    Swift

    baby-sit let clientID = FirebaseApp.app()?.options.clientID else { return }  // Create Google Sign In configuration object. let config = GIDConfiguration(clientID: clientID)  // Commencement the sign in menstruum! GIDSignIn.sharedInstance.signIn(with: config, presenting: cocky) { [unowned self] user, error in    if let error = fault {     // ...     return   }    baby-sit     let authentication = user?.authentication,     let idToken = authentication.idToken   else {     return   }    permit credential = GoogleAuthProvider.credential(withIDToken: idToken,                                                  accessToken: authentication.accessToken)    // ... }                

    Objective-C

    GIDConfiguration *config = [[GIDConfiguration alloc] initWithClientID:[FIRApp defaultApp].options.clientID];  __weak __auto_type weakSelf = self; [GIDSignIn.sharedInstance signInWithConfiguration:config presentingViewController:self callback:^(GIDGoogleUser * _Nullable user, NSError * _Nullable mistake) {   __auto_type strongSelf = weakSelf;   if (strongSelf == goose egg) { return; }    if (error == nil) {     GIDAuthentication *hallmark = user.authentication;     FIRAuthCredential *credential =     [FIRGoogleAuthProvider credentialWithIDToken:hallmark.idToken                                      accessToken:authentication.accessToken];     // ...   } else {     // ...   } }];                
  5. Add a GIDSignInButton to your storyboard, XIB file, or instantiate it programmatically. To add the push to your storyboard or XIB file, add a View and set its custom form to GIDSignInButton.
  6. Optional: If you want to customize the button, do the post-obit:

    Swift

    1. In your view controller, declare the sign-in button every bit a property.
      @IBOutlet weak var signInButton: GIDSignInButton!
    2. Connect the button to the signInButton property yous just declared.
    3. Customize the button past setting the backdrop of the GIDSignInButton object.

    Objective-C

    1. In your view controller's header file, declare the sign-in push button equally a property.
      @property(weak, nonatomic) IBOutlet GIDSignInButton *signInButton;
    2. Connect the button to the signInButton property y'all just declared.
    3. Customize the button by setting the properties of the GIDSignInButton object.

3. Authenticate with Firebase

Finally, consummate the Firebase login procedure with the auth credential created in the previous step.

Swift

Auth.auth().signIn(with: credential) { authResult, error in     if let error = error {       let authError = error as NSError       if isMFAEnabled, authError.code == AuthErrorCode.secondFactorRequired.rawValue {         // The user is a multi-factor user. 2d factor claiming is required.         let resolver = authError           .userInfo[AuthErrorUserInfoMultiFactorResolverKey] every bit! MultiFactorResolver         var displayNameString = ""         for tmpFactorInfo in resolver.hints {           displayNameString += tmpFactorInfo.displayName ?? ""           displayNameString += " "         }         cocky.showTextInputPrompt(           withMessage: "Select factor to sign in\n\(displayNameString)",           completionBlock: { userPressedOK, displayName in             var selectedHint: PhoneMultiFactorInfo?             for tmpFactorInfo in resolver.hints {               if displayName == tmpFactorInfo.displayName {                 selectedHint = tmpFactorInfo as? PhoneMultiFactorInfo               }             }             PhoneAuthProvider.provider()               .verifyPhoneNumber(with: selectedHint!, uiDelegate: zip,                                  multiFactorSession: resolver                                    .session) { verificationID, error in                 if error != nil {                   print(                     "Multi cistron start sign in failed. Fault: \(error.debugDescription)"                   )                 } else {                   self.showTextInputPrompt(                     withMessage: "Verification code for \(selectedHint?.displayName ?? "")",                     completionBlock: { userPressedOK, verificationCode in                       let credential: PhoneAuthCredential? = PhoneAuthProvider.provider()                         .credential(withVerificationID: verificationID!,                                     verificationCode: verificationCode!)                       permit assertion: MultiFactorAssertion? = PhoneMultiFactorGenerator                         .assertion(with: credential!)                       resolver.resolveSignIn(with: assertion!) { authResult, error in                         if error != zero {                           print(                             "Multi gene finanlize sign in failed. Fault: \(mistake.debugDescription)"                           )                         } else {                           cocky.navigationController?.popViewController(animated: true)                         }                       }                     }                   )                 }               }           }         )       } else {         cocky.showMessagePrompt(mistake.localizedDescription)         return       }       // ...       return     }     // User is signed in     // ... }

Objective-C

[[FIRAuth auth] signInWithCredential:credential                           completion:^(FIRAuthDataResult * _Nullable authResult,                                        NSError * _Nullable error) {     if (isMFAEnabled && fault && error.code == FIRAuthErrorCodeSecondFactorRequired) {       FIRMultiFactorResolver *resolver = error.userInfo[FIRAuthErrorUserInfoMultiFactorResolverKey];       NSMutableString *displayNameString = [NSMutableString string];       for (FIRMultiFactorInfo *tmpFactorInfo in resolver.hints) {         [displayNameString appendString:tmpFactorInfo.displayName];         [displayNameString appendString:@" "];       }       [self showTextInputPromptWithMessage:[NSString stringWithFormat:@"Select factor to sign in\n%@", displayNameString]                            completionBlock:^(BOOL userPressedOK, NSString *_Nullable displayName) {        FIRPhoneMultiFactorInfo* selectedHint;        for (FIRMultiFactorInfo *tmpFactorInfo in resolver.hints) {          if ([displayName isEqualToString:tmpFactorInfo.displayName]) {            selectedHint = (FIRPhoneMultiFactorInfo *)tmpFactorInfo;          }        }        [FIRPhoneAuthProvider.provider         verifyPhoneNumberWithMultiFactorInfo:selectedHint         UIDelegate:nil         multiFactorSession:resolver.session         completion:^(NSString * _Nullable verificationID, NSError * _Nullable error) {           if (error) {             [self showMessagePrompt:error.localizedDescription];           } else {             [self showTextInputPromptWithMessage:[NSString stringWithFormat:@"Verification code for %@", selectedHint.displayName]                                  completionBlock:^(BOOL userPressedOK, NSString *_Nullable verificationCode) {              FIRPhoneAuthCredential *credential =                  [[FIRPhoneAuthProvider provider] credentialWithVerificationID:verificationID                                                               verificationCode:verificationCode];              FIRMultiFactorAssertion *assertion = [FIRPhoneMultiFactorGenerator assertionWithCredential:credential];              [resolver resolveSignInWithAssertion:exclamation completion:^(FIRAuthDataResult * _Nullable authResult, NSError * _Nullable error) {                if (fault) {                  [cocky showMessagePrompt:mistake.localizedDescription];                } else {                  NSLog(@"Multi factor finanlize sign in succeeded.");                }              }];            }];           }         }];      }];     }   else if (error) {     // ...     return;   }   // User successfully signed in. Get user information from the FIRUser object   if (authResult == aught) { render; }   FIRUser *user = authResult.user;   // ... }];

Side by side steps

After a user signs in for the commencement time, a new user account is created and linked to the credentials—that is, the user proper noun and countersign, telephone number, or auth provider data—the user signed in with. This new account is stored every bit function of your Firebase project, and can be used to place a user across every app in your project, regardless of how the user signs in.

  • In your apps, you can get the user's basic profile data from the FIRUser object. Meet Manage Users.

  • In your Firebase Realtime Database and Cloud Storage Security Rules, you tin get the signed-in user's unique user ID from the auth variable, and use it to control what data a user can access.

You can allow users to sign in to your app using multiple authentication providers by linking auth provider credentials to an existing user business relationship.

To sign out a user, phone call signOut:.

Swift

              permit firebaseAuth = Auth.auth() do {   attempt firebaseAuth.signOut() } catch let signOutError as NSError {   print("Error signing out: %@", signOutError) }            

Objective-C

              NSError *signOutError; BOOL status = [[FIRAuth auth] signOut:&signOutError]; if (!condition) {   NSLog(@"Error signing out: %@", signOutError);   return; }            

You may also want to add fault handling code for the full range of authentication errors. Come across Handle Errors.

silbermanbreas1983.blogspot.com

Source: https://firebase.google.com/docs/auth/ios/google-signin

0 Response to "Storyboarder Cannot Read Property '0' of Undefined"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel