1

I've recently implemented PushSharp into an application but for the life of me I can't figure out why the notification isn't appearing on the device.

The following is a method that put together to test the behaviour:

private void SendPushNotification()
{
    var push = new PushBroker();

    //Wire up the events for all the services that the broker registers
    push.OnNotificationSent += NotificationSent;
    push.OnChannelException += ChannelException;
    push.OnServiceException += ServiceException;
    push.OnNotificationFailed += NotificationFailed;
    push.OnDeviceSubscriptionExpired += DeviceSubscriptionExpired;
    push.OnDeviceSubscriptionChanged += DeviceSubscriptionChanged;
    push.OnChannelCreated += ChannelCreated;
    push.OnChannelDestroyed += ChannelDestroyed;

    push.RegisterGcmService(new GcmPushChannelSettings("My-API-Key-here"));

    push.QueueNotification(new GcmNotification().ForDeviceRegistrationId("MyReallyLongRegisteredDeviceKeyHere")
              .WithJson(@"{""alert"":""Hello World!"",""badge"":7,""sound"":""sound.caf""}"));


    //Stop and wait for the queues to drains
    push.StopAllServices();
}

This method is called immediately upon application start, so I would expect that I get a notification straight away which I don't.

What else is strange is that the event OnNotificationSent is called which would indicate that the message has gone through.

Is there anything else I need to configure in order for this to work? The documentation states that the sender id, package name and api key are required in order to send notifications

https://github.com/Redth/PushSharp/wiki/How-to-Configure-&-Send-GCM-Google-Cloud-Messaging-Push-Notifications-using-PushSharp#setting-up-pushsharp-to-send-notifications

all but the api key are used though.

Any help would be greatly appreciated.

Matthew Merryfull
  • 1,466
  • 18
  • 32
  • Did you change the package name to yours? For example, the BroadcastReceiver. – ztan Feb 11 '15 at 17:30
  • Are you referring to the server or the application? As mentioned, I can't see anything in the documentation which would indicate that I need to update the package name – Matthew Merryfull Feb 11 '15 at 22:27
  • From this page: https://github.com/Redth/PushSharp `take a look at the PushService.cs file in the sample project. You can copy much of this class into your own App, but again be sure to substitute your own package name in where applicable (the BroadcastReceiver attributes need to be changed). ` – ztan Feb 11 '15 at 22:34
  • @MatthewMerryfull I am facing the EXACTLY same problem. My code is almost identical to your code. Can you specify in details how do you solved this. I am really struggling with this problem. – Hakan Fıstık Aug 19 '15 at 11:44
  • @ztan, please can you explain more your suggestion. I could not figure out your idea. – Hakan Fıstık Aug 19 '15 at 11:47
  • Please see my answer on [Structuring GCM messages in PushSharp 4.0](http://stackoverflow.com/questions/36905361/structuring-gcm-messages-in-pushsharp-4-0/40913273#40913273) – Umut Bebek Dec 01 '16 at 14:41
  • Please see my answer on [Structuring GCM messages in PushSharp 4.0](http://stackoverflow.com/questions/36905361/structuring-gcm-messages-in-pushsharp-4-0/40913273#40913273) – Umut Bebek Dec 01 '16 at 14:42
  • Please see my answer on [Structuring GCM messages in PushSharp 4.0](http://stackoverflow.com/questions/36905361/structuring-gcm-messages-in-pushsharp-4-0) – Umut Bebek Dec 01 '16 at 14:44
  • Plase see the answer on http://stackoverflow.com/questions/36905361/structuring-gcm-messages-in-pushsharp-4-0 – Umut Bebek Dec 01 '16 at 14:45

3 Answers3

0

From my experience, I faced this issue 3 times in the last two years :)

The first time: I had to regenerate a new GCM API key, used it and it worked.

The second time: the first solution didn't work, I checked with the android developer to double check his code, it turned out there was something wrong with his code.

The third time: the issue was with the device, I had to restart the device, after that the notification received right away.

Hakan Fıstık
  • 16,800
  • 14
  • 110
  • 131
Ala' Alnajjar
  • 788
  • 1
  • 11
  • 23
  • I tried the 3 solutions which you suggest, but nothing work for me. do you have other solutions. I am facing exactly the same problem in the question – Hakan Fıstık Aug 19 '15 at 12:11
  • I'm not sure if your case is exactly as this one,maybe It would be best if you post your question on a new thread with the code you'r using – Ala' Alnajjar Aug 19 '15 at 12:24
  • My problem has been solved, it was like the second case you mentioned. the problem was in the Android App – Hakan Fıstık Aug 20 '15 at 05:46
0

Try using message instead of alert.

.WithJson(@"{""message"":""Hello World!"",""badge"":7,""sound"":""sound.caf""}"));

As in my case the service (like yours was) was sending an alert but the client device was expecting a message.

Regards,

Palvinder
  • 1,447
  • 1
  • 10
  • 9
0

For PushSharp 4.0 , you can go like this

var config = new GcmConfiguration("senderKey", "apiKey", null);
config.GcmUrl = "https://fcm.googleapis.com/fcm/send"; //!!!!!gmc changed to fcm;)

var gcmBroker = new GcmServiceBroker(config);
gcmBroker.Start();

_gcmBroker.QueueNotification(new GcmNotification
                {
                    RegistrationIds = new List<string> { "YourDeviceToken" },
                    Notification = JObject.Parse(
                        "{" +
                            "\"title\" : \"" + yourMessageTitle + "\"," +
                            "\"body\" : \"" + yourMessageBody + "\"," +
                            "\"sound\" : \"mySound.caf\"" +
                        "}") ,
                    Data = JObject.Parse(
                        "{" +                            
                            "\"CustomDataKey1\" : \"" + yourCustomDataValue1 + "\"," +
                            "\"CustomDataKey2\" : \"" + yourCustomDataValue2 + "\"" +
                        "}")
                });

I did not test if the custom data values are arriving but the notification does:) The items starts with "your" are your dynamic arguments like parameters that you pass to that method etc. The question asked long time ago but i started to use pushsharp just now :) Hope this helps to PushSharp users.

Umut Bebek
  • 364
  • 4
  • 9