Ios 将应用程序从后台移到前台时无法触发didReceive通知委托

Ios 将应用程序从后台移到前台时无法触发didReceive通知委托,ios,swift,xcode8,ios11,Ios,Swift,Xcode8,Ios11,我已经为ios10实现了推送通知。如果我将通知保存在coredata中,或者如果我在前台,点击通知警报将触发“didReceive”委托。问题是,如果我在后台收到一堆通知,当我从后台将我的应用程序带到前台时,如果我可以将我的项目同步到coredata,是否有可能调用“didReceive”委托或任何其他推送通知委托 注意 我不想使用静默通知或点击警报在后台同步(didReceive或任何代理)。当我将应用程序带到前台时,它应该自动同步推送通知堆栈 func handleInboxNot

我已经为ios10实现了推送通知。如果我将通知保存在coredata中,或者如果我在前台,点击通知警报将触发“didReceive”委托。问题是,如果我在后台收到一堆通知,当我从后台将我的应用程序带到前台时,如果我可以将我的项目同步到coredata,是否有可能调用“didReceive”委托或任何其他推送通知委托

注意 我不想使用静默通知或点击警报在后台同步(didReceive或任何代理)。当我将应用程序带到前台时,它应该自动同步推送通知堆栈

     func handleInboxNotification(didReceiveRemoteNotification userInfo: [AnyHashable: Any]) {
    if let inboxValue = userInfo["inbox"] as? String, let value = inboxValue.boolValue(), value {
        let mappedMessage = MessageCenterSDK.shared.constructReorderedDictionary(userInfo: userInfo)
        MessageCenterDataManager.shared.synchronize(messages: mappedMessage)
        messageCenterDelegate?.didFindNewMessages(hasNewMessages: true)
    }
}


func userNotificationCenter(_ center: UNUserNotificationCenter,
                            didReceive response: UNNotificationResponse,
                            withCompletionHandler completionHandler: @escaping () -> Void) {
    /// Handle outbound remote
    handleInboxNotification(didReceiveRemoteNotification: response.notification.request.content.userInfo)
    completionHandler()
}

您需要在appDelegate中使用willpresent委托

    func userNotificationCenter(_ center: UNUserNotificationCenter,
                            willPresent notification: UNNotification,
                            withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
    // Change this to your preferred presentation option
    completionHandler([])
}

在前台收到通知时调用此委托

我也遇到了同样的问题,但我的目标是iOS 13&我正在使用
BGTaskScheduler
在后台以及终止状态下从服务器获取数据

     func handleInboxNotification(didReceiveRemoteNotification userInfo: [AnyHashable: Any]) {
    if let inboxValue = userInfo["inbox"] as? String, let value = inboxValue.boolValue(), value {
        let mappedMessage = MessageCenterSDK.shared.constructReorderedDictionary(userInfo: userInfo)
        MessageCenterDataManager.shared.synchronize(messages: mappedMessage)
        messageCenterDelegate?.didFindNewMessages(hasNewMessages: true)
    }
}


func userNotificationCenter(_ center: UNUserNotificationCenter,
                            didReceive response: UNNotificationResponse,
                            withCompletionHandler completionHandler: @escaping () -> Void) {
    /// Handle outbound remote
    handleInboxNotification(didReceiveRemoteNotification: response.notification.request.content.userInfo)
    completionHandler()
}
我也想在应用程序处于后台时触发通知。但没有点击,但这似乎是不可能的,所以我们改变了我们的实现,启用后台模式,它为我工作

希望这也有帮助


如需有关
BGTaskScheduler

的更多参考信息,请参阅前面的评论。点击警报可以正常工作。。当我将应用程序从前台移到后台时,.didReceive或任何可用的delegate应该work@user578386我已经更新了我的答案。您需要将此功能用于前台notifications@summit您是否能够获取已排队的推送通知字典?您需要从服务器获取所需的数据,如从API或套接字获取数据,因为不点击就无法获取通知的响应。