I am trying to use FirebaseLoginViewController
to be able to authenticate my users. At the moment the code is like this:
import UIKit
class AccesoPrincipal : FirebaseLoginViewController{
var loginViewController : FirebaseLoginViewController?
var loginButton : FirebaseLoginButton?
var logoutButton : FirebaseLoginButton?
override func viewDidLoad() {
super.viewDidLoad()
let firebaseRef = Firebase(url: "https://superapp.firebaseio.com/")
self.loginViewController = FirebaseLoginViewController(ref: firebaseRef)
self.loginViewController!.enableProvider(FAuthProvider.Facebook)
//self.loginViewController.enableProvider(FAuthProvider.Google)
//self.loginViewController.enableProvider(FAuthProvider.Twitter)
self.loginViewController!.enableProvider(FAuthProvider.Password)
// Scenario 2: Set up user action based login flow
loginButton!.addTarget(self, action: "login", forControlEvents: UIControlEvents.TouchUpInside)
logoutButton!.addTarget(self, action: "logout", forControlEvents: UIControlEvents.TouchUpInside)
}
// Scenario 2: User action launches login flow, dismissal and routing handled by `FirebaseLoginViewController`
func login() {
if ((self.loginViewController!.currentUser() == nil)) {
self.presentViewController(self.loginViewController!, animated: true, completion: nil)
}
}
override func logout() {
if ((self.loginViewController!.currentUser()) != nil) {
self.loginViewController!.logout()
}
}
}
When I run the application I get the following error code:
Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Please enable at least one authentication provider in your FirebaseLoginViewController'
2016-02-16 19:39:57.725 MyApp[3623:91775] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Please enable at least one authentication provider in your FirebaseLoginViewController'
*** First throw call stack:
(
0 CoreFoundation 0x01138a14 __exceptionPreprocess + 180
1 libobjc.A.dylib 0x0429ee02 objc_exception_throw + 50
2 CoreFoundation 0x0113893d +[NSException raise:format:] + 141
3 MyApp 0x001b18f4 -[FirebaseLoginViewController viewDidLoad] + 292
4 MyApp 0x0005b7a5 _TFC16MyApp15AccesoPrincipal11viewDidLoadfS0_FT_T_ + 85
5 MyApp 0x0005bd32 _TToFC16MyApp15AccesoPrincipal11viewDidLoadfS0_FT_T_ + 34
6 UIKit 0x01fdd2ae -[UIViewController _sendViewDidLoadWithAppearanceProxyObjectTaggingEnabled] + 44
7 UIKit 0x01fe1dce -[UIViewController loadViewIfRequired] + 1384
8 UIKit 0x01fe21ed -[UIViewController view] + 35
9 UIKit 0x01e8ff94 -[UIWindow addRootViewControllerViewIfPossible] + 69
10 UIKit 0x01e906b1 -[UIWindow _setHidden:forced:] + 304
11 UIKit 0x01e90a67 -[UIWindow _orderFrontWithoutMakingKey] + 49
12 UIKit 0x01ea4118 -[UIWindow makeKeyAndVisible] + 80
13 UIKit 0x01e0c6e7 -[UIApplication _callInitializationDelegatesForMainScene:transitionContext:] + 4190
14 UIKit 0x01e13cd6 -[UIApplication _runWithMainScene:transitionContext:completion:] + 1989
15 UIKit 0x01e38ee5 __84-[UIApplication _handleApplicationActivationWithScene:transitionContext:completion:]_block_invoke3218 + 68
16 UIKit 0x01e10966 -[UIApplication workspaceDidEndTransaction:] + 163
17 FrontBoardServices 0x06377c76 __37-[FBSWorkspace clientEndTransaction:]_block_invoke_2 + 71
18 FrontBoardServices 0x0637774d __40-[FBSWorkspace _performDelegateCallOut:]_block_invoke + 54
19 FrontBoardServices 0x06395173 -[FBSSerialQueue _performNext] + 184
20 FrontBoardServices 0x063955aa -[FBSSerialQueue _performNextFromRunLoopSource] + 52
21 FrontBoardServices 0x063948a6 FBSSerialQueueRunLoopSourceHandler + 33
22 CoreFoundation 0x010526ff __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 15
23 CoreFoundation 0x0104838b __CFRunLoopDoSources0 + 523
24 CoreFoundation 0x010477a8 __CFRunLoopRun + 1032
25 CoreFoundation 0x010470e6 CFRunLoopRunSpecific + 470
26 CoreFoundation 0x01046efb CFRunLoopRunInMode + 123
27 UIKit 0x01e10206 -[UIApplication _run] + 540
28 UIKit 0x01e15bfa UIApplicationMain + 160
29 MyApp 0x00060f0c main + 140
30 libdyld.dylib 0x04d0ba21 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
I understand that the error is because an authentication provider has not been detected, however, that part is defined within the viewController
, isn't it? There isn't much documentation FirebaseUI
so it's been hard to find anything about it.
After reviewing the code, I tell you the error. The main problem is that you declared it
AccesoPrincipal
as a subclass of ,FirebaseLoginViewController
and it was instantiated directly without the necessary parameters. To solve it, I have modified the code so that it looks like this:I also leave you the modified code, since I have added the button that opens the login screen. Here it is: https://www.dropbox.com/s/jamv2eo40ixjf2k/PuertoMorelosApp_Modificada.zip?dl=0