简体   繁体   English

推送通知不适用于通过Parse.com发送的Android和iOS设备

[英]Push notification is not working with Android and iOS devices sending via Parse.com

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. 我将Parse.com用于后端,并且试图在同一事件创建时向Android和iOS设备发送推送通知。

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. 当我从Android应用创建事件时,它仅通知Android设备,并且通知与iOS设备相同的事件,但不会同时使用相同事件在两个平台设备中获得通知。

Important Note: My bundle identifier for both technology(Android and iOS) is different in Installation table. 重要说明:我的两种技术(Android和iOS)的捆绑包标识符在“安装”表中均不同。

Is this affect my push notification mechanism? 这会影响我的推送通知机制吗?

And is there any alternative solution to send notification to both type of devices? 还有没有其他解决方案可以将通知发送到两种类型的设备?

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. 我创建了一个列“ Should_notify”,并为其保留了true / false值,并且在编码方面,我编写了查询以发送推送通知。

Note: This code block is for iOS but same available for Android too. 注意:此代码块适用于iOS,但同样适用于Android。

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. 希望对您有帮助。 :) :)

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. 首先,您必须具有Android和iOS通知功能。 It sounds like you do. 听起来像你。

You can make sure you do by the fact that Parse has the pushes showing in the dashboard: 您可以通过Parse在面板中显示推送来确保您这样做:

像这样

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: 例如,在我的iOS项目中,我将推送数据设置如下:

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 这是让我感到震惊的一点,我将用户通道设置为user_simplelogin_XX,而不是将Android设置为usersimplelogin)

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: TL DR:

  1. Are push notifications working and posting correct pushes to Parse 推送通知是否正常运行并将正确的推送发布到Parse
  2. Are push notifications enabled between devices (check in push details) 在设备之间是否启用了推送通知(签入推送详细信息)
  3. Are the correct users being added as targets to the push channels? 是否将正确的用户添加为推播渠道的目标?

Hope this helps as it was very frustrating but now it works great 希望这会有所帮助,因为它非常令人沮丧,但现在效果很好

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM