Reputation: 1178
I am using Parse.com for backend and I am trying to send push notification to android and iOS devices at a same event creation.
When I create event from Android app then it notifies only Android devices and same with iOS devices but not getting notification in both platform devices using same event at same time.
Important Note: My bundle identifier for both technology(Android and iOS) is different in Installation table.
Is this affect my push notification mechanism?
And is there any alternative solution to send notification to both type of devices?
Upvotes: 0
Views: 716
Reputation: 1178
Yes, I found one solution for this:
I created one column "Should_notify" and maintain true/false value for same and on coding side I wrote query to send push notifications.
Note: This code block is for iOS but same available for Android too.
NSDictionary *data = [NSDictionary dictionaryWithObjectsAndKeys:
message, @"alert",
@"Increment", @"badge",
nil];
PFQuery *pushQuery = [PFInstallation query];
/**
* Where condition: if user or device enable Notification switch
*/
[pushQuery whereKey:@"Should_Notify" equalTo:@YES];
/**
* Send push notification with data using pushQuery
*/
[PFPush sendPushDataToQueryInBackground:pushQuery withData:data];
Hope, This will help you too. :)
Upvotes: 1
Reputation: 6093
I had this issue recently and managed to get it fixed as there was just one small line of code stopping it from working.
First of all you must have Android and iOS notifications working. It sounds like you do.
You can make sure you do by the fact that Parse has the pushes showing in the dashboard:
Next you can check if the push notifications are set up for all devices, click on one of the pushes and check in the push break down:
As you can see my pushes are ok for all devices. If yours doesn't say this then this might be your problem.
The last thing to check is that your pushes are being sent to the correct channel. The channel is set in the push dictionary:
For instance in my iOS project I set the push data like this:
text = [NSString stringWithFormat:@"%@: %@", message.user.name, text];
// Send the push message to the users specified
PFPush * push = [[PFPush alloc] init];
[push setChannels:userChannels];
[push setData:@{bAction: @"",
bContent: text,
bAlert: text,
bMessageEntityID: message.entityID,
bThreadEntityID: message.thread.entityID,
bMessageDate: [NSString stringWithFormat:@"%f", [[NSDate date] timeIntervalSince1970]],
bMessageSenderEntityID:message.user.entityID,
bMessageType: message.type.stringValue,
bMessagePayload: message.text,
bBadge: @"Increment",
bSound: @"default"}];
This is the bit that tripped me up, I was setting the user channel to be user_simplelogin_XX instead of what Android was setting is as usersimplelogin)XX
So this is an important final part to check, are the pushes being sent to the correct users added to the channel.
I would check this in the push details where it says "channels including..." like in the picture above.
TL DR:
Hope this helps as it was very frustrating but now it works great
Upvotes: 0