2222#import < FBSDKLoginKit/FBSDKLoginKit.h>
2323#import < FirebaseAuthUI/FIRAuthUIErrorUtils.h>
2424
25- /* * @var kBundleFileName
26- @brief The name of the bundle containing Facebook auth provider assets/resources.
27- */
28- static NSString *const kBundleFileName = @" FirebaseFacebookAuthUIBundle.bundle" ;
29-
3025/* * @var kTableName
3126 @brief The name of the strings table to search for localized strings.
3227*/
3732 */
3833static NSString *const kSignInWithFacebook = @" SignInWithFacebook" ;
3934
35+ /* * @var kFacebookAppId
36+ @brief The string key used to read Facebook App Id from Info.plist.
37+ */
38+ static NSString *const kFacebookAppId = @" FacebookAppID" ;
39+
40+ /* * @var kFacebookDisplayName
41+ @brief The string key used to read Facebook App Name from Info.plist.
42+ */
43+ static NSString *const kFacebookDisplayName = @" FacebookDisplayName" ;
44+
4045@implementation FIRFacebookAuthUI {
4146 /* * @var _loginManager
4247 @brief The Facebook login manager.
@@ -49,24 +54,17 @@ @implementation FIRFacebookAuthUI {
4954 FIRAuthProviderSignInCompletionBlock _pendingSignInCallback;
5055}
5156
52- - (instancetype )init {
53- @throw [NSException exceptionWithName: @" Attempt to call unavailable initializer."
54- reason: @" Please call the designated initializer."
55- userInfo: nil ];
56- }
57-
58- - (instancetype )initWithAppID : (NSString *)appID permissions : (NSArray *)permissions {
57+ - (instancetype )initWithPermissions : (NSArray *)permissions {
5958 self = [super init ];
6059 if (self != nil ) {
6160 _scopes = permissions;
62- [FBSDKSettings setAppID: appID];
63- _loginManager = [[FBSDKLoginManager alloc ] init ];
61+ [self configureProvider ];
6462 }
6563 return self;
6664}
6765
68- - (instancetype )initWithAppID : ( NSString *) appID {
69- return [self initWithAppID: appID permissions : @[ @" email" ]];
66+ - (instancetype )init {
67+ return [self initWithPermissions : @[ @" email" ]];
7068}
7169
7270/* * @fn frameworkBundle
@@ -77,13 +75,7 @@ + (NSBundle *)frameworkBundle {
7775 static NSBundle *frameworkBundle = nil ;
7876 static dispatch_once_t predicate;
7977 dispatch_once (&predicate, ^{
80- NSString *mainBundlePath = [[NSBundle mainBundle ] resourcePath ];
81- NSString *frameworkBundlePath =
82- [mainBundlePath stringByAppendingPathComponent: kBundleFileName ];
83- frameworkBundle = [NSBundle bundleWithPath: frameworkBundlePath];
84- if (!frameworkBundle) {
85- frameworkBundle = [NSBundle mainBundle ];
86- }
78+ frameworkBundle = [NSBundle bundleForClass: [self class ]];
8779 });
8880 return frameworkBundle;
8981}
@@ -214,4 +206,22 @@ - (void)callbackWithCredential:(nullable FIRAuthCredential *)credential
214206 }
215207}
216208
209+ /* * @fn callbackWithCredential:error:
210+ @brief Validates that Facebook SDK data was filled in Info.plist and creates Facebook login manager
211+ */
212+ - (void )configureProvider {
213+ NSBundle *bundle = [[self class ] frameworkBundle ];
214+ NSString *facebookAppId = [bundle objectForInfoDictionaryKey: kFacebookAppId ];
215+ NSString *facebookDisplayName = [bundle objectForInfoDictionaryKey: kFacebookDisplayName ];
216+
217+ if (!(facebookAppId && facebookDisplayName)) {
218+ [NSException raise: NSInternalInconsistencyException
219+ format: @" Please set FacebookAppID, FacebookDisplayName, and\n URL types > Url "
220+ @" Schemes in `Supporting Files/Info.plist` according to "
221+ @" https://developers.facebook.com/docs/ios/getting-started" ];
222+ }
223+
224+ _loginManager = [[FBSDKLoginManager alloc ] init ];
225+ }
226+
217227@end
0 commit comments