Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the right way to use PushSharp?

Tags:

pushsharp

I use PushSharp to send notifications for a few Apps. PushSharp is great it really simplifies the work with push services, and I wonder what is the right way to work with it? I haven't found examples/ explanations about that.

Now, when I have a message to send , I ...

  1. create a PushSharp object
  2. do a PushService.QueueNotification() for all devices
  3. do a PushService.StopAllServices to send all queued messages
  4. exits the method (and kill the PushService object).

Should I work this way, or keep this PushService object alive and call its methods when needed?

How should I use a PushService object to get the unregistered device ids? with a dedicated instance?

Any suggestion would be appreciated.

like image 385
gilp Avatar asked Mar 28 '13 14:03

gilp


1 Answers

This is a question which frequently comes up.

The answer isn't necessarily one way or the other, but it depends on your situation. In most cases it would be absolutely fine to just create a PushBroker instance whenever you need it, since most platforms use HTTP based protocols for sending notifications. In the case of Apple, they state in their documentation that you should keep your connection to APNS open in order to minimize overhead of opening and closing secure connections.

However, in practice I think this means that they don't want you connecting and disconnecting VERY frequently (eg: they don't want you creating a new connection for every message you send). In reality, if you're sending batches of notifications every so often (let's say every 15 minutes or every hour) they probably won't have a problem with you opening a new connection for each batch and then closing it when done.

I've never heard of anyone being blocked from Apple's APNS servers for doing this. In fact in the very early days of working with push notifications, I had a bug that caused a new apns connection to be created for each notification. I sent thousands of notifications a day like this and never heard anything about it from Apple (eventually I identified it as a bug and fixed it of course).

As for collecting feedback, by default the ApplePushService will poll the feedback servers after 10 seconds of starting, and then every 10 minutes thereafter. If you want to disable this from happening you can simply set the ApplePushChannelSettings.FeedbackIntervalMinutes to <= 0. You can then use the FeedbackService class to poll for feedback whenever you need to, manually.

like image 72
Redth Avatar answered Oct 04 '22 20:10

Redth