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

问题描述 投票:0回答:2

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

注意我不想使用无声通知或点击名称在后台同步项目。

     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()
}
ios swift xcode8 ios11
2个回答
0
投票
func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) { // Change this to your preferred presentation option completionHandler([]) }

当您触摸通知时将呼叫此代表


0
投票
我也想在应用程序处于后台但未被点击时触发通知,但这似乎是不可能的,因此我们通过启用后台模式更改了实现方式,并且对我有用。希望它也对您有帮助。

有关BGTaskScheduler的更多参考,https://developer.apple.com/documentation/backgroundtasks/bgtaskscheduler

© www.soinside.com 2019 - 2024. All rights reserved.