Simple Swift in-app notifications

Overview

LNRSimpleNotifications

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.

Budweiser Made in America Screenshot LNRSimpleNotifications Demo Screenshot Wakarusa Screenshot

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 [email protected].

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 [email protected].

License

LNRSimpleNotifications is available under the MIT license. See LICENSE.txt for details.

Credits

LNRSimpleNotifications is based on TSMessages, developed by Felix Krause. If LNRSimpleNotifications isn't quite what you're looking for we recommend you check it out.

Comments
  • Demo Xcode 8.2.1 / Swift 3 (Unresolved identifier)

    Demo Xcode 8.2.1 / Swift 3 (Unresolved identifier)

    Hi there,

    I'm trying to test your lib. With the demo project (after pod install) I have this issue from compiler :

    /LNRSimpleNotifications/LNRSimpleNotificationsDemo/LNRSimpleNotificationsDemo/ViewController.swift:56:60: Use of unresolved identifier 'LNRNotification'

    opened by ghost 4
  • Add @objc annotation to public methods

    Add @objc annotation to public methods

    This was the default behaviour in Swift 3 - the compiler inferred all these annotations automatically. Now in Swift 4, the compiler does not automatically infer these anymore and its necessary to explicitly add these @objc annotations to methods that should be available in ObjC.

    opened by iv-mexx 2
  • Verision 0.7.0 has not been released

    Verision 0.7.0 has not been released

    It seems the version is not included in https://github.com/CocoaPods/Specs/tree/master/Specs/e/4/1/LNRSimpleNotifications either. So I guess it is not me.

    pod search LNRSimpleNotifications (after repo update) will show the output:

    -> LNRSimpleNotifications (0.6.1)
       Simple Swift in-app notifications.
       pod 'LNRSimpleNotifications', '~> 0.6.1'
       - Homepage: https://github.com/LISNR/LNRSimpleNotifications
       - Source:   https://github.com/LISNR/LNRSimpleNotifications.git
       - Versions: 0.6.1, 0.6.0, 0.5.3, 0.5.2, 0.4.2, 0.4.1, 0.4.0, 0.3.0, 0.2.3, 0.2.2, 0.2.1, 0.2.0, 0.1.2, 0.1.1, 0.1.0 [master
       repo]
    

    I think nobody executed pod trunk push LNRSimpleNotifications.podspec. For more information see https://guides.cocoapods.org/making/making-a-cocoapod.html

    opened by dkk 1
  • Add configurable notifications queue

    Add configurable notifications queue

    Closes #21

    With these changes, notifications can be configured to be displayed in a queue.

    To enable the feature simply add in the class that triggers notifications:

    notificationManager.notificationsQueueEnabled = true
    

    Defaults to false to keep previous behaviour.

    Notifications are stored in an array of:

    class LNRNotification {
        var title: String
        var body: String
        var onTap: LNRNotificationOperationCompletionBlock
    
        init(title: String, body: String, onTap: @escaping LNRNotificationOperationCompletionBlock) {
            self.title = title
            self.body = body
            self.onTap = onTap
        }
    }
    
    opened by danielfmoreira 1
  • Add notifications queue

    Add notifications queue

    When i receive a number of notifications simultaneously or in a short period of time, I would like them to remain in a queue.

    Instead of immediately replacing each other as they get triggered, they would wait for the currently displayed notification to be dismissed.

    This way all notifications can be seen and read easily by the user.

    opened by danielfmoreira 1
  • Update the width to use the width of the window instead of the screen.

    Update the width to use the width of the window instead of the screen.

    When an app is in multitasking mode (on iPad), the width of the notification extends beyond the width of the window.

    This happens on iPad when apps are in side-by-side mode.

    I changed these lines in LNRNotificationView

    let notificationWidth: CGFloat = (UIApplication.sharedApplication().keyWindow?.bounds.width)!
    
    override public func layoutSubviews() {
            super.layoutSubviews()
            self.notificationViewHeightAfterLayoutOutSubviews(kLNRNotificationViewMinimumPadding, notificationWidth: (UIApplication.sharedApplication().keyWindow?.bounds.width)!)
        }
    
    opened by moshegutman 1
  • One shoot notification

    One shoot notification

    Hello!

    Exists any way for show a different notification from sharedInstace?

    I have this code :

    let notification = LNRSimpleNotifications()

        notification.notificationsPosition = LNRNotificationPosition.Top
        notification.notificationsBackgroundColor = UIColor.blueColor()
        notification.notificationsTitleTextColor = UIColor.whiteColor()
        notification.notificationsBodyTextColor = UIColor.whiteColor()
    
        notification.showNotification("Guardada correctamente", body: nil, callback: nil)
    

    Show a notification and crashes!

    opened by josete89 1
  • fix width of title label to respect padding and image

    fix width of title label to respect padding and image

    The width of the titleLabel was set to the whole notificationWidth, not respecting the padding and not respecting the presence of an image.

    This lead to the following Bug:

    screen shot 2015-11-19 at 14 06 27 2 screen shot 2015-11-19 at 14 06 51 2

    Fixed

    With this fix these now look like that:

    screen shot 2015-11-19 at 14 16 17 2 screen shot 2015-11-19 at 14 17 12 2

    Autolayout

    Btw, would it not be better to use Autolayout?

    opened by iv-mexx 1
  • Solved warnings related to deprecated String properties

    Solved warnings related to deprecated String properties

    Xcode 9.1 is throwing 2 warnings of the type: 'characters' is deprecated: Please use String or Substring directly

    when including the pod directly as pod 'LNRSimpleNotifications' in the podfile.

    This should solve the issue

    opened by dkk 0
  • Swift3 with UIImageView Setup and Async UIImageView

    Swift3 with UIImageView Setup and Async UIImageView

    Allows for async UIImageView Allows for customizing the UIImageView with a block

    notificationManager1.notificationsIconImageViewSetup = { imageView in
                imageView.backgroundColor = UIColor.red
    }
    notificationManager1.notificationsIconAsyncLoader = { completionHandler in
                let url = URL(string: "https://homepages.cae.wisc.edu/~ece533/images/airplane.png")
                URLSession.shared.dataTask(with: url!, completionHandler: { (data, response, error) in
                    guard let data = data  else { return }
                    let downloadedData = UIImage(data: data)
                    completionHandler(downloadedData)
                }).resume()
    }
    
    opened by mbalex99 0
  • Update the width to use the width of the window instead of the screen.

    Update the width to use the width of the window instead of the screen.

    When an app is in multitasking mode (on iPad), the width of the notification extends beyond the width of the window.

    This happens on iPad when apps are in side-by-side mode.

    I changed these lines in LNRNotificationView

    let notificationWidth: CGFloat = (UIApplication.sharedApplication().keyWindow?.bounds.width)!
    
    override public func layoutSubviews() {
            super.layoutSubviews()
            self.notificationViewHeightAfterLayoutOutSubviews(kLNRNotificationViewMinimumPadding, notificationWidth: (UIApplication.sharedApplication().keyWindow?.bounds.width)!)
        }
    
    opened by moshegutman 0
  • Swift3

    Swift3

    Notifications with Async Image Loader

    Perhaps you'd like an asynchronous image. You'll need to create a variable of LNRNotificationAsyncImageBlock and pass it in on the show showNotification method.

    Important: You will need to set an image on the Manager Instance like so:

    notificationManager.notificationsIcon = UIImage(named: "lisnr-cir-bw-notifications-icon")
    
    let imageAsyncLoader : LNRNotificationAsyncImageBlock = { completionHandler in
                let url = URL(string: "https://homepages.cae.wisc.edu/~ece533/images/airplane.png")
                URLSession.shared.dataTask(with: url!, completionHandler: { (data, response, error) in
                    guard let data = data  else { return }
                    let downloadedData = UIImage(data: data)
                    completionHandler(downloadedData)
                }).resume()
            }
    
    
    // Important to set the placeholder image
    notificationManager.notificationsIcon = UIImage(named: "lisnr-cir-bw-notifications-icon")
    // Call the showNotification method
    notificationManager.showNotification(
                title: "Hipster Ipsum",
                body: "I love nier",
                imageAsyncLoader:  imageAsyncLoader
            )
    

    Customizing the Icon UIImageView

    You'll need to create a variable conforming to the block LNRNotificationImageViewSetupBlock. Then you can pass it into the showNotification block.

    let imageViewSetup : LNRNotificationImageViewSetupBlock = { imageView in
                imageView.backgroundColor = UIColor.red
            }
    
    // Important to set the placeholder image
    notificationManager.notificationsIcon = UIImage(named: "lisnr-cir-bw-notifications-icon")
    // Call the showNotification method
    notificationManager.showNotification(
                title: "Hipster Ipsum",
                body: "I love nier",
                imageViewSetup:  imageViewSetup
            )
    
    opened by mbalex99 0
Owner
LISNR
LISNR
A simple style messages/notifications, in Swift.

Demo Example To show notifications use the following code: self.showMessage("Something success", type: .success) To display a notice on a view: view.s

Gesen 704 Dec 17, 2022
CoffeeToast - A swift package to easily add Toast notifications to your app

CoffeeToast A simple Swift package to add Toast Notifications to your app. Insta

Maegan Wilson 2 Feb 3, 2022
SwiftOverlays is a Swift GUI library for displaying various popups and notifications

SwiftOverlays is a Swift GUI library for displaying various popups and notifications. SwiftOverlays animated logo is kindly made by Crafted Pixels Fea

Peter Prokop 632 Dec 22, 2022
A Swift extension that adds toast notifications to the UIView object class.

Toast-Swift Toast-Swift is a Swift extension that adds toast notifications to the UIView object class. It is intended to be simple, lightweight, and e

Charles Scalesse 3.3k Dec 22, 2022
💌 Easy to use and customizable messages/notifications for iOS à la Tweetbot

Notice: TSMessages is no longer being maintained/updated. We recommend everyone migrate to RMessage. This repository will be kept as is for those who

Felix Krause 4.9k Dec 31, 2022
[iOS] Easy, customizable notifications displayed on top of the statusbar. With progress and activity. iPhone X ready.

JDStatusBarNotification Show messages on top of the status bar. Customizable colors, font and animation. Supports progress display and can show an act

M Emrich 3.8k Dec 27, 2022
Customizable simple Alert and simple ActionSheet for Swift

SimpleAlert It is simple and easily customizable alert. Can be used as UIAlertController. Appetize's Demo Requirements Swift 5.0 iOS 9.0 or later How

Kyohei Ito 397 Dec 6, 2022
Simple app to help understanding the spoken text in islamic prayers.

About • Community Forum • App Store • Donation • Contributing • License About You regularly pray your prayers in Arabic, but do not really understand

Flinesoft 29 Nov 17, 2022
Simple UIAlertController builder class in Swift.

Kamagari Simple UIAlertController builder class in Swift. Features AlertBuilder class to simply build UIAlertController by using method chaining UIAle

Kazunobu Tasaka 78 Nov 29, 2022
A simple, customizable popup dialog for iOS written in Swift. Replaces UIAlertController alert style.

Introduction Popup Dialog is a simple, customizable popup dialog written in Swift. Features Easy to use API with hardly any boilerplate code Convenien

Orderella Ltd. 3.8k Dec 20, 2022
Lightweight dropdown message bar in Swift. It's simple and beautiful.

SwiftyDrop SwiftyDrop is a lightweight pure Swift simple and beautiful dropdown message. Features Easy to use like: Drop.down("Message") Message field

Morita Naoki 691 Nov 20, 2022
Simple Alert View written in Swift, which can be used as a UIAlertController. (AlertController/AlertView/ActionSheet)

DOAlertController Simple Alert View written in Swift, which can be used as a UIAlertController replacement. It supports from iOS7! It is simple and ea

Daiki Okumura 406 Sep 5, 2022
😍A simple NoticeBar written by Swift 3, similar with QQ notice view.

NoticeBar ?? A simple NoticeBar written by Swift 3, similar with QQ notice view. ?? ScreenShots Remember: If you want the status bar style change, you

Qiun Cheng 235 Sep 9, 2022
A Simple Customizable Alert With Swift

SimpleCustomizableAlert trying to make my very first library. Support Title Message (TextView) Image TextField Button Action Example let alert

null 1 Oct 26, 2021
A simple custom popup dialog view for iOS written in Swift. Replaces UIAlertController alert style.

A simple custom popup dialog view for iOS written in Swift. Replaces UIAlertController alert style.

donggyu 5 Jan 26, 2022
BottomSheet makes it easy to take advantage of the new UISheetPresentationController in SwiftUI with a simple .bottomSheet modifier on existing views.

BottomSheet makes it easy to take advantage of the new UISheetPresentationController in SwiftUI with a simple .bottomSheet modifier on existing views.

Adam Foot 341 Dec 15, 2022
🌊 - Jelly is a library for animated, non-interactive & interactive viewcontroller transitions and presentations with the focus on a simple and yet flexible API.

Jelly is a library for animated, non-interactive & interactive viewcontroller transitions and presentations with the focus on a simple and yet flexibl

Sebastian Boldt 2.4k Dec 25, 2022
iOS / Objective C: an extremely simple UIAlertView alternative

RKDropdownAlert an extremely simple (and customizeable) alert alternative based on Facebook's app Slingshot, and inspiration from SVProgressHUD (yes,

Richard Kim 1.5k Nov 20, 2022
zekunyan 608 Dec 30, 2022