LocalNotificationHelper 2.0

LocalNotificationHelper 2.0

测试已测试
Lang语言 SwiftSwift
许可 MIT
发布最后发布2016年11月
SwiftSwift 版本3.0
SPM支持 SPM

Ahmet 维护。



LocalNotificationHelper

Swift 的本地通知助手

关于

LocalNotificationHelper 是一个 Swift 类,它可以帮助您轻松创建和发布本地通知,并为用户通知添加操作按钮。

安装

下载 项目并将源文件夹复制到您的项目中,然后您可以在任何文件中使用它。

使用

  // Create and post local notifications
  LocalNotificationHelper.sharedInstance().scheduleNotificationWithKey("mobiwise", title: "mobiwise", message: "Lets take a break", seconds: 5)

  /*
  LocalNotificationHelper.sharedInstance().scheduleNotificationWithKey(key: <#T##String#>, title: <#T##String#>, message: <#T##String#>, seconds: <#T##Double#>, userInfo: <#T##[NSObject : AnyObject]?#>)
  LocalNotificationHelper.sharedInstance().scheduleNotificationWithKey(key: <#T##String#>, title: <#T##String#>, message: <#T##String#>, date: <#T##NSDate#>, userInfo: <#T##[NSObject : AnyObject]?#>)
  LocalNotificationHelper.sharedInstance().scheduleNotificationWithKey(key: <#T##String#>, title: <#T##String#>, message: <#T##String#>, date: <#T##NSDate#>, soundName: <#T##String#>, userInfo: <#T##[NSObject : AnyObject]?#>)
  LocalNotificationHelper.sharedInstance().scheduleNotificationWithKey(key: <#T##String#>, title: <#T##String#>, message: <#T##String#>, seconds: <#T##Double#>, soundName: <#T##String#>, userInfo: <#T##[NSObject : AnyObject]?#>)
*/

  // Create action buttons and register notification

  let actionOne = LocalNotificationHelper.sharedInstance().createUserNotificationActionButton(identifier: ACTION_ONE_IDENTIFIER, title: "Like")
        let actionTwo = LocalNotificationHelper.sharedInstance().createUserNotificationActionButton(identifier: ACTION_TWO_IDENTIFIER, title: "Dislike")

  let actions = [actionOne,actionTwo]

  LocalNotificationHelper.sharedInstance().registerUserNotificationWithActionButtons(actions: actions)

处理本地通知

  // Catching notifications in appdelegate 
  func application(_ application: UIApplication, didReceive notification: UILocalNotification) {
        print("notification - tapped")
    }

  // Handling action buttons and notifying where you need with notificationCenter  
  func application(_ application: UIApplication, handleActionWithIdentifier identifier: String?, for notification: UILocalNotification, withResponseInfo responseInfo: [AnyHashable : Any], completionHandler: @escaping () -> Void) {
        if identifier == ACTION_ONE_IDENTIFIER {
            print("action one - tapped")

            NotificationCenter.default.post(name: NSNotification.Name(rawValue: ACTION_ONE_IDENTIFIER), object: nil)

        }else if identifier == ACTION_TWO_IDENTIFIER {
            print("action two - tapped")

            NotificationCenter.default.post(name: NSNotification.Name(rawValue: ACTION_TWO_IDENTIFIER), object: nil)

        }

        completionHandler()
    }

许可

MIT 许可(MIT)

版权所有 © 2015 AhmetKeskin

任何获得此软件和相关文档副本(“软件”)的个人均可免费使用本软件,未受到任何限制,包括但不限于使用、复制、修改、合并、发布、分发、再许可和/或销售软件副本的权利,并允许获得本软件的个人将这些副本提供给人使用,但必须遵守以下条件:

上述版权声明和本许可声明应包括在本软件的所有副本或主要部分中。

本软件按“原样”提供,不提供任何明示或暗示的保证,包括但不限于适销性、特定用途和不受侵犯的保证。在任何情况下,作者或版权持有人不对任何索赔、损失或其他责任(无论是基于合同、侵权或其他方式)承担责任,也不论该索赔、损失或其他责任是由本软件或其使用或与其他软件一起使用引起的。