iOS Question Facebook Login (No Firebase) - Login Event?

laguilar

Member
Licensed User
Longtime User
I need to integrate the facebook sdk but without firebase. I understand firebase is the better solution but it requires some re-work on our website that we are avoiding for now.

With what I have so far, I am able to trigger the facebook login, go through the login process and return to the application. In the Application_Active sub it is hit or miss capturing the facebook token the first time, sometimes it requires a second attempt. I think I am missing an event but it is not listed anywhere that I can find. If there is an event that fires, this would solve my problem. Also I notice when the user cancels the login, the debugger prints a line "Cancelled". Is there a similar event I can use to handle the cancelled event? One other thing is I find myself having to include the iFirebaseAuth library in order to get the project to compile, are there any steps I can take to avoid including any un-necessary libraries or is iFirebaseAuth required with iFacebook? Thanks in advance.

Here is a minified test version of what I have so far:

B4X:
'Code module
#Region  Project Attributes
    #ApplicationLabel: Test
    #Version: 1.0.0
    #iPhoneOrientations: Portrait
    #iPadOrientations: Portrait
    #Target: iPhone, iPad
    #MinVersion: 7
    
    #QueriesSchemes: fbapi
    #QueriesSchemes: fb-messenger-api
    #QueriesSchemes: fbauth2
    #QueriesSchemes: fbshareextension
    #UrlScheme: fb9999999999999999
#End Region

Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'Public variables can be accessed from all modules.
    Public App As Application
    Public NavControl As NavigationController
    Private Page1 As Page
    Private xui As XUI
    
    Private facebook As FacebookSdk
    Public LastOpenUrl As String = ""
End Sub

Private Sub Application_Active
    If LastOpenUrl <> "" Then
        Dim url As String = LastOpenUrl
        LastOpenUrl = ""
        If url.Contains("error=access_denied") = True Then
            Log("Facebook-Login-Failed (Access Denied)")
        Else
            If GetFacebookToken <> "" Then
                Log("Facebook-Login-Success")
                Log("Token:" & GetFacebookToken)
            Else
                Log("Facebook-Login-Failed (No Token)")
            End If
        End If
    End If
End Sub

Private Sub Application_OpenUrl(Url As String, Data As Object, SourceApplication As String) As Boolean
    Try
        Log("App-URL: " & Url)
        If Url.StartsWith("fb9999999999999999://authorize") = True Then
            LastOpenUrl = Url
            facebook.OpenUrl(Url, Data, SourceApplication)
        Else
            LastOpenUrl = ""
        End If
        Return False
    Catch
    End Try
End Sub

Private Sub Application_Start (Nav As NavigationController)
    NavControl = Nav
    Page1.Initialize("Page1")
    Page1.RootPanel.LoadLayout("Page1")
    NavControl.ShowPage(Page1)
    facebook.Initialize("9999999999999999")
End Sub

Private Sub GetFacebookToken As String
    Try
        Dim NaObj As NativeObject
        NaObj = NaObj.Initialize("FBSDKAccessToken")
        Return NaObj.RunMethod("currentAccessToken",Null).GetField("tokenString").AsString
    Catch
        Return ""
    End Try
End Sub

Sub Button1_Click
    facebook.SignIn
End Sub
 

laguilar

Member
Licensed User
Longtime User
When using firebase, a facebook token is not returned, only a "firebase" token. We have 2 other existing platforms with integrations using facebook login directly without firebase, and as mentioned before, it requires a bit of re-work that we want to avoid for now. Additionally there are limitations with google (free tier), its one more service to rely on. We simply want to integrate the facebook login as we have in our other 2 platforms to be consistent.

I am able to make the whole login process work as is right now, and I am able to get the correct token that I need as I have tried to validate it. All I need is a reliable event that can tell me when the token is ready. I thought it was during Application_Active but its hit or miss. Is there such an event? Can it be added? How can I go about adding it myself if I need to? I am not too familiar with swift or obj-c (the reason I use b4i) so any help is appreciated. Thanks.
 
Upvote 0

laguilar

Member
Licensed User
Longtime User
The TokenAvailable is an event in firebase. We went over this already, we do not want to use Firebase.
 
Upvote 0
Top