Skip to content

Commit 52a8e8d

Browse files
committed
didSignInWithUser is not being called when subclass of FIRAuthPickerViewController is used. #138
1 parent 7bbaf82 commit 52a8e8d

File tree

8 files changed

+209
-16
lines changed

8 files changed

+209
-16
lines changed

samples/objc/FirebaseUIChat.xcodeproj/project.pbxproj

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88

99
/* Begin PBXBuildFile section */
1010
34755DFFAC2DCB6B1176CE87 /* libPods-FirebaseUIChat.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 2CFFAE2215B9D3116BF1AEEF /* libPods-FirebaseUIChat.a */; };
11+
C375CB181D935D1F002EECD3 /* FIRCustomAuthPickerViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = C375CB161D935D1F002EECD3 /* FIRCustomAuthPickerViewController.m */; };
12+
C375CB191D935D1F002EECD3 /* FIRCustomAuthPickerViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = C375CB171D935D1F002EECD3 /* FIRCustomAuthPickerViewController.xib */; };
13+
C375CB1C1D943D5F002EECD3 /* FIRCustomAuthUIDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = C375CB1B1D943D5F002EECD3 /* FIRCustomAuthUIDelegate.m */; };
1114
C3AC675E1D81FE6B00FC956D /* FIRAuthViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = C3AC67531D81FE6B00FC956D /* FIRAuthViewController.m */; };
1215
C3AC675F1D81FE6B00FC956D /* FIRChatMessage.m in Sources */ = {isa = PBXBuildFile; fileRef = C3AC67561D81FE6B00FC956D /* FIRChatMessage.m */; };
1316
C3AC67601D81FE6B00FC956D /* FIRChatMessageDataSource.m in Sources */ = {isa = PBXBuildFile; fileRef = C3AC67581D81FE6B00FC956D /* FIRChatMessageDataSource.m */; };
@@ -28,6 +31,11 @@
2831
104B66B372B77CFFE53BC90D /* Pods-FirebaseUIChat.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-FirebaseUIChat.debug.xcconfig"; path = "Pods/Target Support Files/Pods-FirebaseUIChat/Pods-FirebaseUIChat.debug.xcconfig"; sourceTree = "<group>"; };
2932
2CFFAE2215B9D3116BF1AEEF /* libPods-FirebaseUIChat.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-FirebaseUIChat.a"; sourceTree = BUILT_PRODUCTS_DIR; };
3033
92E1431893A040764FCC115E /* Pods-FirebaseUIChat.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-FirebaseUIChat.release.xcconfig"; path = "Pods/Target Support Files/Pods-FirebaseUIChat/Pods-FirebaseUIChat.release.xcconfig"; sourceTree = "<group>"; };
34+
C375CB151D935D1F002EECD3 /* FIRCustomAuthPickerViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FIRCustomAuthPickerViewController.h; sourceTree = "<group>"; };
35+
C375CB161D935D1F002EECD3 /* FIRCustomAuthPickerViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FIRCustomAuthPickerViewController.m; sourceTree = "<group>"; };
36+
C375CB171D935D1F002EECD3 /* FIRCustomAuthPickerViewController.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = FIRCustomAuthPickerViewController.xib; sourceTree = "<group>"; };
37+
C375CB1A1D943D5F002EECD3 /* FIRCustomAuthUIDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FIRCustomAuthUIDelegate.h; sourceTree = "<group>"; };
38+
C375CB1B1D943D5F002EECD3 /* FIRCustomAuthUIDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FIRCustomAuthUIDelegate.m; sourceTree = "<group>"; };
3139
C3AC67521D81FE6B00FC956D /* FIRAuthViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FIRAuthViewController.h; sourceTree = "<group>"; };
3240
C3AC67531D81FE6B00FC956D /* FIRAuthViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FIRAuthViewController.m; sourceTree = "<group>"; };
3341
C3AC67551D81FE6B00FC956D /* FIRChatMessage.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FIRChatMessage.h; sourceTree = "<group>"; };
@@ -97,6 +105,11 @@
97105
children = (
98106
C3AC67521D81FE6B00FC956D /* FIRAuthViewController.h */,
99107
C3AC67531D81FE6B00FC956D /* FIRAuthViewController.m */,
108+
C375CB1A1D943D5F002EECD3 /* FIRCustomAuthUIDelegate.h */,
109+
C375CB1B1D943D5F002EECD3 /* FIRCustomAuthUIDelegate.m */,
110+
C375CB151D935D1F002EECD3 /* FIRCustomAuthPickerViewController.h */,
111+
C375CB161D935D1F002EECD3 /* FIRCustomAuthPickerViewController.m */,
112+
C375CB171D935D1F002EECD3 /* FIRCustomAuthPickerViewController.xib */,
100113
);
101114
path = Auth;
102115
sourceTree = "<group>";
@@ -228,6 +241,7 @@
228241
C3AC67621D81FE6B00FC956D /* FIRChatMessageTableViewCell.xib in Resources */,
229242
D81A06041B86A78700498183 /* LaunchScreen.xib in Resources */,
230243
D81A06011B86A78700498183 /* Images.xcassets in Resources */,
244+
C375CB191D935D1F002EECD3 /* FIRCustomAuthPickerViewController.xib in Resources */,
231245
);
232246
runOnlyForDeploymentPostprocessing = 0;
233247
};
@@ -287,6 +301,8 @@
287301
buildActionMask = 2147483647;
288302
files = (
289303
D81A05F91B86A78700498183 /* AppDelegate.m in Sources */,
304+
C375CB181D935D1F002EECD3 /* FIRCustomAuthPickerViewController.m in Sources */,
305+
C375CB1C1D943D5F002EECD3 /* FIRCustomAuthUIDelegate.m in Sources */,
290306
C3F23ED01D80F58A0020509F /* FIRSamplesViewController.m in Sources */,
291307
C3AC67631D81FE6B00FC956D /* FIRChatViewController.m in Sources */,
292308
C3AC67611D81FE6B00FC956D /* FIRChatMessageTableViewCell.m in Sources */,

samples/objc/FirebaseUIChat/Base.lproj/Main.storyboard

Lines changed: 38 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
<dependencies>
44
<deployment identifier="iOS"/>
55
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="10085"/>
6+
<capability name="Constraints to layout margins" minToolsVersion="6.0"/>
67
</dependencies>
78
<scenes>
89
<!--Navigation Controller-->
@@ -125,7 +126,7 @@
125126
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
126127
<color key="backgroundColor" red="0.93725490199999995" green="0.93725490199999995" blue="0.95686274510000002" alpha="1" colorSpace="calibratedRGB"/>
127128
<toolbar key="tableFooterView" opaque="NO" clearsContextBeforeDrawing="NO" contentMode="scaleToFill" id="83E-4Z-ptP">
128-
<rect key="frame" x="0.0" y="587" width="600" height="44"/>
129+
<rect key="frame" x="0.0" y="631" width="600" height="44"/>
129130
<autoresizingMask key="autoresizingMask" widthSizable="YES" flexibleMinY="YES"/>
130131
<items>
131132
<barButtonItem style="plain" systemItem="flexibleSpace" id="o3y-o4-Gpu"/>
@@ -138,7 +139,7 @@
138139
</items>
139140
</toolbar>
140141
<sections>
141-
<tableViewSection headerTitle="Signed In" id="PRj-zg-0nr">
142+
<tableViewSection headerTitle="Settings" id="PRj-zg-0nr">
142143
<cells>
143144
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" selectionStyle="none" indentationWidth="10" textLabel="l96-xc-PHH" style="IBUITableViewCellStyleDefault" id="ORf-bf-Sq2">
144145
<rect key="frame" x="0.0" y="50" width="600" height="44"/>
@@ -157,12 +158,41 @@
157158
</subviews>
158159
</tableViewCellContentView>
159160
</tableViewCell>
161+
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" selectionStyle="none" indentationWidth="10" id="1sh-pl-VVu">
162+
<rect key="frame" x="0.0" y="94" width="600" height="44"/>
163+
<autoresizingMask key="autoresizingMask"/>
164+
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="1sh-pl-VVu" id="cPB-dF-hTp">
165+
<rect key="frame" x="0.0" y="0.0" width="600" height="43"/>
166+
<autoresizingMask key="autoresizingMask"/>
167+
<subviews>
168+
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Use Custom AuthPickerViewController" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" minimumFontSize="9" translatesAutoresizingMaskIntoConstraints="NO" id="YxK-c8-9q7">
169+
<rect key="frame" x="19" y="12" width="563" height="20"/>
170+
<fontDescription key="fontDescription" type="system" pointSize="16"/>
171+
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
172+
<nil key="highlightedColor"/>
173+
</label>
174+
<switch opaque="NO" contentMode="scaleToFill" horizontalHuggingPriority="750" verticalHuggingPriority="750" contentHorizontalAlignment="center" contentVerticalAlignment="center" translatesAutoresizingMaskIntoConstraints="NO" id="JZd-6c-Soe">
175+
<rect key="frame" x="533" y="6" width="51" height="31"/>
176+
<connections>
177+
<action selector="onAuthUIDelegateChanged:" destination="CNE-cz-Qwp" eventType="valueChanged" id="KtF-5y-VCY"/>
178+
</connections>
179+
</switch>
180+
</subviews>
181+
<constraints>
182+
<constraint firstItem="JZd-6c-Soe" firstAttribute="centerY" secondItem="cPB-dF-hTp" secondAttribute="centerY" id="1Bs-jz-kxY"/>
183+
<constraint firstAttribute="trailingMargin" secondItem="JZd-6c-Soe" secondAttribute="trailing" constant="10" id="StU-03-OWl"/>
184+
<constraint firstItem="YxK-c8-9q7" firstAttribute="leading" secondItem="cPB-dF-hTp" secondAttribute="leadingMargin" constant="11" id="USn-bv-nmj"/>
185+
<constraint firstItem="YxK-c8-9q7" firstAttribute="trailing" secondItem="JZd-6c-Soe" secondAttribute="trailing" id="cPK-Rb-Vg8"/>
186+
<constraint firstItem="YxK-c8-9q7" firstAttribute="centerY" secondItem="cPB-dF-hTp" secondAttribute="centerY" id="mlx-Tf-Sum"/>
187+
</constraints>
188+
</tableViewCellContentView>
189+
</tableViewCell>
160190
</cells>
161191
</tableViewSection>
162192
<tableViewSection headerTitle="Name" id="0YA-IY-hOV">
163193
<cells>
164194
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" selectionStyle="none" indentationWidth="10" id="kCl-ip-jc2">
165-
<rect key="frame" x="0.0" y="145" width="600" height="44"/>
195+
<rect key="frame" x="0.0" y="189" width="600" height="44"/>
166196
<autoresizingMask key="autoresizingMask"/>
167197
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="kCl-ip-jc2" id="dm4-D7-IWN">
168198
<rect key="frame" x="0.0" y="0.0" width="600" height="43"/>
@@ -174,7 +204,7 @@
174204
<tableViewSection headerTitle="Email" id="Y94-bQ-cWH">
175205
<cells>
176206
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" selectionStyle="none" indentationWidth="10" id="MCw-zF-UTn">
177-
<rect key="frame" x="0.0" y="240" width="600" height="44"/>
207+
<rect key="frame" x="0.0" y="284" width="600" height="44"/>
178208
<autoresizingMask key="autoresizingMask"/>
179209
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="MCw-zF-UTn" id="ea1-oT-1Py">
180210
<rect key="frame" x="0.0" y="0.0" width="600" height="43"/>
@@ -186,7 +216,7 @@
186216
<tableViewSection headerTitle="UID" id="Yxe-jV-t3o">
187217
<cells>
188218
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" selectionStyle="none" indentationWidth="10" id="EWm-GE-IZV">
189-
<rect key="frame" x="0.0" y="335" width="600" height="44"/>
219+
<rect key="frame" x="0.0" y="379" width="600" height="44"/>
190220
<autoresizingMask key="autoresizingMask"/>
191221
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="EWm-GE-IZV" id="ISG-G9-H8V">
192222
<rect key="frame" x="0.0" y="0.0" width="600" height="43"/>
@@ -198,7 +228,7 @@
198228
<tableViewSection headerTitle="Provider Access Token" id="E31-4c-QDa">
199229
<cells>
200230
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" selectionStyle="none" indentationWidth="10" textLabel="k9f-GH-UBQ" style="IBUITableViewCellStyleDefault" id="mdj-SS-dqJ">
201-
<rect key="frame" x="0.0" y="430" width="600" height="44"/>
231+
<rect key="frame" x="0.0" y="474" width="600" height="44"/>
202232
<autoresizingMask key="autoresizingMask"/>
203233
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="mdj-SS-dqJ" id="oCT-Ra-9l7">
204234
<rect key="frame" x="0.0" y="0.0" width="600" height="43"/>
@@ -219,7 +249,7 @@
219249
<tableViewSection headerTitle="Provider ID Token" id="GaU-wa-aFK">
220250
<cells>
221251
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" selectionStyle="none" indentationWidth="10" textLabel="M61-v5-jhZ" style="IBUITableViewCellStyleDefault" id="b45-X5-eC9">
222-
<rect key="frame" x="0.0" y="525" width="600" height="44"/>
252+
<rect key="frame" x="0.0" y="569" width="600" height="44"/>
223253
<autoresizingMask key="autoresizingMask"/>
224254
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="b45-X5-eC9" id="ofC-qT-5cz">
225255
<rect key="frame" x="0.0" y="0.0" width="600" height="43"/>
@@ -243,6 +273,7 @@
243273
<outlet property="delegate" destination="CNE-cz-Qwp" id="KFk-25-IpR"/>
244274
</connections>
245275
</tableView>
276+
<simulatedToolbarMetrics key="simulatedBottomBarMetrics"/>
246277
<connections>
247278
<outlet property="btnAuthorization" destination="bgV-bu-PcA" id="bBY-yq-fyj"/>
248279
<outlet property="cellAccessToken" destination="mdj-SS-dqJ" id="8WY-EZ-Gy6"/>

samples/objc/FirebaseUIChat/Samples/Auth/FIRAuthViewController.m

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,18 @@
1616
// limitations under the License.
1717
//
1818

19-
#import "FIRAuthViewController.h"
20-
2119
@import Firebase;
2220

21+
#import "FIRAuthViewController.h"
22+
#import "FIRCustomAuthUIDelegate.h"
23+
2324
#import <FirebaseAuthUI/FirebaseAuthUI.h>
2425
#import <FirebaseFacebookAuthUI/FIRFacebookAuthUI.h>
2526
#import <FirebaseGoogleAuthUI/FIRGoogleAuthUI.h>
2627
#import <FirebaseTwitterAuthUI/FIRTwitterAuthUI.h>
2728

29+
#import "FIRCustomAuthPickerViewController.h"
30+
2831
@interface FIRAuthViewController () <FIRAuthUIDelegate>
2932
@property (weak, nonatomic) IBOutlet UITableViewCell *cellSignIn;
3033
@property (weak, nonatomic) IBOutlet UITableViewCell *cellName;
@@ -36,6 +39,8 @@ @interface FIRAuthViewController () <FIRAuthUIDelegate>
3639

3740
@property (nonatomic) FIRAuth *auth;
3841
@property (nonatomic) FIRAuthUI *authUI;
42+
// retain customAuthUIDelegate so it can be used when needed
43+
@property (nonatomic) id<FIRAuthUIDelegate> customAuthUIDelegate;
3944

4045
@property (nonatomic) FIRAuthStateDidChangeListenerHandle authStateDidChangeHandle;
4146

@@ -51,9 +56,13 @@ - (void)viewDidLoad {
5156
self.tableView.rowHeight = UITableViewAutomaticDimension;
5257
self.tableView.estimatedRowHeight = 240;
5358

59+
self.customAuthUIDelegate = [[FIRCustomAuthUIDelegate alloc] init];
60+
5461
self.auth = [FIRAuth auth];
5562
self.authUI = [FIRAuthUI defaultAuthUI];
56-
self.authUI.delegate = self;
63+
//set AuthUI Delegate
64+
[self onAuthUIDelegateChanged:nil];
65+
5766
}
5867

5968
- (void)viewWillAppear:(BOOL)animated {
@@ -88,14 +97,14 @@ - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPa
8897

8998
- (void)updateUI:(FIRAuth * _Nonnull) auth withUser:(FIRUser * _Nullable) user {
9099
if (user) {
91-
self.cellSignIn.textLabel.text = @"YES";
100+
self.cellSignIn.textLabel.text = @"Signed-in";
92101
self.cellName.textLabel.text = user.displayName;
93102
self.cellEmail.textLabel.text = user.email;
94103
self.cellUID.textLabel.text = user.uid;
95104

96105
self.btnAuthorization.title = @"Sign Out";
97106
} else {
98-
self.cellSignIn.textLabel.text = @"NO";
107+
self.cellSignIn.textLabel.text = @"Not signed-in";
99108
self.cellName.textLabel.text = @"";
100109
self.cellEmail.textLabel.text = @"";
101110
self.cellUID.textLabel.text = @"";
@@ -108,6 +117,14 @@ - (void)updateUI:(FIRAuth * _Nonnull) auth withUser:(FIRUser * _Nullable) user {
108117

109118
[self.tableView reloadData];
110119
}
120+
- (IBAction)onAuthUIDelegateChanged:(UISwitch *)sender {
121+
BOOL isCustomAuthDelegateSelected = sender ? sender.isOn : NO;
122+
if (isCustomAuthDelegateSelected) {
123+
self.authUI.delegate = self.customAuthUIDelegate;
124+
} else {
125+
self.authUI.delegate = self;
126+
}
127+
}
111128

112129
- (IBAction)onAuthorization:(id)sender {
113130
if (!self.auth.currentUser) {
@@ -120,16 +137,22 @@ - (IBAction)onAuthorization:(id)sender {
120137

121138
#pragma mark - FIRAuthUIDelegate methods
122139

140+
// this method is called only when FIRAuthViewController is delgate of AuthUI
123141
- (void)authUI:(FIRAuthUI *)authUI didSignInWithUser:(nullable FIRUser *)user error:(nullable NSError *)error {
124142
if (error) {
125-
NSError *detailedError = error.userInfo[NSUnderlyingErrorKey];
126-
if (!detailedError) {
127-
detailedError = error;
143+
if (error.code == FIRAuthUIErrorCodeUserCancelledSignIn) {
144+
[self showAlert:@"User cancelled sign-in"];
145+
} else {
146+
NSError *detailedError = error.userInfo[NSUnderlyingErrorKey];
147+
if (!detailedError) {
148+
detailedError = error;
149+
}
150+
[self showAlert:detailedError.localizedDescription];
128151
}
129-
[self showAlert:detailedError.localizedDescription];
130152
}
131153
}
132154

155+
133156
#pragma mark - Helper Methods
134157

135158
- (NSString *)getAllAccessTokens {
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//
2+
// FIRCustomAuthPickerViewController.h
3+
// FirebaseUIChat
4+
//
5+
// Created by Yury Ramanchuk on 9/21/16.
6+
// Copyright © 2016 Firebase, Inc. All rights reserved.
7+
//
8+
9+
#import <FirebaseAuthUI/FirebaseAuthUI.h>
10+
11+
@interface FIRCustomAuthPickerViewController : FIRAuthPickerViewController
12+
13+
@end

0 commit comments

Comments
 (0)