静音推送通知只能工作一次

时间:2016-07-04 10:44:38

标签: ios swift firebase notifications completionhandler

我正在构建一个应用程序,需要每隔5分钟将一些数据上传到我的Firebase数据库。 为此,我正在用cron发送内容推送通知。

对于我遵循本教程的通知:Push Notification Tutorial

这是我的AppDelegate文件中的didReceiveRemoteNotification函数:

    func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject], fetchCompletionHandler completionHandler: (UIBackgroundFetchResult) -> Void) {


    let aps = userInfo["aps"] as! [String: AnyObject]
    print(aps["content-available"]!)


    if (aps["content-available"]!).intValue == 1 {
        print("Content notification received")

        //Check if user is logged in or not
        if (loggedIn == false) {
            print("Not logged in, so nothing happens")
            //Maybe call completion handler here ?
        } else {

            //Check the value on the device (works well)
            ViewController().getAValueFromTheDevice()

            //Send the value to the Firebase DB (works only one time in background)
            valueRef.setValue("\(valueFromTheDevice)")

            //Maybe call a completion handler here too ?

        }


    }

这很奇怪,因为它只在应用程序处于后台时发送一次数据,否则,“本地”值检查始终有效。

另外,我注意到当我使用“逐步”执行断点时,它总是按预期工作。它是否与完成处理程序相关联?

在我的输出中,当我收到无声通知时,我有两条消息:

  

警告:应用程序委托收到对-application的调用:didReceiveRemoteNotification:fetchCompletionHandler:但是从未调用完成处理程序。

但我不知道在我的代码中要调用什么......

  

FIRMessaging在无效状态2中接收通知

我使用Firebase存储实时数据,但不发送推送通知。

非常感谢任何帮助。

0 个答案:

没有答案
相关问题