MMNotifications 0.1.7

MMNotifications 0.1.7

Matías Martínez 维护。



  • 作者:
  • Matías Martínez

MMNotifications

一种简单可定制的展示应用内通知的方式。它与系统的外观和感觉相匹配,完全支持 iPhone X 和 iPad。

MMNotifications

安装

从 CocoaPods 开始

CocoaPods 是 Objective-C 的依赖管理工具,它自动化并简化了在项目中使用第三方库(如 MMNotifications)的过程。首先,将以下行添加到您的 Podfile

pod 'MMNotifications'

其次,将 MMNotifications 安装到您的项目中

pod install

使用

如果您曾尝试过本地通知 API,那么这将非常简单。

您创建一个 MMLocalNotification 对象并设置标题、消息和图片

// 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"];

您可以可选地添加一些操作!这些将会在通知本身中显示

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

[notification addAction:okay];

最后,您可以安排在未来某天调度通知或立即显示

// 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];

展示控制器会为您处理所有困难的事情!例如,它会排队并延迟通知。

定制

您可以创建自定义通知视图。与 UICollectionView 类似,您可以为您的通知注册一个自定义视图类。

// 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];

请参阅 <MMNotificationView> 协议的文档,了解如何配置您的自定义视图。

开发

欢迎接收合并请求,并且广泛欢迎。