How to trigger Remote Push Notification when Firebase database node values are changed for a user in Swift for iOS development using Batch?
Asked Answered
E

1

7

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:

 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.

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.

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

Eclectic answered 7/4, 2016 at 1:4 Comment(1)
Any luck with this @AtlasShrugged ? I'm trying to do a similar thing with Firebase.Oringas
L
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.

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

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

Leninist answered 7/4, 2016 at 10:35 Comment(2)
This is what I do to send notifications with batch and firebase, however I was told bye someone form the Batch team that sending notifications from the app could be insecure and potentially unreliable. If this is the case, is there a way to trigger the notification based on a change in the firebase realtime database rather than from within the app?Opportunist
Sending from the app directly implies that you put security keys in the client code, it was unsecured with Parse and it is with other services, Batch included. If you want to trigger notifications based on Firebase userbase changes, you'll have to write server-side code yourself I'm afraid..Selfimportant

© 2022 - 2024 — McMap. All rights reserved.