我正在尝试从Android向iOS发送推送通知,但无法在iOS设备上收到每条聊天消息的通知。 Android到Android推送通知正在运行,Android到iOS推送通知无效。
Below is the format of payload which is send for receiving push notification on Android and iOS:
{
"uuid": "d587abbf-91f6-4231-a917-e42b9ecfc78a",
"date": "2017-04-03T16:33:37.832+0530",
"id": "8c6df2eb-44f8-4337-b66f-450749ec0dee",
"stageName": "Vicky",
"message": "jggiviib",
"type": "chat",
"status": 1,
"pn_gcm": {
"data": {
"alert": "jggiviib",
"type": "chat",
"id": "8c6df2eb-44f8-4337-b66f-450749ec0dee",
"stageName": "Vicky",
"uuid": "d587abbf-91f6-4231-a917-e42b9ecfc78a",
"message": "jggiviib",
"date": "2017-04-03T16:33:37.832+0530"
}
},
"pn_apns": {
"aps": {
"alert": "Vicky: jggiviib",
"badge": 1,
"data": {
"type": "chat",
"id": "8c6df2eb-44f8-4337-b66f-450749ec0dee",
"stageName": "Vicky",
"uuid": "d587abbf-91f6-4231-a917-e42b9ecfc78a",
"message": "jggiviib",
"date": "2017-04-03T16:33:37.832+0530"
}
}
}
}
我正在接收Android到Android的推送通知。同样,iOS到iOS推送通知也很有效。
以下是注册推送通知的通道的方法:
public void addChannels() {
pubnub.addPushNotificationsOnChannels().pushType(PNPushType.GCM)
.channels(newChannels).deviceId(mLocalDataSource.getGcmToken()).async(new PNCallback<PNPushAddChannelResult>() {
@Override
public void onResponse(PNPushAddChannelResult result, PNStatus status) {
if (status.isError()) {
Log.d(TAG, "enable push notifications failed");
status.retry();
} else {
Log.d(TAG, "registered for push notifications successfully");
}
}
});
}
发送消息的方法:
public void sendMessage(final ChatMessage chatMessage) {
JsonObject jsonSend = chatMessage.toJson();
jsonSend.add("pn_gcm",chatMessage.toGcmPlayload());
jsonSend.add("pn_apns", chatMessage.toAPNPayload());
Log.d(TAG,"apns payload :" +chatMessage.toAPNPayload());
pubnub.publish().message(jsonSend).channel(chatMessage.mChatChannel.getChannelName())
.shouldStore(true)
.async(new PNCallback<PNPublishResult>() {
@Override
public void onResponse(PNPublishResult result, PNStatus status) {
if (status.isError()) {
Log.d(TAG, "error occurred");
status.retry();
} else {
Log.d(TAG, "published successfully");
}
}
});
}
我也遵循了Pubnub的故障排除指南,在使用Pubnub控制台进行调试时,注册APNS的设备显示为0。
"Devices found for push notification apns: 0 gcm: 2 mpns: 0"