BSForegroundNotification 2.0.1

BSForegroundNotification 2.0.1

测试已测试
语言语言 SwiftSwift
许可证 MIT
发布最新发布2017年3月
SwiftSwift 版本3.0
SPM支持 SPM

kunass2 维护。



  • Bartłomiej Semańczyk

ForegroundNotification

使用方法

要运行示例项目,请克隆仓库,然后首先从 Example 目录运行 `pod install`。

安装

ForegroundNotification 通过 CocoaPods 提供。要安装它,只需在 Podfile 中添加以下行:

pod "BSForegroundNotification"

如果您在 podfile 中使用了 `use_framework`,只需这样做:

import ForegroundNotification

当您需要使用它时,对每个文件进行操作。

您还可以使用

@import ForegroundNotification

桥接头文件 中,以避免为每个需要的文件导入框架。

信息

  • 完全使用最新的 Swift 语法编写。支持 iOS 8 和 9 以及 Xcode7。
  • 要显示本地前台通知,`alertTitle` 和 `alertBody` 都不能为 nil
  • 要显示远程前台通知,在 `alert` 字典中,`title` 和 `body` 都不能为 nil。如果 `alert` 是字符串,则该字符串不能为空。

使用方法

简单创建前台通知对象的三种方式之一
let notification = ForegroundNotification(userInfo: userInfo) //remote
let notification = ForegroundNotification(localNotification: localNotification) //local
let notification = ForegroundNotification(titleLabel: "title", subtitleLabel: "subtitle", categoryIdentifier: "category") //custom initializer
设置默认静态属性
ForegroundNotification.timeToDismissNotification = 4
ForegroundNotification.systemSoundID: SystemSoundID = 1001
设置遵守协议 BSForegroundNotificationDelegate 的代理

请注意,ForegroundNotificationDelegate 继承自 UIApplicationsDelegate

notification.delegate = self
实现 ForegroundNotificationDelegate 的可选方法
@objc public protocol ForegroundNotificationDelegate: class, UIApplicationDelegate {

    optional func foregroundRemoteNotificationWasTouched(with userInfo: [AnyHashable: Any])
    optional func foregroundLocalNotificationWasTouched(with localNotification: UILocalNotification)
}
然后显示通知
notification.presentNotification()
如果需要,将调用 ForegroundNotificationDelegate 类中的一个方法
func application(application: UIApplication, handleActionWithIdentifier identifier: String?, forRemoteNotification userInfo: [AnyHashable: Any], completionHandler: () -> Void)
func application(application: UIApplication, handleActionWithIdentifier identifier: String?, forRemoteNotification userInfo: [AnyHashable: Any], withResponseInfo responseInfo: [AnyHashable: Any], completionHandler: () -> Void)
func application(application: UIApplication, handleActionWithIdentifier identifier: String?, forLocalNotification notification: UILocalNotification, completionHandler: () -> Void)
func application(application: UIApplication, handleActionWithIdentifier identifier: String?, forLocalNotification notification: UILocalNotification, withResponseInfo responseInfo: [AnyHashable: Any], completionHandler: () -> Void)

作者

Bartłomiej Semańczyk,[email protected]

许可证

BSForegroundNotification 可在 MIT 许可证下使用。更多信息请参阅 LICENSE 文件。