Skip to content

Commit 3956196

Browse files
committed
implement Facebook authentication demo
1 parent 574188f commit 3956196

File tree

2 files changed

+58
-3
lines changed

2 files changed

+58
-3
lines changed

samples/objc/FirebaseUIChat/Info.plist

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,33 @@
2323
<dict>
2424
<key>CFBundleTypeRole</key>
2525
<string>Editor</string>
26+
<key>CFBundleURLName</key>
27+
<string>REVERSED_CLIENT_ID</string>
2628
<key>CFBundleURLSchemes</key>
2729
<array>
28-
<string>REVERSED_CLIENT_ID</string>
30+
<string>REPLACE_ME__WITH_REVERSED_CLIENT_ID</string>
31+
</array>
32+
</dict>
33+
<dict>
34+
<key>CFBundleTypeRole</key>
35+
<string>Editor</string>
36+
<key>CFBundleURLName</key>
37+
<string>FACEBOOK_APP_ID</string>
38+
<key>CFBundleURLSchemes</key>
39+
<array>
40+
<string>REPLACE_ME_WITH_FACEBOOK_APP_ID</string>
2941
</array>
3042
</dict>
3143
</array>
3244
<key>CFBundleVersion</key>
3345
<string>1</string>
46+
<key>LSApplicationQueriesSchemes</key>
47+
<array>
48+
<string>fbapi</string>
49+
<string>fb-messenger-api</string>
50+
<string>fbauth2</string>
51+
<string>fbshareextension</string>
52+
</array>
3453
<key>LSRequiresIPhoneOS</key>
3554
<true/>
3655
<key>UILaunchStoryboardName</key>

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

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@
2525
// Uncomment when using frawemorks
2626
//@import FirebaseGoogleAuthUI;
2727
#import <FIRGoogleAuthUI.h>
28+
// Uncomment when using frawemorks
29+
//@import FirebaseFacebookAuthUI;
30+
#import <FIRFacebookAuthUI.h>
2831

2932
@interface FIRAuthViewController ()
3033
@property (weak, nonatomic) IBOutlet UITableViewCell *cellSignIn;
@@ -54,16 +57,27 @@ - (void)viewWillAppear:(BOOL)animated {
5457
[super viewWillAppear:animated];
5558

5659
NSString *googleId = [[FIRApp defaultApp] options].clientID;
57-
NSArray<id<FIRAuthProviderUI>> *providers = [NSArray arrayWithObjects:[[FIRGoogleAuthUI alloc] initWithClientID:googleId] , nil];
60+
NSString *facebookAppId = [self readFacebookAppId];
61+
62+
NSArray<id<FIRAuthProviderUI>> *providers = [NSArray arrayWithObjects:
63+
[[FIRGoogleAuthUI alloc] initWithClientID:googleId],
64+
[[FIRFacebookAuthUI alloc] initWithAppID:facebookAppId],
65+
nil];
5866
_authUI.providers = providers;
5967

68+
__weak FIRAuthViewController *weakSelf = self;
6069
self.authStateDidChangeHandle = [self.auth addAuthStateDidChangeListener:^(FIRAuth * _Nonnull auth, FIRUser * _Nullable user) {
61-
[self updateUI:auth withUser:user];
70+
[weakSelf updateUI:auth withUser:user];
6271
}];
6372

6473

6574
}
6675

76+
-(void)viewDidDisappear:(BOOL)animated {
77+
[super viewDidDisappear:animated];
78+
[self.auth removeAuthStateDidChangeListener:self.authStateDidChangeHandle];
79+
}
80+
6781
- (void)updateUI:(FIRAuth * _Nonnull) auth withUser:(FIRUser * _Nullable) user {
6882
self.authUser = user;
6983
if (user) {
@@ -97,5 +111,27 @@ - (IBAction)onAuthorization:(id)sender {
97111
}
98112
}
99113

114+
#pragma mark - Helper Methods
115+
116+
// Helper method to retrieve FB app ID from info.plist
117+
- (NSString *)readFacebookAppId {
118+
NSString *facebookAppId = nil;
119+
NSArray *urlTypes = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleURLTypes"];
120+
for (NSDictionary *type in urlTypes) {
121+
if ([(NSString *)type[@"CFBundleURLName"] isEqualToString:@"FACEBOOK_APP_ID"]) {
122+
NSArray *urlSchemes = type[@"CFBundleURLSchemes"];
123+
if (urlSchemes.count == 1) {
124+
facebookAppId = urlSchemes.firstObject;
125+
if (facebookAppId.length > 2) {
126+
facebookAppId = [facebookAppId substringFromIndex:2];
127+
}
128+
}
129+
break;
130+
}
131+
}
132+
133+
return facebookAppId;
134+
}
135+
100136

101137
@end

0 commit comments

Comments
 (0)