如何触发远程推送通知,当使用批处理的iOS开发时,用户对Firebase数据库节点值进行了更改?

时间:2022-10-16 21:25:46

I am using a Firebase database for my iOS Swift app. After going through a volume of material online, I decided to try Batch+Firebase to provide remote push notifications to a logged-in, authenticated user within an app, whenever node values in his/her database changes. I save the logged-user UID like so:

我正在为我的iOS Swift应用使用一个Firebase数据库。在网上查阅了大量资料后,我决定尝试Batch+Firebase,在一个应用中为登录的、经过验证的用户提供远程推送通知,只要他/她的数据库中的节点值发生变化。我将登录用户UID保存为:

 override func viewDidLoad(){
      super.viewDidLoad()
      //...
     editor = BatchUser.editor
     editor.setIdentifier("uid" as String!)
     editor.save()
 }

Of course, I have done the necessary background work for enabling push notifications for my app. Also, have installed pods of both Firebase and Batch, and I get user to activate notification settings.

当然,我已经做了必要的后台工作,为我的app启用推送通知。另外,我已经安装了Firebase和Batch的pods,我让用户激活通知设置。

I am not certain how to write the changed database values into a push notification and deliver to a user. I searched a lot for relevant tutorials online, but to no avail.

我不确定如何将修改后的数据库值写入push通知并交付给用户。我在网上搜索了很多相关的教程,但都没用。

Any direction on how to implement the Batch APIs in Swift for Firebase will be greatly appreciated.

对于如何在Swift中为Firebase实现批处理api,我们将非常感激。

1 个解决方案

#1


0  

If you want to send push notifications directly from the app (users to users), you'll have to use Batch Transactional API with custom_ids (Firebase UID) in the recipients list instead of push tokens.

如果您想要直接从应用程序(用户到用户)发送推送通知,您必须在收件人列表中使用带有custom_id (Firebase UID)的批处理API,而不是推送令牌。

You'll have to learn how to call a REST API from Swift code.

您必须学习如何从Swift代码调用REST API。

Here is a tutorial: http://www.kaleidosblog.com/nsurlsession-in-swift-get-and-post-data

这里有一个教程:http://www.kaleidosblog.com/nsurlsession-in-swift-get-and-post-data。

#1


0  

If you want to send push notifications directly from the app (users to users), you'll have to use Batch Transactional API with custom_ids (Firebase UID) in the recipients list instead of push tokens.

如果您想要直接从应用程序(用户到用户)发送推送通知,您必须在收件人列表中使用带有custom_id (Firebase UID)的批处理API,而不是推送令牌。

You'll have to learn how to call a REST API from Swift code.

您必须学习如何从Swift代码调用REST API。

Here is a tutorial: http://www.kaleidosblog.com/nsurlsession-in-swift-get-and-post-data

这里有一个教程:http://www.kaleidosblog.com/nsurlsession-in-swift-get-and-post-data。