简体   繁体   English

离线本地通知(快速)

[英]Local Notification on offline (Swift)

I want to receive a local notification in my app (swift) when I'm not connected to Internet and I have some information registered in my Local Data base. 当我未连接到Internet并且我的本地数据库中注册了一些信息时,我想在我的应用程序中(Swift)接收本地通知。 Is it possible to do that please? 请问有可能这样做吗?

Local Notification doesnot requires internet. 本地通知不需要互联网。 About Local Notification from apple developer site 关于来自Apple开发人员站点的本地通知

Local notifications give you a way to alert the user at times when your app might not be running. 本地通知为您提供了一种在应用程序可能未运行时提醒用户的方法。 You schedule local notifications at a time when your app is running either in the foreground or background. 您可以在应用程序在前台或后台运行时安排一次本地通知。 After scheduling a notification, the system takes on the responsibility of delivering the notification to the user at the appropriate time. 安排通知后,系统负责在适当的时间将通知传递给用户。 Your app does not need to be running for the system to deliver the notification. 您的应用无需运行,系统即可传递通知。

For more info check this link. 有关更多信息,请单击链接。 You can also check this link for tutorial. 您也可以检查链接以获取教程。

do like this : 这样做:

    public func presentNotification(_ notifAction: String, notifBody: String) {
    let application = UIApplication.shared
    let applicationState = application.applicationState

    if applicationState == UIApplicationState.background {
        let localNotification = UILocalNotification()
        localNotification.alertBody = notifBody
        localNotification.alertAction = notifAction
        localNotification.soundName = UILocalNotificationDefaultSoundName
        localNotification.applicationIconBadgeNumber += 1
        application.presentLocalNotificationNow(localNotification)
    }
}

UIApplicationState has these states : UIApplicationState具有以下状态:

    case active

    case inactive

    case background

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM