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

Please help with code to send push to mutliple phones #35

Closed
GoogleCodeExporter opened this issue Dec 21, 2015 · 13 comments
Closed

Please help with code to send push to mutliple phones #35

GoogleCodeExporter opened this issue Dec 21, 2015 · 13 comments

Comments

@GoogleCodeExporter
Copy link

Hi...I am able to send Push notifications using the following code template
Please suggest if there is better way to do this batch push using your APIs

//create payload

//open connection with apple server
pushManager.initializeConnection(.....);

for each iphone in database
           pushManager.addDevice("iPhone", device.getDeviceToken());
           client=pushManager.getDevice("iPhone");  
           pushManager.sendNotification(client, payLoad);
           pushManager.removeDevice("iPhone");
end for

//close connection in finally block

Original issue reported on code.google.com by pilotj...@gmail.com on 9 Dec 2010 at 3:28

@GoogleCodeExporter
Copy link
Author

instead of looping thru each iphone id and naming the device 'iPhone'...

loop thru each iphone id and add it to the pushmanager as a unique device.

Then send all the notifications in one shot.

like:

for device in database
           pushManager.addDevice("iPhone", device.getDeviceToken());
           client=pushManager.getDevice( device.name ); 
end for

pushManager.sendNotification(client, payLoad);

for device in database
           pushManager.removeDevice(device.name);
end for

Original comment by idbill.p...@gmail.com on 9 Dec 2010 at 5:41

@GoogleCodeExporter
Copy link
Author

Hi, 
Thanks for your reply. By looking at the above code skeleton, wouldn't client 
represent the last device in the for loop. Please advise.

Original comment by pilotj...@gmail.com on 9 Dec 2010 at 6:50

@GoogleCodeExporter
Copy link
Author

I'm assuming device is a row coming back from your database call.

And device.name is unique to that device 
and device.token is the unique token for said device row.

Original comment by idbill.p...@gmail.com on 9 Dec 2010 at 7:03

@GoogleCodeExporter
Copy link
Author

Yes, what you have assumed is correct. I think you did not understand my 
question...

In the below line
pushManager.sendNotification(client, payLoad);

doesn't client represent the last device present in the DB  and so won't the 
notification be sent to only that device.

Please let me know...

Original comment by pilotj...@gmail.com on 9 Dec 2010 at 7:10

@GoogleCodeExporter
Copy link
Author

I'm very busy at the moment, so please read the wiki, there are examples 
already provided.

The important part, is to only initialize the connection once, send all the 
notifications, then close the connection.

Bill

Original comment by idbill.p...@gmail.com on 9 Dec 2010 at 7:30

@GoogleCodeExporter
Copy link
Author

Okay..Thanks. I did change the code as per your code skeleton and as expected 
only the last device returned from the DB got notified. 

I think it is because you have put
 pushManager.sendNotification(client, payLoad);

outside the for loop. I couldn't locate any example on the wiki for sending 
bulk pushes. Please re-examine you suggested code and reply back when you get 
time

Thanks
John

Original comment by pilotj...@gmail.com on 9 Dec 2010 at 8:19

@GoogleCodeExporter
Copy link
Author

I did not understand the line made in Comment #1
"Then send all the notifications in one shot."

Since you are calling 
pushManager.sendNotification(client, payLoad);

outside the loop. So won't only the device represented in 'client' be notified. 
Please advice

Original comment by pilotj...@gmail.com on 10 Dec 2010 at 2:11

@GoogleCodeExporter
Copy link
Author

See:
http://code.google.com/p/javapns/wiki/MultipleClientsExample

I have not tested the code, but it should have everything in the right place.

Someone is working on a database connection piece that may streamline this 
process, but I do not know the status at this time.

Original comment by idbill.p...@gmail.com on 11 Dec 2010 at 7:08

@GoogleCodeExporter
Copy link
Author

Original comment by idbill.p...@gmail.com on 11 Dec 2010 at 7:08

  • Added labels: Type-Other
  • Removed labels: Type-Defect

@GoogleCodeExporter
Copy link
Author

Thanks. I have implemented your template into my code.

Original comment by pilotj...@gmail.com on 13 Dec 2010 at 3:29

@GoogleCodeExporter
Copy link
Author

Comment by MrPatol, Dec 15 (2 days ago)
missing line before

pushManager.sendNotification( client, aPayload );
should have:

Device client = pushManager.getDevice(user.getUsername());

Original comment by idbill.p...@gmail.com on 17 Dec 2010 at 6:00

@GoogleCodeExporter
Copy link
Author

example has been updated

Original comment by idbill.p...@gmail.com on 17 Dec 2010 at 6:01

@GoogleCodeExporter
Copy link
Author

Closing issue since example for javapns 1.x has been updated, and because 
javapns 2.0 provides direct support for this.

Original comment by sype...@gmail.com on 7 Sep 2011 at 1:13

  • Changed state: Fixed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant