Create a persistent notification in iOS

前端 未结 2 1607
生来不讨喜
生来不讨喜 2021-01-14 15:15

Is there any way to create a notification that cannot be dismissed in iOS? It can even be a workaround (e.g. listening for the notification to be cleared and showing up a ne

相关标签:
2条回答
  • 2021-01-14 15:37

    I found that if you use the old APIs the notification will not disappear.

    I used pre-iOS 10 API and it worked.

    let notification = UILocalNotification()
    notification.fireDate = Date().addingTimeInterval(10) // post after 10 seconds
    if #available(iOS 8.2, *) {
        notification.alertTitle = "Title"
    }
    notification.alertBody = "Your message"
    
    notification.soundName = UILocalNotificationDefaultSoundName
    UIApplication.shared.scheduleLocalNotification(notification)
    

    Tested this on iOS 12.1 and the notification did not disappear. If I were to use UNMutableNotificationContent the notification would disappear.

    0 讨论(0)
  • 2021-01-14 15:39

    No. You could schedule a bunch of notifications but that's different. There is no way to listen to when the notification is dismissed, keep it on the screen, or do anything that changes it's performance as it's all handled outside of your app.

    0 讨论(0)
提交回复
热议问题