2017-07-27 72 views
-1

我想在我的应用程序(swift)中接收本地通知,当我没有连接到Internet时,并且我的一些信息已注册在本地数据库中。 请问可以这样做吗?离线本地通知(Swift)

+1

是的,你可以使用userlocalnotification –

+1

来自ios 10,你可以使用用户通知框架。您可以通过https://www.appcoda.com/ios10-user-notifications-guide/查看该链接。 – luckyShubhra

+1

查看本教程获取本地通知 http://jamesonquave.com/blog/local-notifications-in-ios-8-with-swift-part-1/ –

回答

2

本地通知不列入需要互联网。 关于本地通知来自苹果开发人员网站

本地通知为您提供了一种在应用程序未运行时提醒用户的方法。当您的应用在前台或后台运行时,您可以安排本地通知。在安排通知后,系统负责在适当的时候向用户发送通知。您的应用程序无需运行系统即可发送通知。

欲了解更多信息,请查阅this链接。您也可以检查this链接了解教程。

+0

谢谢这些是我正在寻找的答案:) –

+0

我很高兴我能帮助你! – luckyShubhra

1

这样做:

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有以下状态:

case active 

    case inactive 

    case background