Coder Social home page Coder Social logo

jpedrosg / mmnotifications Goto Github PK

View Code? Open in Web Editor NEW

This project forked from matmartinez/mmnotifications

0.0 0.0 0.0 369 KB

A simple and customizable way to display in-app notifications on iOS.

License: MIT License

Ruby 0.78% Objective-C 99.22%

mmnotifications's Introduction

MMNotifications

A simple and customizable way to display in-app notifications. They match the system's look and feel, fully supporting iPhone X and the iPad.

MMNotifications

Installation

From CocoaPods

CocoaPods is a dependency manager for Objective-C, which automates and simplifies the process of using 3rd-party libraries like MMNotifications in your projects. First, add the following line to your Podfile:

pod 'MMNotifications'

Second, install MMNotifications into your project:

pod install

Usage

If you ever tried the local notifications API, this will be easy as pie.

You create a MMLocalNotification object and set a title, message, and image:

// Create and configure the notification.
MMLocalNotification *notification = [[MMLocalNotification alloc] init];
notification.title = @"This is a simple notification";
notification.message = @"The message goes here.";
notification.image = [UIImage imageNamed:@"ExampleIcon"];

You can optionally add some actions! These will be displayed in the notification itself:

// Add action an "Okay" button:
MMNotificationAction *okay = [MMNotificationAction actionWithTitle:@"Okay" style:MMNotificationActionStyleDone handler:^(MMNotificationAction *action){
	// Handle this action.
}];

[notification addAction:okay];

Finally, you can schedule the notification for a future date or present it right away:

// Grab the presentation controller:
MMNotificationPresentationController *controller = [MMNotificationPresentationController sharedPresentationController];

// Present it right away...
[controller presentLocalNotificationNow:notification];

// ...or schedule it for a future date.
notification.fireDate = [NSDate dateWithDateIntervalSinceNow:(4000)];

[controller scheduleLocalNotification:notification];

The presentation controller will handle the hard stuff for you! For example, it will queue and delay notifications.

Customization

You can create a custom notification view. Much like an UICollectionView, you can register a custom view class for your notifications.

// Implement an UIView subclass that conforms to the <MMNotificationView> protocol:
Class notificationViewClass = [MyCustomNotificationView class];

// Set a category to identify notifications that will use your custom class:
NSString *category = @"MyCategory";

// Register your class with the presentation controller:
MMNotificationPresentationController *controller = [MMNotificationPresentationController sharedPresentationController];

[controller registerViewClass:notificationViewClass forNotificationCategory:category];

Please refer to the documentation from the <MMNotificationView> protocol on how to configure your custom view.

Development

Pull requests are welcome and mostly appreciated.

mmnotifications's People

Contributors

jpedrosg avatar matmartinez 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.