Push notifications in xamarin with php

0

Friends we are working on an app in xamarin.forms cross platform, the issue is that you want to implement push notifications for both the android project and the ios, the issue is that you are not working with the notification service of azure, since the app is a complement of the base system that is all built in php, the question is how can I implement push notifications in xamarin with php without using azure? it's possible? and how would it be done? since all the documentation I have found is about azure and I think it is possible to do it with php, someone can help me with this.

    
asked by Jhonny Luis 27.09.2018 в 22:18
source

2 answers

1
  

is it possible?

Of course, you do not need to use Azure for push notifications (I assume you're talking about the Azure Notification Hub service).

  

How can I implement push notifications in xamarin with php without using azure?

You can check this link where this question has already been answered so you can see how the integration works: link

From your server you must connect to the Firebase notification service following the official documentation:

link

link

And to receive notifications, you can use this plugin for Xamarin.Forms link and follow its documentation.

    
answered by 02.10.2018 в 22:09
0

If possible.

You must set up your application in Google Firebase: link

To send the notification from PHP you must use CURL, something similar to the following code:

public function SendGlobalNotification($Message)
{
        $url = 'https://fcm.googleapis.com/fcm/send';

                                $headers = array(
                                    'Authorization: key=' . 'AAAAZjH-iIw:APA91bGc1NPUOJfHlsgu_f8SxTvisH86-4QEZxun5l6Mn6vbv9XwTjesELMAXR2vlGnCuX6znafH8SsX5bagh9-Rf4SUgmTpNPZZ73meSfFfG5zTzqZuy9GSS2t1zCREUKtv0HX-gEEp',
                                    'Content-Type: application/json'
                                );

        $msg = array('body' => $Message);

        $fields = array
                    (
                        'to'        => '/topics/user',
                        'notification'  => $msg
                    );

        // Open connection
        $ch = curl_init();

        // Set the url, number of POST vars, POST data
        curl_setopt($ch, CURLOPT_URL, $url);

        curl_setopt($ch, CURLOPT_POST, true);
        curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

        // Disabling SSL Certificate support temporarily
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

        curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields));

        // Execute post
        $result = curl_exec($ch);

        // Close connection
        curl_close($ch);
}

And to receive notification in Mobile Applications you must use the Google Firebase library: link

    
answered by 01.11.2018 в 20:47