Giter Club home page Giter Club logo

localnotificationscheduler's Introduction

LocalNotificationScheduler

Introduction

LocalNotificationScheduler is an easier method to schedule local notifications in your project. It can schedule different types of local notifocations with one line of code.

Requirements

  • Swift 4.2+
  • iOS 10.0+
  • Xcode 9.0+

Installation

CocoaPods

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

pod 'LocalNotificationScheduler'

and import the library in a page where you use

import LocalNotificationScheduler

Usage

LocalNotificationScheduler provided three methods to schedule notifications. Every method has an optional completion handler that returns error if there was any problem in scheduling notifications. Error can be notifications permissions error in case of normal notifications or location permissions error incase of region monitoring notifications.

To schedule notifications you can use shared instance:

NotificationScheduler.shared

or create your own instance if you want to handle delegate methods yourself

let scheduler = NotificationScheduler(withDelegate: self)

Schedule Calendar Notifications

  • Below method can be used to fire notification at some specific date time.
  • User can set notification with only date, repeating, identifier and title.
let date = NSDate().addingTimeInterval(100)
NotificationScheduler.shared.scheduleNotificationWithFireDate(date as Date, repeatInterval:.hour, identifier: "hourly_repeating", title: "Hours Repeat")
  • Or user can use some/all parameters to schedule notifications. Most parametes are optional so can be skipped from the function.
import UserNotifications

NotificationScheduler.shared.scheduleNotificationWithFireDate(date as Date, repeatInterval: .month, identifier: "monthly_repeating", title: "This notification repeats every month", subTitle: "This notification repeats every month", body: "This notification repeats every month", badge: NSNumber(value: 10), categoryIdentifier: "categortOne", threadIdentifier: "threadOne", launchImageName: nil, sound: UNNotificationSound.default, userInfo: ["paramOne": 10], attachments: []) { (error) in

}

Schedule Time Interval Notifications

  • This method can be used to schedule notifications that fire after specific time interval in seconds.
NotificationScheduler.shared.scheduleNotificationWithTimeInterval(200, repeats: true, identifier: "time_interval", title: "This notification fires after 200 seconds.", subTitle: "This notification fires after 200 seconds.", completion: { error in
print(error)
})
})

Schedule Region Monitoring Notifications

  • Before scheduling any notifications using this method, your app must have authorization to use Core Location and must have when-in-use permissions. If you don't have location authorization then this method will throw an error.
  • This method can be used to schedule notifications that monitor circular region.
import CoreLocation

let toBeMonitoredRegion = CLCircularRegion(center: CLLocationCoordinate2DMake(48.424080, -123.363826), radius: 1000, identifier: "home")
toBeMonitoredRegion.notifyOnExit = true
toBeMonitoredRegion.notifyOnEntry = true
NotificationScheduler.shared.scheduleNotificationWithRegion(toBeMonitoredRegion, repeats: true, identifier: "region_home", title: "You have entered/exited your home")

Author

harishchopra86, [email protected], [email protected]

License

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

localnotificationscheduler's People

Watchers

 avatar

Forkers

dragonetail

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.