iOS Question RE: How Detect User Tap on Notification


Licensed User
Longtime User
Hello, I'm trying to detect if a user tapped on a Firebase remote notification to raise the Application_RemoteNotification event, or not. The event is raised when the message is received, either after a tap on the notification (if app is in background or killed) or direct if the app is open. I need to know if the user tapped a notification or not.

I've seen a previous thread about this, and the suggested solutions do not work. Adding flags to the _background and _active events does not work if the app has been killed, only if it was in the background.

Anyone have any ideas?


B4X founder
Staff member
Licensed User
Longtime User
Try this:
1. Add a global boolean variable named ForegroundFlag.
Private Sub Application_RemoteNotification (Message As Map, CompletionHandler As CompletionHandler)
    If ForegroundFlag = False Then
        Log("Notification clicked")
    End If
    Log($"Message arrived: ${Message}"$)
    Msgbox(Message, "Push message!")
End Sub

Private Sub Application_Active
    fm.FCMConnect 'should be called from Application_Active
    ForegroundFlag = True
End Sub

Private Sub Application_Background
    fm.FCMDisconnect 'should be called from Application_Background
    ForegroundFlag = False
End Sub
Upvote 0