2017-12-02 144 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

達斯汀,有沒有辦法在這裏私下給你發消息?我真的可以使用一些幫助,並在這個問題上停留了一個月。謝謝你 –