使用 Firebase 的本地通知

Local Notifications using Firebase

我对编程和开发应用程序相当陌生,该应用程序会在我的商店开张时通知用户。我正在使用 firebase 来存储数据,我希望使用本地通知而不是推送。

我根据一些在线资源设置了我的应用委托来发送通知,但我不确定如何为其调用函数。我在 Xcode 中使用 swift 4。

import Firebase

var refNotificationValue = DatabaseReference!

@IBAction func openButtonClicked(_ sender: UIButton) {
    // Alert Controller confirming actions
   self.shouldSendNotification()
}

// DidLoad()

refNotificationValue = database.database().reference().child("Notifications").child("enabled")     // set to yes

// EndLoad()

func shouldSendNotification () {
    refNotificationValue?.observeSingleEvent(of: .value, with: { (snapshot) in
        let dict = snapshot.value as! [String: Any]
        let status = dict["enabled"] as! String

if status == "yes" {
      setToOpen()
      sendNotification()
} else {
     setToOpen()
   }
 })
}

func sendNotification() {
      ????????
}

提前致谢!!

假设您正在从数据库中观察打开和关闭时间,有 3 种方法可以解决这个问题。

1.) 创建节点服务器为您进行观察并推送通知。这种方法听起来很复杂,但它非常简单,也是我采用的方法。 firebase 有很棒的 documentation on it and you can find great tutorials like this one.

2.) 在您的应用委托中使用后台获取,就像在 中一样。这只会定期发生,因此可能不完全适合。

3.) 使用firebase cloud functions 来完成节点服务器的工作。查看 this post 了解如何操作。

您不能像 所讨论的那样在后台维护数据库观察功能。