- 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.
- Customize the notifications.
- Support notifications number control.
- Support notifications ignore mode.
- Support shared notifications.
- Git clone this project.
- Copy this project into your own project.
- Add the .xcodeproj into you project and link it as embed framework.
- You can remove the
demo
andScreenShots
folder.
- Add
pod 'IRNotificationReceiver'
in thePodfile
pod install
- 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. UseIRNotificationReceiver
can be eazy to manage these notifications.
#import <IRNotificationReceiver/IRNotificationReceiver.h>
#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
isYES
, that means once the conditions are completed, theNotificationReceiver
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
isYES
, if set toNO
, TheNotificationReceiverDelegate
will not be called, andcheckConditionsWith
not work too.
[notificationReceiver addObserver:self selector:@selector(completionNotifications:) conditioner:[[NotificationConditioner alloc] initWithName:GetUserProfileSuccessNotification minCount:1] ignoreable:YES object:nil];
-
ignoreable
- If set
YES
, while you callignoreConditionerWithName
orignoreConditioner
, the specific notification would not manage bycheckConditionsWith
. It also triger the ignore delegaet:receivedIgnoreConditionerWithName:(NSString*)name
in theNotificationReceiverDelegate
.
- If set
-
minCount
- You can set
minCount
to help you promise the number of specific notification are called if verified bycheckConditionsWith
.
- You can set
- Check verified by
checkConditionsWith
, the common way is put the codes in the call back of the requests. - Important!!! Do
checkConditionsWith
would consume theminCount
in theNotificationConditioner
. That means if you set aLogin NotificationConditioner
with 3 forminCount
, after you callcheckConditionsWith:@"Login"
three times, the check result would be verified.
[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];
}
}];
- 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.
- Don't forgot to remove observer while you not want to observe the notifications.
- 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 doLogin
. - Use
SharedNotificationConditioner
forLogin
request in the all of the pages that you want to login first. Like Profile page, Friends page, etc....
- The situation for use is when you want to do a common request, like
[notificationReceiver addObserver:self selector:@selector(completionNotifications:) conditioner:[[SharedNotificationConditioner sharedInstance] sharedNotificationConditionerWithName:LoginSuccessNotification minCount:1] ignoreable:YES object:nil];
Main Page | Failure |
---|---|
Sequential Requesting | Sequential Success |
Concurent Requesting | Concurent Success |