LNRSimpleNotifications
TSMessages 是一个功能强大的内联通知库,但需要大量配置。 LNRSimpleNotifications 为想要快速获得美观内联通知的开发者提供了一个简化的版本。
如何设置它?
我们很高兴您提出了这个问题。
如果您的项目使用 Swift 编写
- 将 LNRSimpleNotifications 添加到您的 Podfile 或 Package.swift。
- 将 AudioToolbox 框架添加到您的项目中。
- 在您想触发或美化您的内联通知的类中添加 import LNRSimpleNotifications。
- (可选) 在管理您的通知初始化器的类中设置通知样式。
- 没有第五步。
如果您的项目使用 Objective-C 编写
- 将 LNRSimpleNotifications 添加到您的 Podfile。
- 将 AudioToolbox 框架添加到您的项目中。
- 在编译设置中,将 "defines Modules" 设置为 是。
- 将 Xcode 生成的 LNRSimpleNotification 模块的头文件导入到您要触发和美化您的内联通知的类中。该头文件的名称应为 #import <LNRSimpleNotifications/LNRSimpleNotifications-Swift.h>。
- (可选) 在管理您的通知初始化器的类中设置通知样式。
示例项目
为了运行示例项目,请先克隆仓库,然后从 Example 目录中运行 pod install
。
我该如何使用它?
在您的应用中只需一次配置通知样式。触发您应用内通知的任何类的初始化方法是一个不错的选择。
触发通知的类
import LNRSimpleNotifications
import AudioToolbox
###
let notificationManager = LNRNotificationManager()
func init() {
super.init()
notificationManager.notificationsPosition = LNRNotificationPosition.Top
notificationManager.notificationsBackgroundColor = UIColor.whiteColor()
notificationManager.notificationsTitleTextColor = UIColor.blackColor()
notificationManager.notificationsBodyTextColor = UIColor.darkGrayColor()
notificationManager.notificationsSeperatorColor = UIColor.grayColor()
var alertSoundURL: NSURL? = NSBundle.mainBundle().URLForResource("click", withExtension: "wav")
if let _ = alertSoundURL {
var mySound: SystemSoundID = 0
AudioServicesCreateSystemSoundID(alertSoundURL!, &mySound)
notificationManager.notificationSound = mySound
}
return true
}
你还可以配置一个将在通知中显示的图标,并为通知标题和内容设置自定义字体。
如果您不设置任何主题选项,您的通知将默认为黑色文本在白色背景下,没有通知声音或图标。
触发通知的类
let notificationManager = LNRNotificationManager()
###
func methodThatTriggersNotification:(title: String, body: String) {
notificationManager.showNotification(notification: LNRNotification(title: title, body: body, duration: LNRNotificationDuration.default.rawValue, onTap: { () -> Void in
print("Notification Dismissed")
}, onTimeout: { () -> Void in
print("Notification Timed Out")
}))
}
谁正在使用LNRSimpleNotifications?
目前我们知道我们已经在以下应用中使用它
今年我们将举办更多音乐节,所以您将在今年夏末和秋初在我们的应用中看到我们的简单而时尚的通知几次。
您在一个项目中使用过LNRSimpleNotifications吗?想在这里展示您的应用吗?请通过 [email protected] 联系我们。
已知错误
自 0.1.0
- 如果您快速触发通知,它们将立即出现,而不是等待上一个通知被清除后再显示。如果发生这种情况,新通知将覆盖屏幕上已有的旧通知。
拉取请求?
当然!
关于 LISNR
LISNR 是一家利用超声波音频在设备之间传输数据而不需要网络的初创公司。使用我们的技术,我们已经在音乐会上同步了手机的灯光秀、触发了基于位置的提醒、对音乐爱好者提供了幕后内容奖励、提供了货架商品信息,并使艺术画廊栩栩如生。
想了解更多关于 LISNR 的信息?请联系 [email protected]。
许可证
LNRSimpleNotifications 在 MIT 许可证下可用。详情请参阅 LICENSE.txt。
致谢
LNRSimpleNotifications 基于由 Felix Krause 开发的 TSMessages。如果您对 LNRSimpleNotifications 没有找到合适的内容,我们建议您查看 它。