手机重启后 iOS 静默通知不起作用

问题描述

使用静通知功能以编程方式从 didReceiveRemoteNotification 绘制通知。除非用户重新启动手机并且至少没有应用一次,否则一切正常。

代码

func application(_ application: UIApplication,didReceiveRemoteNotification userInfo: [AnyHashable: Any],fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void)
{
    
    let localnotification = UNMutableNotificationContent()
    localnotification.sound = UNNotificationSound.default
    localnotification.userInfo = userInfo
    
    
    if (UIApplication.shared.applicationState != .inactive) {
        
        if UserDetails.language == "ar"{
            localnotification.body = (userInfo["display_message_ar"] as? String ?? "").withoutHtml
            localnotification.title = (userInfo["title"] as? String ?? "").withoutHtml
        }else{
            localnotification.body = (userInfo["display_message_en"] as? String ?? "").withoutHtml
            localnotification.title = (userInfo["title"] as? String ?? "").withoutHtml
        }
        
    }
    
    let trigger = UNTimeIntervalNotificationTrigger(timeInterval: 0.1,repeats: false)
    let request = UNNotificationRequest(identifier: "TempPush",content: localnotification,trigger: trigger)
    let center = UNUserNotificationCenter.current()
    
    if (UIApplication.topViewController() as? ChatVC) != nil {
        
    }
    else
    {
        center.add(request,withCompletionHandler: { error in
        })
    }
    
    completionHandler(UIBackgroundFetchResult.newData)
}

背景模式:

enter image description here

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)