Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/irons163/irnotificationreceiver
IRNotificationReceiver is a powerful notification receiver/manager for iOS, it can set conditions for eazy to manage the notifications.
https://github.com/irons163/irnotificationreceiver
ios manager manager-system network notification notification-center notifications objective-c receiver
Last synced: 3 days ago
JSON representation
IRNotificationReceiver is a powerful notification receiver/manager for iOS, it can set conditions for eazy to manage the notifications.
- Host: GitHub
- URL: https://github.com/irons163/irnotificationreceiver
- Owner: irons163
- License: mit
- Created: 2019-07-11T08:40:48.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2019-12-23T09:11:45.000Z (almost 5 years ago)
- Last Synced: 2024-09-30T15:18:42.700Z (3 days ago)
- Topics: ios, manager, manager-system, network, notification, notification-center, notifications, objective-c, receiver
- Language: Objective-C
- Homepage:
- Size: 191 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
![Build Status](https://img.shields.io/badge/build-%20passing%20-brightgreen.svg)
![Platform](https://img.shields.io/badge/Platform-%20iOS%20-blue.svg)# IRNotificationReceiver
- IRNotificationReceiver is a powerful notification receiver/manager for iOS, it can set conditions for eazy to manage the notifications.
- Notification is base on `Observer Pattern`, it is a good feature to send messages between classes and not break you codes structure, but sometimes you have a lot of notifications and want to manage them, like network relative notifications.## Features
- Customize the notifications.
- Support notifications number control.
- Support notifications ignore mode.
- Support shared notifications.## Install
### Git
- Git clone this project.
- Copy this project into your own project.
- Add the .xcodeproj into you project and link it as embed framework.
#### Options
- You can remove the `demo` and `ScreenShots` folder.### Cocoapods
- Add `pod 'IRNotificationReceiver'` in the `Podfile`
- `pod install`## Usage
- Then `demo` project display a situation for network requests. You want to use notifications to deliver the status of requests, they could be success or failure, and called by sequential or concurent. Use `IRNotificationReceiver` can be eazy to manage these notifications.
### Basic
#### Setup `NotificationReceiver`
```obj-c
#import#define GetUserProfileSuccessNotification @"GetUserProfileSuccessNotification"
#define GetFriendsSuccessNotification @"GetFriendsSuccessNotification"
#define GetMessagesSuccessNotification @"GetMessagesSuccessNotification"NotificationReceiver *notificationReceiver = [[NotificationReceiver alloc] init];
notificationReceiver.repeat = NO;
notificationReceiver.delegate = self;
```- The default value of `repeat` is `YES`, that means once the conditions are completed, the `NotificationReceiver` will reset and look forward the same conditions again. The situation is use for some the same requests you want to do again, ex: Click a button do 3 requests A, B, C, show the result after the requests are completed, then you can click again.
- The default value of `enable` is `YES`, if set to `NO`, The `NotificationReceiverDelegate` will not be called, and `checkConditionsWith` not work too.
#### Set `addObserver`, and set `NotificationConditioner`
```obj-c
[notificationReceiver addObserver:self selector:@selector(completionNotifications:) conditioner:[[NotificationConditioner alloc] initWithName:GetUserProfileSuccessNotification minCount:1] ignoreable:YES object:nil];
```- `ignoreable`
- If set `YES`, while you call `ignoreConditionerWithName` or `ignoreConditioner`, the specific notification would not manage by `checkConditionsWith`. It also triger the ignore delegaet: `receivedIgnoreConditionerWithName:(NSString*)name` in the `NotificationReceiverDelegate`.- `minCount`
- You can set `minCount` to help you promise the number of specific notification are called if verified by `checkConditionsWith`.#### Check verified by `checkConditionsWith`
- Check verified by `checkConditionsWith`, the common way is put the codes in the call back of the requests.
- Important!!! Do `checkConditionsWith` would consume the `minCount` in the `NotificationConditioner`. That means if you set a `Login NotificationConditioner` with 3 for `minCount`, after you call `checkConditionsWith:@"Login"` three times, the check result would be verified.```obj-c
[notificationReceiver checkConditionsWith:name verifity:^(BOOL isVerified) {
if(name) {
self.statusLabel.text = [self.statusLabel.text stringByAppendingString:[NSString stringWithFormat:@"%@ %@\n", [name stringByReplacingOccurrencesOfString:@"SuccessNotification" withString:@""], @"Success."]];
}
if(isVerified) {
[self didUpdate];
}
}];
```#### Reset by `resetConditioners`
- You can call `resetConditioners` to make the conditions reset to default. Ex: Click logout button, discard all of the network requests and reset the conditions.
#### Call `removeObserver`
- Don't forgot to remove observer while you not want to observe the notifications.
### Advanced settings
- Use `SharedNotificationConditioner`.
- The situation for use is when you want to do a common request, like `Login`. You just want to do it once, so if logined, then do something, else do `Login`.
- Use `SharedNotificationConditioner` for `Login` request in the all of the pages that you want to login first. Like Profile page, Friends page, etc....
```obj-c
[notificationReceiver addObserver:self selector:@selector(completionNotifications:) conditioner:[[SharedNotificationConditioner sharedInstance] sharedNotificationConditionerWithName:LoginSuccessNotification minCount:1] ignoreable:YES object:nil];
```## Screenshots
| Main Page | Failure |
|:---:|:---:|
| ![Main](./ScreenShots/demo1.png) | ![Failure](./ScreenShots/demo6.png) |
| Sequential Requesting | Sequential Success |
| ![Sequential](./ScreenShots/demo2.png) | ![Success](./ScreenShots/demo3.png) |
| Concurent Requesting | Concurent Success |
| ![Concurent](./ScreenShots/demo4.png) | ![Success](./ScreenShots/demo5.png) |