iOS Question Firebase notifications on iOS

cooperlegend

Active Member
Licensed User
Longtime User
My App received firebase message notifications from my PHP code to do updates in the App. This works fine, the App can subscribe and unsubscribe from the service. BUT , If the App crashes and does not unsubscribe from firebase the Phone will continue to get these messages and display these on the screen. Is there any way to send firebase messages that only work with the App and not display on the phone (if not absorbed by the App) ?
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
1. You can send "silent push notifications": https://www.b4x.com/android/forum/threads/silent-push-notifications.56016/#content
These notifications start your app and you can then choose what to do with the notification. The problem with them is that they are quite unreliable.

2. If you only want to show a notification when your app is open then don't use push notifications. Make your app connect to your server and check for updates.
 
Upvote 0

cooperlegend

Active Member
Licensed User
Longtime User
Thanks Erel

Silent push notifications should work for me, what do I need to modify in my PHP code to make this work ?

p.s. I still need it to send "Title" and "Body" as these trigger routines in the Apps

Firebase:
        if(strStartsWith($topic, 'ios_')){
            // B4i
            $badge = 0;
            $iosalert = array('title' => $dataArray['title'], 'body' => $dataArray['body']);
            $customMessageFields['notification'] = $iosalert;
           
            $customMessageFields['apns'] = array(
                'headers' => array('apns-priority' => '10'),
                'payload' => array('aps' => array('sound' => 'default', 'badge' => $badge))
            );
           
            $data->setCustomData($dataArray, $customMessageFields);
            $fcmClient->build($recipient, null, $data);
           
            return $fcmClient->fire();
        }
 
Upvote 0
Top