Background push notifications in Xamarin

Please consider the following problem:

I use the following plugin for Xamarin to execute push notifications, I am trying to run this on both iOS and Androids.

https://github.com/CrossGeeks/FirebasePushNotificationPlugin

I also use the following PHP code to send push notifications to a device from a website.

$fields = array ( 'to' => $ID->notification_token, "content_available" => true, 'priority'=>10, 'notification' => array('title' => 'You have a new message', 'body' => 'Hooray', 'sound'=>'default', 'vibration'=>'default'), ); $headers = array ( 'Authorization: key=' . PUSH_NOTIFICATION_API_ACCESS_KEY, 'Content-Type: application/json', ); $ch = curl_init(); curl_setopt( $ch,CURLOPT_URL, 'https://android.googleapis.com/gcm/send' ); curl_setopt( $ch,CURLOPT_POST, true ); curl_setopt( $ch,CURLOPT_HTTPHEADER, $headers ); curl_setopt( $ch,CURLOPT_RETURNTRANSFER, true ); curl_setopt( $ch,CURLOPT_SSL_VERIFYPEER, false ); curl_setopt( $ch,CURLOPT_POSTFIELDS, json_encode( $fields ) ); $result = curl_exec($ch ); curl_close( $ch ); echo $result; 

Now the problem is in iOS. I find that the push notification is reliable and works fine when the application is in the foreground, but as soon as I close it (or lock the screen), they stop passing until I precede it again, all notifications sent at that the time when they were in the background, everything immediately passes.

I have included background processes in my info.plist , as per the Getting Started plugins.

I tried changing the content_availiable to content-availiable , also moving it to the notification array, also setting its value to true , 'true' , 1 and '1'

I also tried adding "alert" => "" both the notification and the general payload, however I still can't get it to work, outside the unlocked foreground state.

I also notice that nothing happens in the actual list of notifications (popped from the top of the screen), the only way I know that receiving notifications is to play a specific sound file as it arrives and is recorded in the debug log.

Any help would be appreciated, thanks for your time.

+5
source share
2 answers

Make sure your Json post has the attributes {"content-available" : "1", "alert" : ""} if you want it to display on iOS when it is not running in the background.

Like Android, push notifications are really not 100% real, there are device-specific obstacles that can block your notification.

Firebase may have a β€œsend test” feature (I am currently using the Azure Push Hub) so you can check if your Json message is configured correctly.

+4
source

I will try to send a data message instead

 $fields = array ( 'to' => $ID->notification_token, "content_available" => true, 'priority'=>10, 'data' => array('title' => 'You have a new message', 'body' => 'Hooray', 'sound'=>'default', 'vibration'=>'default'), ); 
+2
source

Source: https://habr.com/ru/post/1274592/


All Articles