MMPReactiveNotification 0.4.1

MMPReactiveNotification 0.4.1

测试已测试
语言语言 Obj-CObjective C
许可证 MIT
发布最后发布2015年10月

Mamad Purbo 维护。



MMPReactiveNotification 是一个响应式库,提供本地和远程推送通知的信号。

功能

  • 不再需要与通知相关的代理方法,注册和通知都可用作信号。
  • 远程推送注册的信号。
  • 接收远程通知的信号。
  • 接收本地通知的信号。
  • 通知设置注册的信号。
  • 本地通知调度。

安装

MMPReactiveNotification 通过 CocoaPods 提供,要安装它,只需将以下行添加到您的 Podfile 中

pod 'MMPReactiveNotification'

使用

在您的应用程序中任何地方使用 MMPReactiveNotification 类方法 service 订阅适当的信号。以下示例展示了如何使用 remoteRegistration 信号以默认设置注册远程推送通知并接收推送令牌

// import the header
#import <MMPReactiveNotification/MMPReactiveNotification.h>

[[[MMPReactiveNotification service]
                           remoteRegistration]
                           subscribeNext:^(NSData *tokenData) {
                               NSLog(@"Receiving push token: %@", tokenData);
                               // Send the push token to your server
                           }
                           error:^(NSError *error) {
                               NSLog(@"Push registration error: %@", error);
                           }];

要接收远程推送通知,使用 remoteNotifications 方法

[[[MMPReactiveNotification service]
                           remoteNotifications]
                           subscribeNext:^(NSDictionary *pushData) {
                               NSLog(@"Receiving push: %@", pushData);
                           }];

要接收本地通知,使用 localNotifications 方法

[[[MMPReactiveNotification service]
                           localNotifications]
                           subscribeNext:^(UILocalNotification *localNotification) {
                               NSLog(@"Receiving local notification: %@", localNotification.alertBody);
                           }];

自定义设置

远程推送注册的默认设置如下

要自定义这些设置,请使用以下示例中使用 notificationTypescategories 方法

// only enable alert and badge
[[[[MMPReactiveNotification service]
                            notificationTypes:UIUserNotificationTypeAlert|UIUserNotificationTypeBadge]
                            remoteRegistration]
                            subscribeNext:^(NSData *tokenData) {
                                NSLog(@"Receiving push token: %@", tokenData);
                                // Send the push token to your server
                            }];

安排本地通知

要创建本地通知,首先使用新的 MMPLocalNotificationSpec 指定通知,然后调用 schedule 方法来安排它

[[[[[[MMPLocalNotificationSpec new]
                               withAlertBody:@"Your daily quiz is now available!"]
                               withSoundName:UILocalNotificationDefaultSoundName] withCategory:@"Quiz"]
                               fireDailyAtHour:18 minute:0 second:0]
                               schedule];

此安排还将自动注册通知设置,如果之前尚未完成。

联系

MMPReactiveNotification 由 Mamad Purbo 维护。

许可证

MMPReactiveNotification 在 MIT 许可下可用。有关更多信息,请参阅 LICENSE 文件。