iOS Question The application does not receive push notifications in the Background [solved]

ThePuiu

Active Member
Licensed User
Longtime User
I inserted the code offered as an example in my application so I can receive push notifications. If the application is in Foreground, the notifications come immediately. If the application is in the Background (even without being closed), the notifications do not reach and are obviously not displayed on the screen. If the application reaches Foreground again, the notifications arrive and the message with their content is displayed. Do you have any idea what's wrong?
B4X:
Private Sub fm_FCMConnected
    Log("FCMConnected")   
    fm.SubscribeToTopic("ios_90796f14-7c14-4ce5-ac7e-dfd183ea7a59")
End Sub
Private Sub Application_RemoteNotification (Message As Map, CompletionHandler As CompletionHandler)   
    Log($"Message arrived: ${Message}"$)
    Msgbox(Message, "Push message!")
    CompletionHandler.Complete
End Sub
Private Sub Application_Active
    fm.FCMConnect 'should be called from Application_Active
End Sub

Private Sub Application_Background
    fm.FCMDisconnect 'should be called from Application_Background
End Sub

Sub Application_PushToken (Success As Boolean, Token() As Byte)
    Log($"PushToken: ${Success}"$)
    Log(LastException)
End Sub
 

Semen Matusovskiy

Well-Known Member
Licensed User
Did you describe UIBackgroundModes, something like
#PlistExtra : <key>UIBackgroundModes</key><array><string>remote-notification</string><string>location</string></array> ?
 
Upvote 0

ThePuiu

Active Member
Licensed User
Longtime User
yes (I forgot to specify):
B4X:
#PlistExtra: <key>UIBackgroundModes</key><array><string>remote-notification</string></array>

How I tested: I installed the application in release mode, I opened it and then sent it to Background. From the web application I sent a notification to that device. The notification does not arrive and nothing is seen in the Log... If I bring the application to Foreground, the message sent previously will rise immediately.
 
Upvote 0

Semen Matusovskiy

Well-Known Member
Licensed User
IOS allows to receive pushes even in terminated state. Another question, that this requires some additional efforts and IOS works not like Android.

The behaviour, which you describes, is expected. Application_RemoteNotification events, as I remember, occur in Foreground only.
Meanwhile background notifications should appear in Notification Center immediately, Try to reconstruct an app a little: use FCMConnect, when application starts only, remove FCMDisconnect.
 
Upvote 0

ThePuiu

Active Member
Licensed User
Longtime User
I tried to remove fm.FCMDisconnect and the result is the same: nothing appears anywhere. I would be pleased if the notification appeared in the Notification Center or at least one number appeared in the badge...

It is my first more complex iOS application and I don't know yet what to expect. Unfortunately, for now, I find whole thing quite unstable.... a lot of errors whose cause I do not understand.

With your help I hope to get over it!
 
Upvote 0

Semen Matusovskiy

Well-Known Member
Licensed User
Ok, I cut a fragment from my app. How to check
1) B4I
a) put your GoogleService-info.plist into Files\Special
b) change bundle id and use own certificate

2) B4J
Change API-Key
 

Attachments

  • notifications.zip
    2.7 KB · Views: 192
Upvote 0

ThePuiu

Active Member
Licensed User
Longtime User
To send notifications I use a routine from the .NET application. The code used went smoothly for B4A applications...

Thanks Semen for the example provided! With your help I solved the problem!
 
Upvote 0
Top