diff --git a/FirebaseUI/Database/Implementation/FirebaseArray.m b/FirebaseUI/Database/Implementation/FirebaseArray.m index e566d642f2c..d7fccf864ca 100755 --- a/FirebaseUI/Database/Implementation/FirebaseArray.m +++ b/FirebaseUI/Database/Implementation/FirebaseArray.m @@ -19,8 +19,7 @@ // clang-format on #import "FirebaseArray.h" - -@import FirebaseDatabase; +#import @implementation FirebaseArray diff --git a/FirebaseUI/Database/Implementation/FirebaseCollectionViewDataSource.m b/FirebaseUI/Database/Implementation/FirebaseCollectionViewDataSource.m index 3b64ab41de9..5d562709a90 100644 --- a/FirebaseUI/Database/Implementation/FirebaseCollectionViewDataSource.m +++ b/FirebaseUI/Database/Implementation/FirebaseCollectionViewDataSource.m @@ -19,8 +19,7 @@ // clang-format on #import "FirebaseCollectionViewDataSource.h" - -@import FirebaseDatabase; +#import @implementation FirebaseCollectionViewDataSource diff --git a/FirebaseUI/Database/Implementation/FirebaseTableViewDataSource.m b/FirebaseUI/Database/Implementation/FirebaseTableViewDataSource.m index 2dd65cd4c96..0af58bf2217 100644 --- a/FirebaseUI/Database/Implementation/FirebaseTableViewDataSource.m +++ b/FirebaseUI/Database/Implementation/FirebaseTableViewDataSource.m @@ -19,8 +19,7 @@ // clang-format on #import "FirebaseTableViewDataSource.h" - -@import FirebaseDatabase; +#import @implementation FirebaseTableViewDataSource diff --git a/FirebaseUI/FirebaseUI.podspec b/FirebaseUI/FirebaseUI.podspec new file mode 100644 index 00000000000..25e9f5a6d4d --- /dev/null +++ b/FirebaseUI/FirebaseUI.podspec @@ -0,0 +1,52 @@ +Pod::Spec.new do |s| + s.name = 'FirebaseUI' + s.version = '0.4.0' + s.summary = 'UI binding libraries for Firebase.' + s.homepage = 'https://github.com/firebase/FirebaseUI-iOS' + s.license = { :type => 'Apache License, Version 2.0', :file => 'LICENSE' } + s.author = 'Firebase' + s.source = { :git => 'https://github.com/firebase/FirebaseUI-iOS.git', :tag => s.version } + s.platform = :ios + s.ios.deployment_target = '7.0' + s.ios.framework = 'UIKit' + s.requires_arc = true + s.default_subspecs = 'All' + + s.subspec 'All' do |all| + all.dependency 'FirebaseUI/Database' + all.dependency 'FirebaseUI/Auth' + end + + s.subspec 'Database' do |database| + database.source_files = 'Database/**/*.{h,m}' + database.dependency 'Firebase/Database', '~> 3.0' + end + + s.subspec 'Auth' do |auth| + auth.dependency 'FirebaseUI/AuthBase' + auth.dependency 'FirebaseUI/Facebook' + auth.dependency 'FirebaseUI/Google' + end + + s.subspec 'AuthBase' do |authbase| + authbase.source_files = 'Auth/AuthUI/Source/*.{h,m}' + authbase.resource_bundles = {'FirebaseAuthUIBundle' => ['Auth/AuthUI/Resources/*.png', 'Auth/AuthUI/Strings/**/*.strings', 'Auth/AuthUI/Source/*.xib']} + authbase.dependency 'Firebase/Analytics', '~> 3.0' + authbase.dependency 'Firebase/Auth', '~> 3.0' + end + + s.subspec 'Facebook' do |facebook| + facebook.source_files = 'Auth/AuthProviderUI/Facebook/Source/*.{h,m}' + facebook.resource_bundles = {'FirebaseFacebookAuthUIBundle' => ['Auth/AuthProviderUI/Facebook/Resources/*.png', 'Auth/AuthProviderUI/Facebook/Strings/**/*.strings'] } + facebook.dependency 'FirebaseUI/AuthBase' + facebook.dependency 'FBSDKLoginKit', '~> 4.0' + end + + s.subspec 'Google' do |google| + google.source_files = 'Auth/AuthProviderUI/Google/Source/*.{h,m}' + google.resource_bundles = {'FirebaseGoogleAuthUIBundle' => ['Auth/AuthProviderUI/Google/Resources/*.png', 'Auth/AuthProviderUI/Google/Strings/**/*.strings'] } + google.dependency 'FirebaseUI/AuthBase' + google.dependency 'GoogleSignIn', '~> 4.0' + end + +end diff --git a/examples/FirebaseUIChat/FirebaseUIChat.xcodeproj/project.pbxproj b/examples/FirebaseUIChat/FirebaseUIChat.xcodeproj/project.pbxproj index 3633cbc634c..18eee350cb7 100644 --- a/examples/FirebaseUIChat/FirebaseUIChat.xcodeproj/project.pbxproj +++ b/examples/FirebaseUIChat/FirebaseUIChat.xcodeproj/project.pbxproj @@ -13,10 +13,6 @@ D81A05FF1B86A78700498183 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = D81A05FD1B86A78700498183 /* Main.storyboard */; }; D81A06011B86A78700498183 /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = D81A06001B86A78700498183 /* Images.xcassets */; }; D81A06041B86A78700498183 /* LaunchScreen.xib in Resources */ = {isa = PBXBuildFile; fileRef = D81A06021B86A78700498183 /* LaunchScreen.xib */; }; - D81A061B1B86AE7100498183 /* Message.m in Sources */ = {isa = PBXBuildFile; fileRef = D81A061A1B86AE7100498183 /* Message.m */; }; - D852D9411B86DEA500C732E2 /* MessageTableViewCell.m in Sources */ = {isa = PBXBuildFile; fileRef = D852D9401B86DEA500C732E2 /* MessageTableViewCell.m */; }; - D852D9431B86DEB500C732E2 /* MessageTableViewCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = D852D9421B86DEB500C732E2 /* MessageTableViewCell.xib */; }; - D852D9461B86E7A100C732E2 /* MessageDataSource.m in Sources */ = {isa = PBXBuildFile; fileRef = D852D9451B86E7A100C732E2 /* MessageDataSource.m */; }; /* End PBXBuildFile section */ /* Begin PBXFileReference section */ @@ -30,13 +26,6 @@ D81A05FE1B86A78700498183 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; D81A06001B86A78700498183 /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Images.xcassets; sourceTree = ""; }; D81A06031B86A78700498183 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/LaunchScreen.xib; sourceTree = ""; }; - D81A06191B86AE7100498183 /* Message.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Message.h; sourceTree = ""; }; - D81A061A1B86AE7100498183 /* Message.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Message.m; sourceTree = ""; }; - D852D93F1B86DEA500C732E2 /* MessageTableViewCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MessageTableViewCell.h; sourceTree = ""; }; - D852D9401B86DEA500C732E2 /* MessageTableViewCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MessageTableViewCell.m; sourceTree = ""; }; - D852D9421B86DEB500C732E2 /* MessageTableViewCell.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = MessageTableViewCell.xib; sourceTree = ""; }; - D852D9441B86E7A100C732E2 /* MessageDataSource.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MessageDataSource.h; sourceTree = ""; }; - D852D9451B86E7A100C732E2 /* MessageDataSource.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MessageDataSource.m; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -77,13 +66,6 @@ D81A06001B86A78700498183 /* Images.xcassets */, D81A06021B86A78700498183 /* LaunchScreen.xib */, D81A05F31B86A78700498183 /* Supporting Files */, - D81A06191B86AE7100498183 /* Message.h */, - D81A061A1B86AE7100498183 /* Message.m */, - D852D93F1B86DEA500C732E2 /* MessageTableViewCell.h */, - D852D9401B86DEA500C732E2 /* MessageTableViewCell.m */, - D852D9421B86DEB500C732E2 /* MessageTableViewCell.xib */, - D852D9441B86E7A100C732E2 /* MessageDataSource.h */, - D852D9451B86E7A100C732E2 /* MessageDataSource.m */, ); path = FirebaseUIChat; sourceTree = ""; @@ -155,7 +137,6 @@ buildActionMask = 2147483647; files = ( D81A05FF1B86A78700498183 /* Main.storyboard in Resources */, - D852D9431B86DEB500C732E2 /* MessageTableViewCell.xib in Resources */, D81A06041B86A78700498183 /* LaunchScreen.xib in Resources */, D81A06011B86A78700498183 /* Images.xcassets in Resources */, ); @@ -169,9 +150,6 @@ buildActionMask = 2147483647; files = ( D81A05FC1B86A78700498183 /* ViewController.m in Sources */, - D81A061B1B86AE7100498183 /* Message.m in Sources */, - D852D9461B86E7A100C732E2 /* MessageDataSource.m in Sources */, - D852D9411B86DEA500C732E2 /* MessageTableViewCell.m in Sources */, D81A05F91B86A78700498183 /* AppDelegate.m in Sources */, D81A05F61B86A78700498183 /* main.m in Sources */, ); diff --git a/examples/FirebaseUIChat/FirebaseUIChat/AppDelegate.m b/examples/FirebaseUIChat/FirebaseUIChat/AppDelegate.m index 3bee4cb531b..201bfbe5539 100644 --- a/examples/FirebaseUIChat/FirebaseUIChat/AppDelegate.m +++ b/examples/FirebaseUIChat/FirebaseUIChat/AppDelegate.m @@ -16,6 +16,7 @@ #import "AppDelegate.h" @import Firebase; +#import @implementation AppDelegate @@ -24,4 +25,11 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:( return YES; } +// You should implement this method to complete the authentication process +- (BOOL)application:(UIApplication *)app + openURL:(NSURL *)url + options:(NSDictionary *)options { + return [[FIRAuthUI authUI] handleOpenURL:url sourceApplication:options[UIApplicationOpenURLOptionsSourceApplicationKey]]; +} + @end diff --git a/examples/FirebaseUIChat/FirebaseUIChat/Base.lproj/Main.storyboard b/examples/FirebaseUIChat/FirebaseUIChat/Base.lproj/Main.storyboard index fb9d6f5199a..935658d318d 100644 --- a/examples/FirebaseUIChat/FirebaseUIChat/Base.lproj/Main.storyboard +++ b/examples/FirebaseUIChat/FirebaseUIChat/Base.lproj/Main.storyboard @@ -1,72 +1,72 @@ - + - - + + - - - - - - - - - - - - - - - - - + - - + + - + - + - - - - - - - - - + + - + - - - - - - - + + + + - + - - + + - + + + + + + + + + + + + + + + + + + + - + diff --git a/examples/FirebaseUIChat/FirebaseUIChat/Message.h b/examples/FirebaseUIChat/FirebaseUIChat/Message.h deleted file mode 100644 index 5108bdb178a..00000000000 --- a/examples/FirebaseUIChat/FirebaseUIChat/Message.h +++ /dev/null @@ -1,26 +0,0 @@ -// -// Copyright (c) 2016 Google Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// - -#import - -@interface Message : NSObject - -@property(strong, nonatomic) NSString *name; -@property(strong, nonatomic) NSString *text; - -- (instancetype)initWithName:(NSString *)name andText:(NSString *)text; - -@end diff --git a/examples/FirebaseUIChat/FirebaseUIChat/Message.m b/examples/FirebaseUIChat/FirebaseUIChat/Message.m deleted file mode 100644 index c0cfc7238cc..00000000000 --- a/examples/FirebaseUIChat/FirebaseUIChat/Message.m +++ /dev/null @@ -1,34 +0,0 @@ -// -// Copyright (c) 2016 Google Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// - -#import "Message.h" - -@implementation Message - -- (instancetype)init { - return [self initWithName:@"" andText:@""]; -} - -- (instancetype)initWithName:(NSString *)name andText:(NSString *)text { - self = [super init]; - if (self) { - self.name = name; - self.text = text; - } - return self; -} - -@end diff --git a/examples/FirebaseUIChat/FirebaseUIChat/MessageDataSource.h b/examples/FirebaseUIChat/FirebaseUIChat/MessageDataSource.h deleted file mode 100644 index 42f26fc8025..00000000000 --- a/examples/FirebaseUIChat/FirebaseUIChat/MessageDataSource.h +++ /dev/null @@ -1,21 +0,0 @@ -// -// Copyright (c) 2016 Google Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// - -#import "FirebaseUI/FirebaseTableViewDataSource.h" - -@interface MessageDataSource : FirebaseTableViewDataSource - -@end diff --git a/examples/FirebaseUIChat/FirebaseUIChat/MessageDataSource.m b/examples/FirebaseUIChat/FirebaseUIChat/MessageDataSource.m deleted file mode 100644 index 263a04f6b80..00000000000 --- a/examples/FirebaseUIChat/FirebaseUIChat/MessageDataSource.m +++ /dev/null @@ -1,33 +0,0 @@ -// -// Copyright (c) 2016 Google Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// - -#import "MessageDataSource.h" -@import FirebaseDatabase; - -@implementation MessageDataSource - -- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath { - return YES; } - -- (void)tableView:(UITableView *)tableView -commitEditingStyle:(UITableViewCellEditingStyle)editingStyle - forRowAtIndexPath:(NSIndexPath *)indexPath { - if (editingStyle == UITableViewCellEditingStyleDelete) { - [[self refForIndex:indexPath.row] removeValue]; - } -} - -@end diff --git a/examples/FirebaseUIChat/FirebaseUIChat/MessageTableViewCell.h b/examples/FirebaseUIChat/FirebaseUIChat/MessageTableViewCell.h deleted file mode 100644 index 8d23d7898a2..00000000000 --- a/examples/FirebaseUIChat/FirebaseUIChat/MessageTableViewCell.h +++ /dev/null @@ -1,26 +0,0 @@ -// -// Copyright (c) 2016 Google Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// - -#import - -@interface MessageTableViewCell : UITableViewCell -@property(weak, nonatomic) IBOutlet UILabel *myMessageLabel; -@property(weak, nonatomic) IBOutlet UILabel *myNameLabel; - -@property(weak, nonatomic) IBOutlet UILabel *otherMessageLabel; -@property(weak, nonatomic) IBOutlet UILabel *otherNameLabel; - -@end diff --git a/examples/FirebaseUIChat/FirebaseUIChat/MessageTableViewCell.m b/examples/FirebaseUIChat/FirebaseUIChat/MessageTableViewCell.m deleted file mode 100644 index eea03736bf9..00000000000 --- a/examples/FirebaseUIChat/FirebaseUIChat/MessageTableViewCell.m +++ /dev/null @@ -1,25 +0,0 @@ -// -// Copyright (c) 2016 Google Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// - -#import "MessageTableViewCell.h" - -@implementation MessageTableViewCell - -- (instancetype)initWithFrame:(CGRect)frame { - return [super initWithFrame:frame]; -} - -@end diff --git a/examples/FirebaseUIChat/FirebaseUIChat/MessageTableViewCell.xib b/examples/FirebaseUIChat/FirebaseUIChat/MessageTableViewCell.xib deleted file mode 100644 index f34b434dabb..00000000000 --- a/examples/FirebaseUIChat/FirebaseUIChat/MessageTableViewCell.xib +++ /dev/null @@ -1,74 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/examples/FirebaseUIChat/FirebaseUIChat/ViewController.h b/examples/FirebaseUIChat/FirebaseUIChat/ViewController.h index 3f5269d1428..7552ada8812 100644 --- a/examples/FirebaseUIChat/FirebaseUIChat/ViewController.h +++ b/examples/FirebaseUIChat/FirebaseUIChat/ViewController.h @@ -15,16 +15,11 @@ // @import UIKit; -@import FirebaseDatabase; -#import +@import Firebase; +#import +#import -@interface ViewController : UIViewController - -@property (strong, nonatomic) FIRDatabaseReference *ref; -@property (strong, nonatomic) FirebaseTableViewDataSource *dataSource; - -@property (weak, nonatomic) IBOutlet UITableView *tableView; -@property (weak, nonatomic) IBOutlet UITextField *inputTextField; +@interface ViewController : UIViewController @end diff --git a/examples/FirebaseUIChat/FirebaseUIChat/ViewController.m b/examples/FirebaseUIChat/FirebaseUIChat/ViewController.m index 2b64d999579..d0897ffb59b 100644 --- a/examples/FirebaseUIChat/FirebaseUIChat/ViewController.m +++ b/examples/FirebaseUIChat/FirebaseUIChat/ViewController.m @@ -15,119 +15,94 @@ // #import "ViewController.h" -#import "Message.h" -#import "MessageTableViewCell.h" -#import "MessageDataSource.h" @interface ViewController () +@property (weak, nonatomic) IBOutlet UIButton *signInBtn; +@property (weak, nonatomic) IBOutlet UIButton *signOutBtn; +@property (nonatomic) FIRAuthStateDidChangeListenerHandle authStateListener; + @end -@implementation ViewController { -// FAuthData *_currentUser; -} +@implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; - self.ref = [FIRDatabase database].reference; - - self.dataSource = - [[MessageDataSource alloc] initWithRef:self.ref - modelClass:[Message class] - nibNamed:@"MessageTableViewCell" - cellReuseIdentifier:@"cellReuseIdentifier" - view:self.tableView]; - - [self.dataSource - populateCellWithBlock:^void(MessageTableViewCell *__nonnull cell, - Message *__nonnull message) { -// if ([message.name isEqualToString:[self usernameForProvider:[self.loginViewController currentUser].provider]]) { -// cell.myMessageLabel.text = message.text; -// cell.myNameLabel.text = message.name; -// cell.myNameLabel.textColor = [UIColor colorWithRed:52.0 / 255.0 -// green:170.0 / 255.0 -// blue:220.0 / 255.0 -// alpha:1.0]; -// [cell.otherMessageLabel setHidden:YES]; -// [cell.otherNameLabel setHidden:YES]; -// [cell.myMessageLabel setHidden:NO]; -// [cell.myNameLabel setHidden:NO]; -// } else { - cell.otherMessageLabel.text = message.text; - cell.otherNameLabel.text = message.name; - cell.otherNameLabel.textColor = [UIColor colorWithRed:164.0 / 255.0 - green:199.0 / 255.0 - blue:57.0 / 255.0 - alpha:1.0]; - [cell.otherMessageLabel setHidden:NO]; - [cell.otherNameLabel setHidden:NO]; - [cell.myMessageLabel setHidden:YES]; - [cell.myNameLabel setHidden:YES]; -// } - }]; - - self.tableView.dataSource = self.dataSource; - self.tableView.delegate = self; - -// self.loginViewController = [[FirebaseLoginViewController alloc] initWithRef:self.ref]; - // Only enable social providers that you've configured -// [self.loginViewController enableProvider:FAuthProviderFacebook]; -// [self.loginViewController enableProvider:FAuthProviderGoogle]; -// [self.loginViewController enableProvider:FAuthProviderTwitter]; -// [self.loginViewController enableProvider:FAuthProviderPassword]; - -// self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:nil style:UIBarButtonItemStylePlain target:self action:@selector(toggleAuth)]; } -- (void)didReceiveMemoryWarning { - [super didReceiveMemoryWarning]; +- (void)viewWillAppear:(BOOL)animated { + + [super viewWillAppear:animated]; + + __weak id weakSelf = self; + self.authStateListener = [[FIRAuth auth] + addAuthStateDidChangeListener:^(FIRAuth *_Nonnull auth, + FIRUser *_Nullable user) { + __strong id strongSelf = weakSelf; + if(strongSelf){ + if (user != nil) { + NSLog(@"User is signed in Listener, %@", user.providerID); + self.signInBtn.hidden = YES; + self.signOutBtn.hidden = NO; + } else { + NSLog(@"No user is signed in Listener"); + self.signInBtn.hidden = NO; + self.signOutBtn.hidden = YES; + } + } + }]; } -- (void)viewWillAppear:(BOOL)animated { -// _currentUser = [self.loginViewController currentUser]; -// self.title = [self usernameForProvider:[self.loginViewController currentUser].provider]; -// self.navigationItem.rightBarButtonItem.title = _currentUser ? @"Logout" : @"Login"; - [self.tableView reloadData]; +- (void)viewWillDisappear:(BOOL)animated { + [super viewWillDisappear:animated]; + [[FIRAuth auth] removeAuthStateDidChangeListener:self.authStateListener]; } -//- (void)toggleAuth { -// if (_currentUser) { -// [self.loginViewController logout]; -// _currentUser = nil; -// self.title = @"iOS User"; -// [self.tableView reloadData]; -// } else { -// [self presentViewController:self.loginViewController animated:YES completion:nil]; -// } -// self.navigationItem.rightBarButtonItem.title = _currentUser ? @"Logout" : @"Login"; -//} - -- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { - [self.tableView deselectRowAtIndexPath:indexPath animated:YES]; +- (IBAction)signInBtnClicked:(id)sender { + + FIRAuthUI *authUI = [FIRAuthUI authUI]; + authUI.delegate = self; + + // Get client ID from [FIRApp defaultApp].options.clientID property + // clientID is the OAuth2 client ID for iOS application used to authenticate Google users + FIRGoogleAuthUI *googleAuthUI = [[FIRGoogleAuthUI alloc] initWithClientID: + [FIRApp defaultApp].options.clientID]; + + authUI.providers = @[ googleAuthUI ]; + + UIViewController *authViewController = [authUI authViewController]; + + [self presentViewController:authViewController animated:YES completion:nil]; + } -- (BOOL)textFieldShouldReturn:(UITextField *)textField { - [[self.ref childByAutoId] -// setValue:@{@"name" : [self usernameForProvider:[self.loginViewController currentUser].provider], @"text" : textField.text}]; - setValue:@{@"name" : @"iOS User", @"text" : textField.text}]; - [textField resignFirstResponder]; - textField.text = @""; - return YES; +- (IBAction)signOutBtnClicked:(id)sender { + + NSError *signOutError; + [[FIRAuthUI authUI].auth signOut:&signOutError]; + if (!signOutError) { + NSLog(@"Sign-out succeeded"); + self.signInBtn.hidden = NO; + self.signOutBtn.hidden = YES; + } } -//- (NSString *)usernameForProvider:(NSString *)provider { -// if ([provider isEqualToString:kGoogleAuthProvider]) { -// return _currentUser.providerData[@"displayName"]; -// } else if ([provider isEqualToString:kFacebookAuthProvider]) { -// return _currentUser.providerData[@"displayName"]; -// } else if ([provider isEqualToString:kTwitterAuthProvider]) { -// return [NSString stringWithFormat:@"@%@", _currentUser.providerData[@"username"]]; -// } else if ([provider isEqualToString:kPasswordAuthProvider]) { -// return _currentUser.providerData[@"email"]; -// } else { -// return @"iOS User"; -// } -//} + +- (void)authUI:(FIRAuthUI *)authUI +didSignInWithUser:(nullable FIRUser *)user +error:(nullable NSError *)error { + if (!error) { + NSLog(@"didSignIn"); + + self.signInBtn.hidden = YES; + self.signOutBtn.hidden = NO; + + } else { + + NSLog(@"authUI didSign error = %@", error.localizedDescription); + + } +} @end diff --git a/examples/FirebaseUIChat/Podfile b/examples/FirebaseUIChat/Podfile index 09bfc9911c1..96f52397379 100644 --- a/examples/FirebaseUIChat/Podfile +++ b/examples/FirebaseUIChat/Podfile @@ -1,6 +1,10 @@ platform :ios, '7.0' -pod 'FirebaseUI', :path => "../../FirebaseUI.podspec" +#use local pod +pod 'FirebaseUI', :path => "../../FirebaseUI" + +#use the lasted pod from git repo +#pod 'FirebaseUI' target 'FirebaseUIChat' do end