iOS Question Firebase Messages does not trigger _RemoteNotification

Mike1970

Well-Known Member
Licensed User
Longtime User
Hi everyone, today i opened a project that i had finished some month ago.
In this project Firebase Messages was used.
It Works now, the problem is that the sub "Application_RemoteNotification" does not trigger anymore when the app is open, but it show the banner in overlay, like if it is closed.
The behaviour changed??

Thanks in advance D:

(iOS 14)
 

Mike1970

Well-Known Member
Licensed User
Longtime User
Ok, i found the problem.
I was using this code that, however, i'm pretty sure that before was working differently

B4X:
Dim NotificationCenter As NativeObject
NotificationCenter = NotificationCenter.Initialize("UNUserNotificationCenter").RunMethod("currentNotificationCenter", Null)
NotificationCenter.SetField("delegate", Me)

I implemented this code because i wanted to show the banner even when the app is in foreground.
BUT, I remember that before the Sub Application_RemoteNotification was fired anyway.. with that code now it's not.

Can you tell me if I remember it wrong, or something changed?
Because now the sub fires but the function that should show the banner doens not work

B4X:
Private Sub Application_RemoteNotification (Message As Map, CompletionHandler As CompletionHandler)       
    Msgbox("","") 'to know if the sub is fired'
    
    If Home.HomePg.IsInitialized Then
        CreateNotificationWithContent(Message.Get("titolo"), Message.Get("corpo"), "identifer 2", "category 1", 3000)
        Sleep(0)
        Wait For (Home.SincronizzaDBInterno) Complete (Result As Object)
    End If
    
    CompletionHandler.Complete
End Sub



Sub CreateNotificationWithContent(Title As String, Body As String, Identifier As String, Category As String, MillisecondsFromNow As Long)
    Dim ln As NativeObject
    ln = ln.Initialize("UNMutableNotificationContent").RunMethod("new", Null)
    ln.SetField("title", Title)
    ln.SetField("body", Body)
    Dim n As NativeObject
    ln.SetField("sound", n.Initialize("UNNotificationSound").RunMethod("defaultSound", Null))
    If Category <> "" Then ln.SetField("categoryIdentifier", Category)
    Dim trigger As NativeObject
    trigger = trigger.Initialize("UNTimeIntervalNotificationTrigger").RunMethod("triggerWithTimeInterval:repeats:", Array(MillisecondsFromNow / 1000, False))
    Dim request As NativeObject
    request = request.Initialize("UNNotificationRequest").RunMethod("requestWithIdentifier:content:trigger:", _
       Array(Identifier, ln, trigger))
    Dim NotificationCenter As NativeObject
    NotificationCenter = NotificationCenter.Initialize("UNUserNotificationCenter").RunMethod("currentNotificationCenter", Null)
    NotificationCenter.RunMethod("addNotificationRequest:", Array(request))
End Sub

#AdditionalLib: UserNotifications.framework
#if OBJC
#import <UserNotifications/UserNotifications.h>
@end
@interface b4i_main (notification) <UNUserNotificationCenterDelegate>
@end
@implementation b4i_main (notification)
- (void)userNotificationCenter:(UNUserNotificationCenter *)center
       willPresentNotification:(UNNotification *)notification
         withCompletionHandler:(void (^)(UNNotificationPresentationOptions options))completionHandler {
        completionHandler(UNNotificationPresentationOptionAlert | UNNotificationPresentationOptionSound );
   }
#End If


Thanks
 
Upvote 0
Top