当应用程序不在前台时从 iOS 应用程序向上游发送 gcm + gcm API 用于上传 APNs 证书

sending gcm upstream from iOS app when app is not in foreground + gcm API for uploading APNs certificate

我有两个关于 APNs push notification 使用 gcm 库的问题。

  1. gcmfcm是否有publicapi上传APNs certificates?我需要自动而不是手动执行此操作。

  2. 似乎在 iOS app 中使用 gcm 库发送 上游 ,仅当应用程序处于前台时才有效。这是正确的吗?即使应用程序未打开或处于后台,是否有任何解决方法可以向上游发送?我想使用 gcm upstream 将通知 click 事件 发送到我的服务器,最好立即执行。

    我知道我可以保存这个点击事件并在应用激活时发送它,但用户可能很长时间没有打开应用。

1. Does gcm or fcm have a public api for uploading APNs certificates?

目前没有 public API 用于上传 APNs 证书。对于 FCM(以及任何新项目),只能通过 Firebase Console. Also, it seems that making use of the APNs Authentication Keys over certificates seem more convenient now (APNs Overview).

完成

2. It seems that sending upstream using gcm library in an iOS app, only works when app is in foreground. Is it correct?

是的。上游消息必须有连接才能工作。

Is there any workaround to send upstream even when app is not open or is in background?

据我所知,不。如FCM doc(强调我的)中所述:

To send messages upstream to the server, an iOS client app composes a message, connects to FCM, and calls sendMessage.

To connect, set the shouldEstablishDirectChannel flag to YES in the AppDelegate. FCM manages the connection, closing it when your app goes into the background and reopening it whenever the app is foregrounded.

...

The FCM client library caches the message on the client app and sends it when the client has an active server connection. On receiving the message, the FCM connection server sends it to the app server.

它提到 FCM 管理连接,但是 AFAICT,iOS 设备存在此限制,如果应用程序处于 background/closed(请参阅这个answer)。如果无法建立连接,上游消息将无法正常工作。

作为一般做法,通过 FCM 传递的数据应尽可能改善用户体验并且不传递任何应用关键数据。

I am aware that I can save this click event and send it when app become active, but it is possible that user does not open the app for a long time.

这是可能的。但用户也不太可能在推送通知显示后不立即点击它。在这种情况下,通常的操作是让用户在仍然有打开的连接时立即单击通知。