Git Product home page Git Product logo

robin's Introduction

Robin

Platform Version Swift 4.2 CI Status License

Robin is a universal notification interface for iOS that handles both UILocalNotification and UserNotifications behind the scenes.

Requirements

  • iOS 10.0+
  • Xcode 8.0+
  • Swift 4.2+

Communication

  • If you need help or have a question, use 'robin' tag on Stack Overflow.
  • If you found a bug or have a feature request, please open an issue.
  • If you want to contribute, please submit a pull request.

Installation

Robin is available through CocoaPods. To install it, simply add the following line to your Podfile.

pod 'Robin', '~> 0.1.1'

For Swift 3, use:

pod 'Robin', '0.1.0'

Usage

import Robin

Before using Robin, you need to request permission to send notifications to users. The following requests badge, sound, and alert permissions.

Robin.shared.requestAuthorization(forOptions: [.badge, .sound, .alert])

This is equivalent to:

Robin.shared.requestAuthorization()

Notifications

Scheduling iOS notifications via Robin is carried over by manipulating RobinNotification objects. To create a RobinNotification object, simply call its initializer.

init(identifier: String = default, body: String, date: Date = default)

Example notification, with a unique identifier, to be fired an hour from now.

let notification = RobinNotification(body: "A notification", date: Date().next(hours: 1))

next(minutes:), next(hours:), and next(days:) are part of a Date extension.

The following table summarizes all RobinNotification properties.

Property Type Description
badge NSNumber? The number the notification should display on the app icon.
body String! The body string of the notification.
date Date! The date in which the notification is set to fire on.
identifier[1] String! A string assigned to the notification for later access.
repeats Repeats The repeat interval of the notification. One of none (default), hour, day, week, or month.
scheduled Bool The status of the notification. read-only
sound RobinNotificationSound The sound name of the notification.
title String? The title string of the notification.
userInfo[2] [AnyHashable : Any]! A dictionary that holds additional information.

[1] identifier is read-only after RobinNotification is initialized.

[2] To add and remove keys in userInfo, use setUserInfo(value: Any, forKey: AnyHashable) and removeUserInfoValue(forKey: AnyHashable) respectively.

Schedule a notification

After creating a RobinNotification object, it can be scheduled using schedule(notification:).

let scheduledNotification = Robin.shared.schedule(notification: notification)

Now scheduledNotification is a valid RobinNotification object if it is successfully scheduled or nil otherwise.

Retrieve a notification

Simply retrieve a scheduled notification by calling notification(withIdentifier: String) -> RobinNotification?.

let scheduledNotification = Robin.shared.notification(withIdentifier: "identifier")

Cancel a notification

To cancel a notification, either call cancel(notification: RobinNotification) or cancel(withIdentifier: String)

Robin.shared.cancel(notification: scheduledNotification)
Robin.shared.cancel(withIdentifier: scheduledNotification.identifier)

Robin allows you to cancel all scheduled notifications by calling cancelAll()

Robin.shared.cancelAll()

Notes

Robin is preset to allow 60 notifications to be scheduled by iOS. The remaining four slots are kept for the app-defined notifications. These free slots are currently not handled by Robin; if you use Robin to utilize these slots, the notifications will be discarded. To change the maximum allowed, just update Robin.maximumAllowedNotifications.

Robin can handle multiple notifications, having the same identifier, scheduled on iOS versions prior to iOS 10 only. Scheduling multiple notifications with the same identifier on iOS 10+ is not allowed.

Author

Ahmed Abdelbadie, [email protected]

License

Robin is available under the MIT license. See the LICENSE file for more info.

robin's People

Contributors

ahmdx avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.