didReceiveRemoteNotification:fetchCompletionHandler не вызывается, когда приложение (iOS 11.0.2) находится в фоновом режиме и не подключено к Xcode 9.0

Когда приложение находится в фоновом режиме и подключено к Xcode, все работает нормально, но когда я отключаю любое устройство iOS и запускаю приложение, перехожу в фоновый режим и отправляю удаленное уведомление, didReceiveRemoteNotification:fetchCompletionHandler не вызывается.

Вот фрагмент кода:

func application(_ application: UIApplication,
                 didFailToRegisterForRemoteNotificationsWithError error: Error) {
    print("Failed to register: \(error)")
}

// MARK: - Notification Delegate
func application(_ application: UIApplication,
                 didReceiveRemoteNotification userInfo: [AnyHashable : Any],
                 fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {

    if UserDefaults.standard.value(forKey: Constants.Key.authToken) != nil {

        print("Payload is: \(userInfo)")

        var dataDict : [String:Any] = [:]
        if (userInfo["data"] != nil){
            dataDict = userInfo["data"] as! [String : Any]
        }

        // ID : notification type
        var idType = 0
        if (dataDict["id"] != nil){
            idType = dataDict["id"] as! Int
        }

        let state = UIApplication.shared.applicationState
        print("state is \(state)")

        // Application in forground state...
        if state == .active {
            self.postNotificationOfType(idType, dict: dataDict)
        }

        // Application in background state...
        else if state == .background || state == .inactive {
            self.postNotificationOfType(idType, dict: dataDict)
        }


    }
    else{
        print("User is logged out!")
    }

    completionHandler(.newData)

}

func postNotificationOfType(_ idType:Int, dict:[String:Any]){

    // service request received
    if idType == 1{

        if (dict["serviceRequestId"] != nil){
            NotificationCenter.default.post(name: Notification.Name("ServiceRequestReceived"), object: nil, userInfo: dict)
        }
    }

    // service request canceled by client
    else if idType == 2 {
        NotificationCenter.default.post(name: Notification.Name("ServiceRequestCanceled"), object: nil)
    }

    // service started by client
    else if idType == 5 {
        NotificationCenter.default.post(name: Notification.Name("ServiceStartedByClient"), object: nil)
    }

        // service started by client
    else if idType == 6 {
        NotificationCenter.default.post(name: Notification.Name("ServiceEndedByClient"), object: nil)
    }
}

Вот моя полезная нагрузка:

 {
"aps" : {
    "content-available" : 1
},
"data" : 1

}

Любая помощь будет оценена. Заранее спасибо.


person Arun    schedule 14.11.2017    source источник
comment
это известная проблема в iOS11.0 – › Apple исправила ее в iOS11.1 – › см. также stackoverflow.com/questions/46330053/   -  person AlexWoe89    schedule 21.11.2017
comment
Все еще проблема с iOS 11.1.1, и я не получил никакой помощи от вашей справочной ссылки.   -  person Arun    schedule 29.11.2017