PubNub sends push notifications to those already subscribed and present in the chat room?
Closed this issue · 6 comments
Each of my PNMessages have the following dictionary (this is an example):
{
@"aps": {@"alert": "HELLO!"},
@"HELLO!"
}
However, this message is being both delivered via push notification and via PubNub's websocket. Am I constructing my PNMessage incorrectly? Ideally, I want push to deliver only to those not present in the chat room (as in, the phone is locked).
A work-around I've found is to call [PubNub removeAllPushNotificationsForDevicePushToken: withCompletionHandlingBlock:] every single time the application becomes active, and call [PubNub enablePushNotificationsForChannels: withDevicePushToken:] whenever the application becomes inactive. But this is very unideal, since you can imagine a variety of scenarios where this would fail.
That is correct. The pubnub suggested pattern is to silently eat the APN if your app is running.
- App is not running… user sees the push notification
- App is running… swallow the push… users see your channel / chat notification
From: Naveen Kasthuri <notifications@github.commailto:notifications@github.com>
Reply-To: pubnub/objective-c <reply@reply.github.commailto:reply@reply.github.com>
Date: Friday, May 16, 2014 at 8:43 AM
To: pubnub/objective-c <objective-c@noreply.github.commailto:objective-c@noreply.github.com>
Subject: [objective-c] PubNub sends push notifications to those already subscribed and present in the chat room? (#63)
Each of my PNMessages have the following dictionary (this is an example):
{
@"aps": {@"alert": "HELLO!"},
@"HELLO!"
}
However, this message is being both delivered via push notification and via PubNub's websocket. Am I constructing my PNMessage incorrectly? Ideally, I want push to deliver only to those not present in the chat room (as in, the phone is locked).
A work-around I've found is to call [PubNub removeAllPushNotificationsForDevicePushToken: withCompletionHandlingBlock:] every single time the application becomes active, and call [PubNub enablePushNotificationsForChannels: withDevicePushToken:] whenever the application becomes inactive. But this is very unideal, since you can imagine a variety of scenarios where this would fail.
—
Reply to this email directly or view it on GitHubhttps://github.com//issues/63.
That suggested pattern of swallowing the push does not work well in the instance where:
- I'm in a low-signal environment.
- I send a message, which takes some time to deliver, but is delivered eventually.
- I lock the screen before the delivery completes.
It also fails in all instances where the push is delivered a second after sending a message & locking the screen.
In this case, you'll see a push notification that you sent to yourself. The only work-around I can think of is disabling pushes upon app open and enabling them upon applicationWillResign. However, you can imagine many scenarios where the push notification fails to enable upon app resign due to low or no signal upon app close.
I don’t think enable/disable is a good idea… (for the reasons you cite) nor do I think it helps your situation.
The user goes into the chat room… which fires off a hello msg… and immediately kills the app…
They would still get the APN, b/c you turned it back on while you were shutting down.
Are you sure you want to send Push notifications when people enter a chat room?? I’m thinking I’d turn that feature off real soon if I was using your app.
From: Naveen Kasthuri <notifications@github.commailto:notifications@github.com>
Reply-To: pubnub/objective-c <reply@reply.github.commailto:reply@reply.github.com>
Date: Friday, May 16, 2014 at 9:12 AM
To: pubnub/objective-c <objective-c@noreply.github.commailto:objective-c@noreply.github.com>
Cc: Eric Oemig <eric@oemig.commailto:eric@oemig.com>
Subject: Re: [objective-c] PubNub sends push notifications to those already subscribed and present in the chat room? (#63)
That suggested pattern of swallowing the push does not work well in the instance where:
- I'm in a low-signal environment.
- I send a message, which takes some time to deliver, but is delivered eventually.
- I lock the screen before the delivery completes.
It also fails in all instances where the push is delivered a second after sending a message & locking the screen.
In this case, you'll see a push notification that you sent to yourself. The only work-around I can think of is disabling pushes upon app open and enabling them upon applicationWillResign. However, you can imagine many scenarios where the push notification fails to enable upon app resign due to low or no signal upon app close.
—
Reply to this email directly or view it on GitHubhttps://github.com//issues/63#issuecomment-43349817.
Sorry, I wasn't clear. That JSON that I had up there was just a sample of how I've structured my chat messages.
People do not get push notifications announcing that someone entered a chat room. In fact, I want people NOT to get push notifications for any messages sent or received when they are connected to PubNub. At the moment, if I don't swallow any pushes, I will be displaying push notifications for messages that I send/receive even when I'm inside the app. I can swallow push notifications, but in the instance that I send a message and immediately turn off my phone, I could still receive a push notification for a message that I had sent.
Thanks for the clarification.
I can’t think of a good workaround for your example.
From: Naveen Kasthuri <notifications@github.commailto:notifications@github.com>
Reply-To: pubnub/objective-c <reply@reply.github.commailto:reply@reply.github.com>
Date: Friday, May 16, 2014 at 9:30 AM
To: pubnub/objective-c <objective-c@noreply.github.commailto:objective-c@noreply.github.com>
Cc: Eric Oemig <eric@oemig.commailto:eric@oemig.com>
Subject: Re: [objective-c] PubNub sends push notifications to those already subscribed and present in the chat room? (#63)
Sorry, I wasn't clear. That JSON that I had up there was just a sample of how I've structured my chat messages.
People do not get push notifications announcing that someone entered a chat room. In fact, I want people NOT to get push notifications for any messages sent or received when they are connected to PubNub. At the moment, if I don't swallow any pushes, I will be displaying push notifications for messages that I send/receive even when I'm inside the app. I can swallow push notifications, but in the instance that I send a message and immediately turn off my phone, I could still receive a push notification for a message that I had sent.
—
Reply to this email directly or view it on GitHubhttps://github.com//issues/63#issuecomment-43351733.
Please contact us at support@pubnub.com, we can discuss your app in more detail, and let you know about some soon-to-be released features that may help you.
geremy