LNRSimpleNotifictions
  • October 27, 2023

TSMessages is an amazingly powerful in-app notifications library but requires a lot of setup. LNRSimpleNotifications is a simplified version for the developer who wants beautiful in-app notifications in minutes.

How do I set it up?


We’re glad you asked.

If your project is in Swift:

  1. Add LNRSimpleNotifications to your Podfile or Package.swift.
  2. Add the AudioToolbox framework to your project.
  3. Add import LNRSimpleNotifications in the classes you want to trigger or style your in-app notifications.
  4. (Optional) Style your notifications in the class managing your notification’s initializer.
  5. There is no step Five.

If your project is in Objective-C:

  1. Add LNRSimpleNotifications to your Podfile.
  2. Add the AudioToolbox framework to your project.
  3. Set “Defines Modules” to Yes in your build settings.
  4. Import the LNRSimpleNotification module’s Xcode-generated Swift header file in the classes you want to trigger and style your in-app notifications. The name of this header should be #import <LNRSimpleNotifications/LNRSimpleNotifications-Swift.h>.
  5. (Optional) Style your notifications in the class managing your notification’s initializer.

Demo Project


To run the demo project clone the repo, and run pod install from the Example directory first.

How do I use it?


Configure your notification styles once in your app. The init method for whatever class is triggering your in-app notifications is a good choice.

The Class Triggering Notifications

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
}

You can also configure an icon that will appear in your notification and set a custom font for the notification title and body.

If you don’t set any theme options your notifications will default to black text on a white background with no notification sound or icon.

The Class Triggering Notifications

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”)
}))
}

Who’s using LNRSimpleNotifications?


 

At the moment we know we’ve used it in:

We’re doing more music festivals this year, so you’ll see our simple yet stylish notifications in our apps a few more times this Summer and Fall.

Have you used LNRSimpleNotifications in a project? Want your app featured here? Let us know at dev@lisnr.com.

Known Bugs


Since 0.1.0

  1. If you trigger notifications very rapidly they’ll start appearing immediately instead of waiting for the one before to be dismissed before displaying. If this happens notifications will start appearing over notifications that were already on screen.

Pull Requests?


Absolutely!

About LISNR


LISNR is a startup leveraging ultrasonic audio to transmit data between devices without a network. Using our technology we have synchronized light shows on phones at concerts, triggered location-based notifications, rewarded music fans with behind-the-scenes content, delivered at-shelf product information, and made art galleries come alive.

Want to know more about LISNR? Reach out to inquiries@lisnr.com.

GitHub


View Github

#framwork #library #objectivec #swift #xcode
YOU MIGHT ALSO LIKE...
🧭 NavigationKit

NavigationKit is a lightweight library which makes SwiftUI navigation super easy to use. 💻 Installation 📦 Swift Package Manager Using Swift Package Manager, add ...

swiftui-navigation-stack

An alternative SwiftUI NavigationView implementing classic stack-based navigation giving also some more control on animations and programmatic navigation. NavigationStack Installation ...

Stinsen

Simple, powerful and elegant implementation of the Coordinator pattern in SwiftUI. Stinsen is written using 100% SwiftUI which makes it ...

SwiftUI Router

With SwiftUI Router you can power your SwiftUI app with path-based routing. By utilizing a path-based system, navigation in your app becomes ...

FlowStacks

This package takes SwiftUI's familiar and powerful NavigationStack API and gives it superpowers, allowing you to use the same API not just ...