![](/img/trans.png)
[英]Parse.com sending push notification to multiple device types i.e Android and iOS not working
[英]Push notification is not working with Android and iOS devices sending via Parse.com
我将Parse.com用于后端,并且试图在同一事件创建时向Android和iOS设备发送推送通知。
当我从Android应用创建事件时,它仅通知Android设备,并且通知与iOS设备相同的事件,但不会同时使用相同事件在两个平台设备中获得通知。
重要说明:我的两种技术(Android和iOS)的捆绑包标识符在“安装”表中均不同。
这会影响我的推送通知机制吗?
还有没有其他解决方案可以将通知发送到两种类型的设备?
是的,我为此找到了一种解决方案:
我创建了一个列“ Should_notify”,并为其保留了true / false值,并且在编码方面,我编写了查询以发送推送通知。
注意:此代码块适用于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];
希望对您有帮助。 :)
我最近遇到了这个问题,并设法解决了这个问题,因为只有一小段代码使它无法正常工作。
首先,您必须具有Android和iOS通知功能。 听起来像你。
您可以通过Parse在面板中显示推送来确保您这样做:
接下来,您可以检查是否为所有设备设置了推送通知,单击其中一项推送并检查推送细分:
如您所见,我对所有设备的推送都可以。 如果您不这样说,那可能是您的问题。
最后要检查的是您的推送已发送到正确的频道。 通道在推字典中设置:
例如,在我的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"}];
这是让我感到震惊的一点,我将用户通道设置为user_simplelogin_XX,而不是将Android设置为usersimplelogin)
因此,这是要检查的重要的最后部分,是否将推送发送给正确的用户添加到通道中。
我会在推送详细信息中对此进行检查,如上图所示,它会显示“包括...的频道”。
TL DR:
希望这会有所帮助,因为它非常令人沮丧,但现在效果很好
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.