iOS Question Problem in firebase push notification

Pooya1

Active Member
Licensed User
I configure firebase in my app well and it is working
But when i am in app,push not receive but when i leave app,notification receive well
Also when i click on notification and it is going to app,again cannot raise remotenotification
I send push with firebase and b4j

My code is :

B4X:
Sub ActivePushNotification
    Dim analytics As FirebaseAnalytics
    analytics.Initialize
    App.RegisterUserNotifications(True, True, True)
    App.RegisterForRemoteNotifications
    fm.Initialize("fm")
End Sub

Private Sub Application_RemoteNotification (Message As Map, CompletionHandler As CompletionHandler)
   
    Dim sType As String
    sType    =    Message.Get("type")
 
    If sType.ToLowerCase = "null" Then Return
 
    Dim notifi As Notifications
    notifi.Initialize
    notifi.AddNotification(Message.Get("body"),DateTime.Now)
   
    CompletionHandler.Complete
   
End Sub

Private Sub fm_FCMConnected
    fm.SubscribeToTopic("users")
End Sub

Private Sub Application_Active
    GetPushData
    fm.FCMConnect
End Sub

Sub GetPushData
   
    If App.LaunchOptions.IsInitialized And _
     App.LaunchOptions.ContainsKey("UIApplicationLaunchOptionsRemoteNotificationKey") Then
        Dim data As Object = App.LaunchOptions.Get("UIApplicationLaunchOptionsRemoteNotificationKey")
        Dim no As NativeObject = App
        no.GetField("delegate").RunMethod("application:didReceiveRemoteNotification:", _
       Array(App, data))
    End If
   
End Sub
 

Pooya1

Active Member
Licensed User
It is not related to the B4i version.

You should send the messages with B4J code. The topic should start with ios_.

See the tutorial.
I didn't use ios_for starting topic
I dont have receive push notification
My problem is that RemoteNotification not fire
 
Upvote 0

Pooya1

Active Member
Licensed User
I didn't use ios_for starting topic
I dont have receive push notification
My problem is that RemoteNotification not fire
Also i use B4j SendingTools
I think problem is profile (however i receive push notification)
 
Upvote 0

Pooya1

Active Member
Licensed User
I can use push and get in app but it is working in sample source and in my app same source not working
What is affect my app firebase?
 
Upvote 0

Pooya1

Active Member
Licensed User
I'm sorry Erel for many topic
I found problem
In my app,Application_Active not fire when app started and i force to use callsubdelay application_active event and i can receive push now
But it is not correct way
Maybe is it bug?
 
Upvote 0

Pooya1

Active Member
Licensed User
Application_Active should be called when the app becomes active. This includes when it is started.
I know but i realized Application_Active not raised and also firebase cannot connect and subscribe also i could not receive push
Now i call Application_Active with CallSubDelay and it is working now
But when application goto background,Application_Background not raised and if i dont call firebase.Disconnect also i cannot receive push in background
I test push in simple source and it is working complete but in my app not working
I think one library make problem for application event
My code for Main module is :
B4X:
'Code module
#Region  Project Attributes
    #ApplicationLabel: Tavos
    #Version: 1.0.0
    'Orientation possible values: Portrait, LandscapeLeft, LandscapeRight and PortraitUpsideDown
    #iPhoneOrientations: Portrait
    #iPadOrientations: Portrait
    #Target: iPhone, iPad
    #ATSEnabled: False
    #MinVersion: 8
    #AppFont: font.ttf
    #AppFont: fontb.ttf
    #AppFont: fontavosium.ttf
   
    #PlistExtra:<key>NSContactsUsageDescription</key><string>Contact</string>
    #PlistExtra:<key>NSPhotoLibraryUsageDescription</key><string>Picture</string>
    #PlistExtra:<key>NSCameraUsageDescription</key><string>Camera</string>
    #PlistExtra:<key>NSMicrophoneUsageDescription</key><string>Record video</string>
    #PlistExtra:<key>UIBackgroundModes</key><array><string>location</string><string>audio</string><string>remote-notification</string></array>
    #PlistExtra:<key>NSLocationWhenInUseUsageDescription</key><string>Location</string>
       #PlistExtra:<key>NSLocationUsageDescription</key><string>Used to display the current navigation data.</string>
    #PlistExtra: <key>UIApplicationShortcutItems</key><array><dict><key>UIApplicationShortcutItemType</key><string>cart</string><key>UIApplicationShortcutItemTitle</key><string>Cart</string></dict><dict><key>UIApplicationShortcutItemType</key><string>profile</string><key>UIApplicationShortcutItemTitle</key><string>Profile</string></dict><dict><key>UIApplicationShortcutItemType</key><string>shop</string><key>UIApplicationShortcutItemTitle</key><string>Shop</string></dict><dict><key>UIApplicationShortcutItemType</key><string>search</string><key>UIApplicationShortcutItemTitle</key><string>Search</string></dict></array>
   
    #CertificateFile: ios_development.cer
    #ProvisionFile: user.mobileprovision
    #PlistExtra: <key>UIBackgroundModes</key><array><string>remote-notification</string></array>
    #Entitlement: <key>aps-environment</key><string>development</string>
   
#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 txtusername As TextField
    Private txtpassword As TextField
    Private btnlogin As Button
    Private MyToast As MyToastMessageShow
    Private MyProgress As MyProgessDialogShow
    Private lblshow As Label
    Private username,password As String
    Private lblregister As Label
    Private pnlcontainer As Panel
    Private push As FirebaseMessaging
    Private logo As Label
    Private ana As FirebaseAnalytics
End Sub

Private Sub Application_Start (Nav As NavigationController)
   
    ana.Initialize
   
    NavControl = Nav
    NavControl.NavigationBarVisible = False
    Library.SettingManager.Initialize
   
    push.Initialize("push")
   
    App.RegisterUserNotifications(True,True,True)
    App.RegisterForRemoteNotifications
   
    CallSubDelayed(Me,"Application_Active")
   
    GetPushData
   
    Dim no As NativeObject = NavControl
    no.GetField("navigationBar").RunMethod("setTintColor:", Array(no.ColorToUIColor(Colors.Gray)))
   
    QuickActions.StartSettings
   
    Dim username,password As String
    username    =    Library.SettingManager.GetString("username")
    password    =    Library.SettingManager.GetString("password")
   
    If username.Length > 4 And password.Length > 4 Then
        Configuration.Username    =    username
        Configuration.Password    =    password
        actShop.Show
        Return
    End If
   
    Page1.Initialize("Page1")
    Page1.RootPanel.LoadLayout("frmlogin")
    NavControl.ShowPage(Page1)
    Page1.RootPanel.Color = Colors.White
    logo.Font                            = Library.GetFontIcon(logo.Font.Size)
    Show

End Sub

Sub Page1_Resize(Width As Int,Height As Int)
   
    MyToast.Initialize(Page1.RootPanel,Me)
    MyToast.ChangedStatusColor = False
    MyProgress.Initialize(Page1.RootPanel)
   
End Sub

Sub Show
   
    Dim username,password As String
    username    =    Library.SettingManager.GetString("username")
    password    =    Library.SettingManager.GetString("password")
   
    txtusername.Color = Colors.RGB(250, 250, 250)
    txtpassword.Color = Colors.RGB(250, 250, 250)
   
    username    =    Library.SettingManager.GetString("username")
    password    =    Library.SettingManager.GetString("password")
   
    If Library.SettingManager.GetString("username").Length > 0 Then
        txtusername.Text = Library.SettingManager.GetString("username")
    End If
   
    If Library.SettingManager.GetString("password").Length > 0 Then
        txtpassword.Text = Library.SettingManager.GetString("password")
    End If
   
    Dim cs As CSBuilder
    cs.Initialize
    cs.Font(Font.CreateNew2("iranyekanmobile",lblregister.Font.Size)).Color(Colors.RGB(173,173,173)).Append("؟").Pop
    cs.Font(Font.CreateNew2("iranyekanmobile",lblregister.Font.Size)).Color(Colors.RGB(125,125,125)).Append("").PopAll
    lblregister.AttributedText = cs
   
End Sub

Sub txtusername_TextChanged (Old As String, New As String)

    If txtusername.Text.Length > 1 And txtpassword.Text.Length > 1 Then
        Library.EnableButton(btnlogin)
    Else
        Library.DisableButton(btnlogin)
    End If
   
End Sub

Sub txtpassword_TextChanged (Old As String, New As String)
   
    If txtusername.Text.Length > 1 And txtpassword.Text.Length > 1 Then
        Library.EnableButton(btnlogin)
    Else
        Library.DisableButton(btnlogin)
    End If
   
End Sub

Sub lblregister_Click
    NavControl.RemoveCurrentPage
    actRegister.Show
End Sub

Sub btnlogin_Click

    Page1.ResignFocus
   
    Wait For (Library.CheckInternet) Complete(State As Boolean)
    If State = False Then
        NavControl.RemoveCurrentPage
        actNoInternet.Show
        Return
    End If
   
    If txtusername.Text.Length < 5 Then
        Return
    End If
   
    If Regex.IsMatch("\w{5,}",txtusername.Text) = False Then
        Return
    End If
   
    If txtpassword.Text.Length < 5 Then
        Return
    End If

    Configuration.Username    =    txtusername.Text
    Configuration.Password    =    txtpassword.Text

    Dim ws2 As OnstagramWS
    ws2.Initialize(Me)
    ws2.User_Login("Login_User")
   
End Sub

Sub Login_User(Data As Map,Status As Boolean)
   
    MyProgress.HideProgress
   
    If Status = False Then
       
        If Data.Get("data") = "NOT_FOUND_USER" Then

           
        Else If Data.Get("status_code") = "INCORRECT_USERNAME" Or Data.Get("status_code") = "INCORRECT_PASSWORD" Then

       
        Else If Data.Get("status_code") = "NOT_VERIFY_USER" Then
   
       
        Else If Data.Get("status_code") = "BLOCK_USER" Then

       
        Else If Data.Get("status_code") = "NOT_ENABLE_USER" Then
   
       
        Else If Data.Get("status_code") = "NOT_ACTIVE_USER" Then
   
           
        Else
        End If
       
        Return
    End If
   
    If Status = True Then
        Library.SettingManager.SetString("username",txtusername.Text)
        Library.SettingManager.SetString("password",txtpassword.Text)
        actShop.Show
    End If
   
End Sub

Sub OnShowLoginForm_Event
    Library.SettingManager.SetString("username",txtusername.Text)
    Library.SettingManager.SetString("password",txtpassword.Text)
    NavControl.RemoveCurrentPage
    QuickActions.Logined    =    True
    actShop.Show
End Sub

Sub lblshow_Click
   
    If txtpassword.Tag = "" Then
        txtpassword.PasswordMode = False
        txtpassword.Tag = "show"
        lblshow.TextColor = Colors.RGB(144,144,144)
    Else
        txtpassword.PasswordMode = True
        lblshow.TextColor = Colors.RGB(36,36,36)
        txtpassword.Tag = ""
    End If
   
End Sub

Sub lblforget_Click
    NavControl.RemoveCurrentPage
    actForget.Show
End Sub

Sub lblinstagram_Click
   
End Sub

Sub StopConnection
    MyProgress.HideProgress
End Sub

Sub btnclose_Click
    NavControl.RemoveCurrentPage
End Sub

Sub ShowNoInternet
    MyProgress.HideProgress
End Sub

Private Sub Application_Background
    QuickActions.InactiveSettings
    push.FCMDisconnect
End Sub

#region FirebaseMessage Service

Sub Application_RemoteNotification (Message As Map, CompletionHandler As CompletionHandler)

    Dim sType As String
    sType    =    Message.Get("type")
    If sType.ToLowerCase = "null" Then Return
    Dim notifi As Notifications
    notifi.Initialize
    notifi.AddNotification(Message.Get("body"),DateTime.Now)
    If actShop.StateVisiablePage Then CallSubDelayed2(actShop,"UpdateNotification",notifi.GetNotificationCount)
   
    CompletionHandler.Complete
   
End Sub

Sub Application_PushToken (Success As Boolean, Token() As Byte)

End Sub

Sub push_FCMConnected
    push.SubscribeToTopic("users")
    push.SubscribeToTopic("ios_general")
    push.SubscribeToTopic(Library.GetDeviceID)
End Sub

Sub SubscribeToTopics2(Topic As String,State As Boolean)
    If State Then
        push.SubscribeToTopic(Topic)
    Else
        push.UnsubscribeFromTopic(Topic)
    End If
End Sub

Sub Application_Active
    push.FCMConnect
    QuickActions.ActiveSettings
End Sub

Sub GetPushData
   
    If App.LaunchOptions.IsInitialized And _
     App.LaunchOptions.ContainsKey("UIApplicationLaunchOptionsRemoteNotificationKey") Then
        Dim data As Object = App.LaunchOptions.Get("UIApplicationLaunchOptionsRemoteNotificationKey")
        Dim no As NativeObject = App
        no.GetField("delegate").RunMethod("application:didReceiveRemoteNotification:", _
       Array(App, data))
    End If
   
End Sub

#End Region

Sub Application_ShortcutItemClicked (ItemType As String)
   
    If QuickActions.Logined    =    True Then
        If ItemType = "cart" Then
            actCart.Show
        Else if ItemType = "profile" Then
            actProfile.Show
        Else if ItemType = "search" Then
            actSearch.Show
        Else if ItemType = "shop" Then
            actShop.Show
        End If
        Return
    End If
   
    actShop.QuickActionType = ItemType
   
End Sub
 
Last edited:
Upvote 0

Pooya1

Active Member
Licensed User
Try to reproduce it in a small project and upload the project.
small project is working Erel,but when i use it in my app,not working because application_active and background not raised
Actually my problem is not raise application events now
 
Upvote 0
Top