iOS Question Push Notifications and UNC class conflict

Andrew (Digitwell)

Well-Known Member
Licensed User
Longtime User
I have an iOS app which uses push notifications to indicate when there is a new message in a chat window.

If the app is active, if the user is in the chat window, the window will refresh (downloading the new messages) and if not not in the chat window, a toast message is shown.
If the app is inactive, the OS displays the Push Notification

This all works fine.

I saw that @Erel had created a new class to support iOS user Notifications, https://www.b4x.com/android/forum/threads/usernotificationcenter-class.117925/ so I decided to use this instead of the toast.

This is when I ran into problems.

MAIN module:
Private Sub Application_RemoteNotification (Message As Map, CompletionHandler As CompletionHandler)
    ReleaseLog.DoReleaseLog($"Message arrived: ${Message}"$)
    FirebaseMessaging.Process_message(Message)
    CompletionHandler.Complete
End Sub

FirebaseMessaging:
Sub Process_message (Message As Map)
    ReleaseLog.DoReleaseLog("Message arrived")
    ReleaseLog.DoReleaseLog($"Message data: ${Message}"$)
    If (Message.Size = 0) Then
        Log("Message is empty")
    Else
        If (ProcessMessage(Message)) Then

            ' These lines stop push notifications working
            Private UNC As UserNotificationCenter
            UNC.Initialize
            UNC.CreateNotificationWithContent(Message.Getdefault("title","title"),Message.Getdefault("body","body"),Starter.gstrAppID,Starter.gstrAppID,8000)
            UNC.RemovePendingNotifications(Array(Starter.gstrAppID))
           
            ' Original code which works
            'Starter.hud.ToastMessageShow(Message.Getdefault("body","body"),False)
        End If
    End If
End Sub

NOTE:The ProcessMessage function checks if the chat window is open, forces a refresh and returns true, else returns false.

What happens is this:
Start the app, if you go to the chat window, then push notifications come through, and the chat window is refreshed.
Move off the chat window to anywhere else in the app, initially the User Notification is displayed. But then Application_RemoteNotification stops being called and the OS starts displaying the push notification as if the app is in the background.

Further testing reveals that you don't actually need to go to the chat window for this to happen.

It seems that calling the UserNotificationCenter code is preventing Push Notifications from being delivered.

Any Ideas?
 

Andrew (Digitwell)

Well-Known Member
Licensed User
Longtime User
Ok,
But it seems strange that any push notification that comes in AFTER I have used this call no longer arrives at the app. Which means that I can no longer handle Push Notifications silently.

Is there a way to turn this behaviour off. If not I will stick with toast.
 
Upvote 0
Top