rdelrosario / xamarin-plugins

Cross platform Xamarin & Windows plugins for PCLs
MIT License
178 stars 161 forks source link

Firebase Cloud Messaging Support #85

Open shivangsanghi opened 8 years ago

shivangsanghi commented 8 years ago

Hi, Are you going to update plugin to support FCM?

erickriva commented 7 years ago

FCM uses same structure of GCM, so all you need is: create a project on Firebase. It also has a SenderId and a Server Key (to put on notification hub, if it is used) like GCM, the usage will be the same. To access this info, access your project page, click on wrench icon > "Project Configuration", and select "Cloud Messaging" tab.

iManchaDev commented 7 years ago

@erickriva I succeed in sending the notification, only issue is the title doesn't show because FireBase uses a body field:

"gcm.notification.body": "testing push"

How do we change this, as my notifications are pushing blanks?

TimesliceTechnologies commented 7 years ago

Put your message and title in their own key/value pairs in your notification instead of the default message label / text fields.

The plugin will be looking for "title" and "message" key/values in the notification rather than "gcm.notificaiton.body". If you are testing with firebase console to send test notifications there's an area near the bottom "Advanced" where you can add key/value pairs. Alternatively you can set the keys the plugin should look for using its methods in the AppDelegate just after you call CrossPushNotification.Initialize() EG: CrossPushNotification.NotificationContentTextKey = "gcm.notification.body"; and CrossPushNotification.NotificationContentTitleKey = "title";

iManchaDev commented 7 years ago

Thanks I figured that out after many hours, was trying to call : CrossPushNotification.NotificationContentTextKey = "gcm.notification.body";

from the Forms PCL project instead of Android, reason why I wasn't seeing the public strings.

Dumb question, do I still need to follow the below procedure for iOS to receive notifications, or is it built into this plugin?

https://developer.xamarin.com/guides/ios/application_fundamentals/notifications/remote_notifications_in_ios/

TimesliceTechnologies commented 7 years ago

Can't authoritatively answer your question on the iOS implementation, but generally I believe the plugin will handle the reception of the iOS notification and you will get that notification in the PCL. You'll have to handle whatever you do with it in the PCL. I'm currently in the testing phase and building our push service to test the plugin. You definitely have to do all the other things in that article with respect to setting up the apple certificate etc in your app.

iManchaDev commented 7 years ago

@TimesliceTechnologies did you manage to get iOS push working?

When I call :

CrossPushNotification.Current.Register();

It generates a token and prints it in the console as below:

Token : a56093f11842e34469ce49fe01d7a0cd1ddd0986f347587991beb11e46bfbcf2

however when I try sending a notification to iOS device with that token, it fails with the following error:

Invalid Registration Token - Check the token format. When sending to all iOS devices, even though there's only one at the moment for testing, the summary shows : sent '0'

I assume that it never registers with the Firebase server in the first place?

I have uploaded the p12 certificates to Firebase, etc.

If you have any information, pleeeeeassssssse share.

TimesliceTechnologies commented 7 years ago

FireBase is for Google push notififcations. For iOS you need to push through APNS rather than GCM / Firebase. Is there some facility in Firebase that lets you push iOS notifications? If so let me know where that is. I've just finished up creating a server using PushSharp for pushing notifications from our systems to both GCM (Firebase) and APNS (Apple). I can confirm that it IS possible to get all these pieces working. I'm not clear on how you are pushing your notifications via a google system (firebase) to Apple's push network. Either I'm not aware of that feature in Firebase, or you are trying to do something that's not possible. Firebase has the Firebase console that lets you send notifications, but as far as I know that's only for Android clients. I haven't found a similar console for devs in Apple's system.

iManchaDev commented 7 years ago

Yes in Firebase you can add the iOs version of your app, add it under projects overview - it give options for Android, iOS and We.

Once the project is added, navigate to setting-cloud messaging tab and then upload the development and production certificates specifically for iOS.

From: TimesliceTechnologies [mailto:notifications@github.com] Sent: Saturday, February 25, 2017 9:49 PM To: rdelrosario/xamarin-plugins Cc: iManchaDev; Comment Subject: Re: [rdelrosario/xamarin-plugins] Firebase Cloud Messaging Support (#85)

FireBase is for Google push notififcations. For iOS you need to push through APNS rather than GCM / Firebase. Is there some facility in Firebase that lets you push iOS notifications? If so let me know where that is. I've just finished up creating a server using PushSharp for pushing notifications from our systems to both GCM (Firebase) and APNS (Apple). I can confirm that it IS possible to get all these pieces working. I'm not clear on how you are pushing your notifications via a google system (firebase) to Apple's push network. Either I'm not aware of that feature in Firebase, or you are trying to do something that's not possible. Firebase has the Firebase console that lets you send notifications, but as far as I know that's only for Android clients. I haven't found a similar console for devs in Apple's system.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/rdelrosario/xamarin-plugins/issues/85#issuecomment-282507741 , or mute the thread https://github.com/notifications/unsubscribe-auth/AYbQjJdjtQivLqiJHyCAJ5s6N2xKoXvyks5rgIXHgaJpZM4J01AS . https://github.com/notifications/beacon/AYbQjPbrJa_G9QzFjFbOcW1p9dSwepLnks5rgIXHgaJpZM4J01AS.gif

TimesliceTechnologies commented 7 years ago

Thanks for the info regarding iOS app defined in Firebase. Didn't realize that was there. I'm reluctant to try this since my stuff is working and I don't want to break anything.

If the token error you get is from Firebase console, then possibly there is some need to indicate the token is iOS rather than Android. Clearly Firebase simply doesn't like that token. Maybe something here: http://stackoverflow.com/questions/41343520/ios-invalid-registration-token-check-the-token-format

Im-PJ commented 7 years ago

@TimesliceTechnologies can you share some of your code how to get notifications working in xam forms? I have my server setup as well. I use dreamfactory which has all the end points for gcm and apns for register token and other such calls. I'm only confused how to set it up in client. How to use this plugin in cross platform way to send notifications to iOS and android. Pls share your implementation as I think it will solve my problem.

rdelrosario commented 7 years ago

For handling firebase push notifications. use this plugin instead:

https://github.com/CrossGeeks/FirebasePushNotificationPlugin