2017-12-02 199 views
0

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

非常感谢!

回答

0

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

1.)创建节点服务器,为您进行观察并推送通知。这种方法听起来很复杂,但它非常简单,并且与我一起工作。 firebase有很大的documentation就可以了,你可以找到很棒的教程,如this one

2.)在您的应用程序代理中使用后台提取,如this post。这只是周期性发生,所以它可能不是一个确切的适合。使用firebase cloud functions来完成节点服务器的工作。看看this post看看怎么做。

您不能在后台维护数据库观察功能,如here所述。

+0

谢谢!我已经制定了你在第二种方式列出的背景获取 –

+0

很棒!我很乐意帮忙=) –

+0

达斯汀,有没有办法在这里私下给你发消息?我真的可以使用一些帮助,并在这个问题上停留了一个月。谢谢你 –