Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add display method with message, duration and completion block #89

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions CWStatusBarNotification/CWStatusBarNotification.h
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,21 @@ typedef NS_ENUM(NSInteger, CWNotificationAnimationType) {
- (void)displayNotificationWithMessage:(NSString *)message
forDuration:(NSTimeInterval)duration;

/**
* Displays a notification with the indicated message for the indicated
* duration and then performs the completion block once the notification animates in.
* @param message
* The content of the message to be displayed.
* @param duration
* The amount of seconds for which the notification should be displayed,
* not including the animate in and out times.
* @param completion
* The block to be invoked once the notification is displayed.
*/
- (void)displayNotificationWithMessage:(NSString *)message
forDuration:(NSTimeInterval)duration
completion:(void (^)(void))completion;

/**
* Displays a notification with the indicated attributed string and then
* performs the completion block once the notification animates in.
Expand Down
10 changes: 10 additions & 0 deletions CWStatusBarNotification/CWStatusBarNotification.m
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ @interface CWViewController()

@implementation CWViewController

@synthesize preferredStatusBarStyle = _preferredStatusBarStyle;
- (UIStatusBarStyle)preferredStatusBarStyle
{
return _preferredStatusBarStyle;
Expand Down Expand Up @@ -512,6 +513,15 @@ - (void)displayNotificationWithMessage:(NSString *)message forDuration:(NSTimeIn
}];
}

- (void)displayNotificationWithMessage:(NSString *)message forDuration:(NSTimeInterval)duration completion:(void (^)(void))completion
{
[self displayNotificationWithMessage:message completion:^{
self.dismissHandle = perform_block_after_delay(duration, ^{
[self dismissNotificationWithCompletion:completion];
});
}];
}

- (void)displayNotificationWithAttributedString:(NSAttributedString *)attributedString completion:(void (^)(void))completion
{
[self displayNotificationWithMessage:[attributedString string] completion:completion];
Expand Down