Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mulitple Notifications for the same notification #13

Closed
saademou opened this issue Jan 4, 2017 · 14 comments
Closed

Mulitple Notifications for the same notification #13

saademou opened this issue Jan 4, 2017 · 14 comments

Comments

@saademou
Copy link

saademou commented Jan 4, 2017

Thank you for your awesome gem !

When calling app.push_notifications, I get a response success and it works perfectly
However, i receive the same notification several Times on iPhone ( not on android and Windows Phone )

First One => 1 seconde after sending the notification
Second one => 1.5 secondes later
Third one => 1.7 secondes later
...
...
I am using ruby 2.2.1p85, Rails 4.1.0 please suggest what could be the issue.

@calonso
Copy link
Owner

calonso commented Jan 7, 2017

Hi @saademou first of all I'm so glad that the gem is being useful for you. About the issue you mention I'm not really sure what may be happening, I've never heard of it before but I'd advise you to double check you're not generating multiple notifications, and if that's not the case then I'm afraid you'll have to debug inside the inner ruby-push-notifications gem to see if it is actually doing two submissions to the APNS service.

Anyway I'm happy to support you on whatever you may need during this troubleshooting process.

Regards

@saademou
Copy link
Author

saademou commented Jan 8, 2017

hi @calonso thanks for your answer. here the implementation of the notification part on the server side :

t = Thread.new do
		begin
		app_type = RailsPushNotifications::APNSApp.find_by(apns_app: destination[:mob_identity])
		if !app_type.blank?
		   notification = app_type.notifications.create(destinations: [destination[:token]], data: { aps: { alert: data, sound: "#{sound}.wav", badge: 1 } })
			arr_result = app_type.push_notifications
			arr_result.each do |result|
				if result.success == 1
                                   Rails.logger.info "[JOBS][ApnsJob] [perform] APNS notification has been sent "
				else
				  Rails.logger.error "[JOBS][ApnsJob] [perform] APNS notification has not been sent"
				end
			end
			else
				Rails.logger.error "[JOBS][ApnsJob] [perform] APNS APP is null "
			end
		rescue Exception => e
			Rails.logger.error "#{e.message} \n".concat( e.backtrace.to_sentence(words_connector: "\n", last_word_connector: "\n") ).concat("\n\n")
			error_catch = true
		end
	end

Can you tell me what's going wrong in my code plz

@calonso
Copy link
Owner

calonso commented Jan 8, 2017

TBH, that looks quite right. It is also quite a long time since I last worked with this product so I'm a bit rusty as well.

A couple of questions come to me right now.

  1. Has this always happened?
  2. Can you please check that the destinations are not repeated? I mean, the only thing I can think of right now is that the destinations array is actually repeating the tokens and that's why more than one notification is reaching the phone. It would make even more sense if the notification's contents are actually equal.

@saademou
Copy link
Author

saademou commented Jan 8, 2017

Thanks again :)

So i investigated my code, it happens only when i have more than 5 devices to notify.

In fact, looking the Notifications in the Database by doing :

RailsPushNotifications::Notification.where(success:nil, failed:nil)

it returns some x records, Is it normal ?

Does notification stay frozen until a new push_notifications

@calonso
Copy link
Owner

calonso commented Jan 8, 2017

Well, that could definitely lead to some notifications being sent several times. A notification is pushed if sent = false, and that flag, as success and failed values are based on the results values as you can see here so that may mean that there is an issue with those callbacks, but on the other hand, that would happen with all notification types, not just iOS ones...

Coming back to my questions...Has this happened since the very beginning?

And yes, notifications are updated when push_notifications is invoked. Are the notifications that you can see in your db unsent expected to be unsent? Those ones may lead us somewhere...

@saademou
Copy link
Author

saademou commented Jan 9, 2017

Indeed, i am testing your gem only on iOS devices.

Has this happened since the very beginning?

1- The gem works fine when I send a single notification to the device, it receives it

2- On the other hand, when I send several notifications, some will be sent and some will remain blocked until the arrival of a new notification system. So Customers will receive old and new notifications, which creates a confusion for them by thinking that these are the same notifications

All the notifications must be sended to devices

@calonso
Copy link
Owner

calonso commented Jan 9, 2017

Well... This sounds definitely as a bug. Can you please debug if the results value assigned here is nil for the notifications that remain 'blocked'? (i.e.) to_send[i].results is nil for all but the first element.

I think that would explain the behaviour you're seeing.

@saademou
Copy link
Author

saademou commented Jan 9, 2017

I will debug the results and keep u in touch.

Is it possible to send a single notification without calling push_notifications.

What i need To do is to create a notification and send it immedialty. Dont care about old pending ones

@calonso
Copy link
Owner

calonso commented Jan 10, 2017

Cool, thanks for your effort!!

Yes, you can create and send the notification straight away. See this example in my rails push notifications test app

Please, let me know the outcome of your debug.

@saademou
Copy link
Author

saademou commented Jan 10, 2017

I saw and understood your examples. You use push_notifications all the time, it will push all pending notifications. I need to push only one ( single one )

@calonso
Copy link
Owner

calonso commented Jan 10, 2017

Ok, got you.

So you can tell the pusher to push only one by providing only the notification you're interested in. Here you can see how it normally does to push all of them, so you can do the same but instead of for all the pending ones, just for the one you want

@saademou
Copy link
Author

saademou commented Jan 10, 2017

@calonso
Copy link
Owner

calonso commented Feb 28, 2017

Hi @saademou.

How are you doing with this? Did you manage to find the error?

Regards

@calonso
Copy link
Owner

calonso commented Mar 9, 2018

Closing as stale... Please reopen if needed or add more info to the issue if you found anything interesting.

@calonso calonso closed this as completed Mar 9, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants