【问题标题】:Local Notifications using Firebase使用 Firebase 的本地通知
【发布时间】:2017-12-02 20:44:34
【问题描述】:

我对编程和开发一个应用程序相当陌生,该应用程序会在我的商店开张时通知用户。我正在使用 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() {
      ????????
}

提前非常感谢!

【问题讨论】:

    标签: ios swift firebase notifications local


    【解决方案1】:

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

    1.) 创建节点服务器为您进行观察并推送通知。这种方法听起来很复杂,但它非常简单,也是我采用的方法。 firebase 上有很棒的documentation,你可以找到很棒的教程,比如this one

    2.) 在您的应用程序委托中使用后台提取,例如 this post。这只会定期发生,因此可能并不完全适合。

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

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

    【讨论】:

    • 谢谢!正如您在第二种方式中列出的那样,我已经完成了后台提取
    • 太棒了!很高兴我能帮上忙 =)
    • 达斯汀,有没有办法在这里私信你?我真的可以使用一些帮助,并且在这个问题上被困了一个月。谢谢大佬
    • 我不这么认为,但如果你愿意,可以在 Facebook 上给我发消息
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-07-31
    • 2021-02-07
    • 1970-01-01
    相关资源
    最近更新 更多