Sending firebase requests over rest client
Posted on 08 Mayıs 2018 in Programlama by admin
First of all a rest client should be installed to pc. You may use “advanced rest client” extension for chrome browser for its simplicity or postman.
Following headers should be added:
Content-Type application/json Authorization key=your server key or legacy key
Fcm uses following url to accept http queries:
https://fcm.googleapis.com/fcm/send
And at this point header configuration ui should be like similar to one below:
Server key could be obtained from firebase console page. It is located at “project settings”>>”cloud messaging” path. Following screenshot is added for illustration:
For sending push notification rest client body field should be set too. You may use following data just to trigger push notification. Be careful that “To” field should contain device token generated by firebase. It might be printed at appdelegate file at following function
func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) { if let t = Messaging.messaging().fcmToken { print(t) ApplicationManager.sharedInstance.deviceTokenId = t } }
Following screenshot illustrates used body field at rest client
Also you may use following content just for copy/paste:
{ "to": "/topics/global", // global is your topic "notification" : { "body" : "great match!", "content_available" : true, "priority" : "high", "title" : "Portugal vs. Denmark" }, "data" : { "body" : "great match!", "content_available" : true, "priority" : "high", "title" : "Portugal vs. Denmark" } }
or
{ "to" : "d2-mL59n79k:APA91bHn3kQXl1SIJV37LvtdxKSvpCGAd5kXYpzGnXEzq0XG0G0tPJQXO5D3-90v5sX3VLEKMouVAMah3p47YATH_4_FUgC5x1fP9f55LtEwdukpsLtUsbDNP4toZ0w6C7_37f7LGNucr25ZWxvrC6fztqB2JdiNNR", "notification":{ "Nick" : "Mario", "body" : "çözümlenemeyen mesaj", "Room" : "PortugalVSDenmark", "priority": "high", "content_available": true, "sound" : "incoming_call.mp3", "time_to_live" : 4 } }
One more note, if you want to send data message instead of notification message from firebase make sure following parameters were sent
<strong>"content_available": true,</strong> <strong>"sound" : "classic_phone.mp3",</strong> "data" :{ ... }
Thats all. If you wonder how to configure iOS xcode side then there is a great article here:
You can download this tutorial in pdf format here:
Push Notifications Tutorial: Getting Started
Happy coding 🙂