diff --git a/ExampleProject/Example.xcodeproj/project.pbxproj b/ExampleProject/Example.xcodeproj/project.pbxproj index 8d868b04..baf1b0dd 100644 --- a/ExampleProject/Example.xcodeproj/project.pbxproj +++ b/ExampleProject/Example.xcodeproj/project.pbxproj @@ -20,6 +20,8 @@ CA0B971E1719CD6800E06F84 /* MainStoryboard.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = CA0B971C1719CD6800E06F84 /* MainStoryboard.storyboard */; }; CA0B97281719CD6800E06F84 /* TSDemoViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = CA0B97271719CD6800E06F84 /* TSDemoViewController.m */; }; CAA3C9E817C3CD180085E06E /* AlternativeDesign.json in Resources */ = {isa = PBXBuildFile; fileRef = CAA3C9E717C3CD180085E06E /* AlternativeDesign.json */; }; + FE493BB9191B63B1001F16FD /* firstViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = FE493BB8191B63B1001F16FD /* firstViewController.m */; }; + FE493BBC191B63C0001F16FD /* secondViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = FE493BBB191B63C0001F16FD /* secondViewController.m */; }; /* End PBXBuildFile section */ /* Begin PBXFileReference section */ @@ -42,6 +44,10 @@ CA0B97261719CD6800E06F84 /* TSDemoViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = TSDemoViewController.h; sourceTree = ""; }; CA0B97271719CD6800E06F84 /* TSDemoViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = TSDemoViewController.m; sourceTree = ""; }; CAA3C9E717C3CD180085E06E /* AlternativeDesign.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = AlternativeDesign.json; sourceTree = ""; }; + FE493BB7191B63B1001F16FD /* firstViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = firstViewController.h; sourceTree = ""; }; + FE493BB8191B63B1001F16FD /* firstViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = firstViewController.m; sourceTree = ""; }; + FE493BBA191B63C0001F16FD /* secondViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = secondViewController.h; sourceTree = ""; }; + FE493BBB191B63C0001F16FD /* secondViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = secondViewController.m; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -98,6 +104,10 @@ CA0B97261719CD6800E06F84 /* TSDemoViewController.h */, CA0B97271719CD6800E06F84 /* TSDemoViewController.m */, CA0B970B1719CD6800E06F84 /* Supporting Files */, + FE493BB7191B63B1001F16FD /* firstViewController.h */, + FE493BB8191B63B1001F16FD /* firstViewController.m */, + FE493BBA191B63C0001F16FD /* secondViewController.h */, + FE493BBB191B63C0001F16FD /* secondViewController.m */, ); path = Example; sourceTree = ""; @@ -205,6 +215,8 @@ CA0B97111719CD6800E06F84 /* main.m in Sources */, CA0B97151719CD6800E06F84 /* TSAppDelegate.m in Sources */, CA0B97281719CD6800E06F84 /* TSDemoViewController.m in Sources */, + FE493BB9191B63B1001F16FD /* firstViewController.m in Sources */, + FE493BBC191B63C0001F16FD /* secondViewController.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/ExampleProject/Example.xcworkspace/xcshareddata/Example.xccheckout b/ExampleProject/Example.xcworkspace/xcshareddata/Example.xccheckout index 354f7fd7..a3dcbda9 100644 --- a/ExampleProject/Example.xcworkspace/xcshareddata/Example.xccheckout +++ b/ExampleProject/Example.xcworkspace/xcshareddata/Example.xccheckout @@ -5,34 +5,34 @@ IDESourceControlProjectFavoriteDictionaryKey IDESourceControlProjectIdentifier - F6FF7C22-1562-4A01-9CD1-A3C34B7E21C3 + 3379FE2B-13BB-43D7-A6E1-7B7A4F8B4942 IDESourceControlProjectName Example IDESourceControlProjectOriginsDictionary - 56C72571-8325-46B6-BC46-920E7DE5B629 - https://github.com/toursprung/TSMessages.git + 8403C1EC-6EA0-4DAB-B624-129408DCF536 + https://github.com/vilyever/TSMessages.git IDESourceControlProjectPath ExampleProject/Example.xcworkspace IDESourceControlProjectRelativeInstallPathDictionary - 56C72571-8325-46B6-BC46-920E7DE5B629 + 8403C1EC-6EA0-4DAB-B624-129408DCF536 ../.. IDESourceControlProjectURL - https://github.com/toursprung/TSMessages.git + https://github.com/vilyever/TSMessages.git IDESourceControlProjectVersion 110 IDESourceControlProjectWCCIdentifier - 56C72571-8325-46B6-BC46-920E7DE5B629 + 8403C1EC-6EA0-4DAB-B624-129408DCF536 IDESourceControlProjectWCConfigurations IDESourceControlRepositoryExtensionIdentifierKey public.vcs.git IDESourceControlWCCIdentifierKey - 56C72571-8325-46B6-BC46-920E7DE5B629 + 8403C1EC-6EA0-4DAB-B624-129408DCF536 IDESourceControlWCCName TSMessages diff --git a/ExampleProject/Example/TSDemoViewController.m b/ExampleProject/Example/TSDemoViewController.m index fd057035..66270638 100644 --- a/ExampleProject/Example/TSDemoViewController.m +++ b/ExampleProject/Example/TSDemoViewController.m @@ -11,6 +11,12 @@ #import "TSMessage.h" #import "TSMessageView.h" +@interface TSDemoViewController() + +@property (nonatomic, strong) TSMessageView *endlessNotification; + +@end + @implementation TSDemoViewController - (void)viewDidLoad @@ -26,28 +32,32 @@ - (IBAction)didTapError:(id)sender { [TSMessage showNotificationWithTitle:NSLocalizedString(@"Something failed", nil) subtitle:NSLocalizedString(@"The internet connection seems to be down. Please check that!", nil) - type:TSMessageNotificationTypeError]; + type:TSMessageNotificationTypeError + simultaneously:NO]; } - (IBAction)didTapWarning:(id)sender { [TSMessage showNotificationWithTitle:NSLocalizedString(@"Some random warning", nil) subtitle:NSLocalizedString(@"Look out! Something is happening there!", nil) - type:TSMessageNotificationTypeWarning]; + type:TSMessageNotificationTypeWarning + simultaneously:YES]; } - (IBAction)didTapMessage:(id)sender { [TSMessage showNotificationWithTitle:NSLocalizedString(@"Tell the user something", nil) subtitle:NSLocalizedString(@"This is some neutral notification!", nil) - type:TSMessageNotificationTypeMessage]; + type:TSMessageNotificationTypeMessage + simultaneously:YES]; } - (IBAction)didTapSuccess:(id)sender { [TSMessage showNotificationWithTitle:NSLocalizedString(@"Success", nil) subtitle:NSLocalizedString(@"Some task was successfully completed!", nil) - type:TSMessageNotificationTypeSuccess]; + type:TSMessageNotificationTypeSuccess + simultaneously:YES]; } - (IBAction)didTapButton:(id)sender @@ -62,10 +72,12 @@ - (IBAction)didTapButton:(id)sender buttonTitle:NSLocalizedString(@"Update", nil) buttonCallback:^{ [TSMessage showNotificationWithTitle:NSLocalizedString(@"Thanks for updating", nil) - type:TSMessageNotificationTypeSuccess]; + type:TSMessageNotificationTypeSuccess + simultaneously:YES]; } atPosition:TSMessageNotificationPositionTop - canBeDismissedByUser:YES]; + canBeDismissedByUser:YES + simultaneously:NO]; } - (IBAction)didTapToggleNavigationBar:(id)sender { @@ -92,7 +104,8 @@ - (IBAction)didTapCustomImage:(id)sender buttonTitle:nil buttonCallback:nil atPosition:TSMessageNotificationPositionTop - canBeDismissedByUser:YES]; + canBeDismissedByUser:YES + simultaneously:YES]; } - (IBAction)didTapDismissCurrentMessage:(id)sender @@ -102,7 +115,7 @@ - (IBAction)didTapDismissCurrentMessage:(id)sender - (IBAction)didTapEndless:(id)sender { - [TSMessage showNotificationInViewController:self + self.endlessNotification = [TSMessage showNotificationInViewController:self title:NSLocalizedString(@"Endless", nil) subtitle:NSLocalizedString(@"This message can not be dismissed and will not be hidden automatically. Tap the 'Dismiss' button to dismiss the currently shown message", nil) image:nil @@ -112,7 +125,8 @@ - (IBAction)didTapEndless:(id)sender buttonTitle:nil buttonCallback:nil atPosition:TSMessageNotificationPositionTop - canBeDismissedByUser:NO]; + canBeDismissedByUser:NO + simultaneously:YES]; } - (IBAction)didTapLong:(id)sender @@ -127,11 +141,13 @@ - (IBAction)didTapLong:(id)sender buttonTitle:nil buttonCallback:nil atPosition:TSMessageNotificationPositionTop - canBeDismissedByUser:YES]; + canBeDismissedByUser:YES + simultaneously:NO]; } - (IBAction)didTapBottom:(id)sender { + [TSMessage dismissNotification:self.endlessNotification]; [TSMessage showNotificationInViewController:self title:NSLocalizedString(@"Hu!", nil) subtitle:NSLocalizedString(@"I'm down here :)", nil) @@ -142,14 +158,16 @@ - (IBAction)didTapBottom:(id)sender buttonTitle:nil buttonCallback:nil atPosition:TSMessageNotificationPositionBottom - canBeDismissedByUser:YES]; + canBeDismissedByUser:YES + simultaneously:YES]; } - (IBAction)didTapText:(id)sender { [TSMessage showNotificationWithTitle:NSLocalizedString(@"With 'Text' I meant a long text, so here it is", nil) subtitle:NSLocalizedString(@"Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus", nil) - type:TSMessageNotificationTypeWarning]; + type:TSMessageNotificationTypeWarning + simultaneously:NO]; } - (IBAction)didTapCustomDesign:(id)sender @@ -158,7 +176,8 @@ - (IBAction)didTapCustomDesign:(id)sender [TSMessage addCustomDesignFromFileWithName:@"AlternativeDesign.json"]; [TSMessage showNotificationWithTitle:NSLocalizedString(@"Updated to custom design file", nil) subtitle:NSLocalizedString(@"From now on, all the titles of success messages are larger", nil) - type:TSMessageNotificationTypeSuccess]; + type:TSMessageNotificationTypeSuccess + simultaneously:YES]; } diff --git a/ExampleProject/Example/en.lproj/MainStoryboard.storyboard b/ExampleProject/Example/en.lproj/MainStoryboard.storyboard index 75c1c236..9108baaf 100644 --- a/ExampleProject/Example/en.lproj/MainStoryboard.storyboard +++ b/ExampleProject/Example/en.lproj/MainStoryboard.storyboard @@ -1,8 +1,8 @@ - + - + @@ -219,7 +219,18 @@ - + + + + + + + + + + + + @@ -243,10 +254,115 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - \ No newline at end of file + + + + diff --git a/ExampleProject/Example/firstViewController.h b/ExampleProject/Example/firstViewController.h new file mode 100644 index 00000000..37ea1225 --- /dev/null +++ b/ExampleProject/Example/firstViewController.h @@ -0,0 +1,13 @@ +// +// firstViewController.h +// Example +// +// Created by FTET on 14-5-8. +// Copyright (c) 2014年 Toursprung. All rights reserved. +// + +#import + +@interface firstViewController : UIViewController + +@end diff --git a/ExampleProject/Example/firstViewController.m b/ExampleProject/Example/firstViewController.m new file mode 100644 index 00000000..3b45e0a4 --- /dev/null +++ b/ExampleProject/Example/firstViewController.m @@ -0,0 +1,82 @@ +// +// firstViewController.m +// Example +// +// Created by FTET on 14-5-8. +// Copyright (c) 2014年 Toursprung. All rights reserved. +// + +#import "firstViewController.h" + +#import "TSMessage.h" + +@interface firstViewController () + +@end + +@implementation firstViewController + +- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil +{ + self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; + if (self) { + // Custom initialization + } + return self; +} + +- (void)viewDidLoad +{ + [super viewDidLoad]; + // Do any additional setup after loading the view. + + +} + +- (void)didReceiveMemoryWarning +{ + [super didReceiveMemoryWarning]; + // Dispose of any resources that can be recreated. +} + +/* +#pragma mark - Navigation + +// In a storyboard-based application, you will often want to do a little preparation before navigation +- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender +{ + // Get the new view controller using [segue destinationViewController]. + // Pass the selected object to the new view controller. +} +*/ +- (IBAction)normalDidTap:(id)sender { + [TSMessage showNotificationInViewController:self + title:NSLocalizedString(@"Normal message in First Tab", nil) + subtitle:NSLocalizedString(@"This message is displayed 100 seconds for test simultaneous", nil) + image:nil + type:TSMessageNotificationTypeWarning + duration:10.0 + callback:nil + buttonTitle:nil + buttonCallback:nil + atPosition:TSMessageNotificationPositionTop + canBeDismissedByUser:YES + simultaneously:NO]; +} + +- (IBAction)simultaneoulyDidTap:(id)sender { + [TSMessage showNotificationInViewController:self + title:NSLocalizedString(@"Simultaneously message in First Tab", nil) + subtitle:NSLocalizedString(@"This message is displayed 100 seconds for test simultaneous", nil) + image:nil + type:TSMessageNotificationTypeWarning + duration:10.0 + callback:nil + buttonTitle:nil + buttonCallback:nil + atPosition:TSMessageNotificationPositionTop + canBeDismissedByUser:YES + simultaneously:YES]; +} + +@end diff --git a/ExampleProject/Example/secondViewController.h b/ExampleProject/Example/secondViewController.h new file mode 100644 index 00000000..f153ad5a --- /dev/null +++ b/ExampleProject/Example/secondViewController.h @@ -0,0 +1,13 @@ +// +// secondViewController.h +// Example +// +// Created by FTET on 14-5-8. +// Copyright (c) 2014年 Toursprung. All rights reserved. +// + +#import + +@interface secondViewController : UIViewController + +@end diff --git a/ExampleProject/Example/secondViewController.m b/ExampleProject/Example/secondViewController.m new file mode 100644 index 00000000..c8112422 --- /dev/null +++ b/ExampleProject/Example/secondViewController.m @@ -0,0 +1,80 @@ +// +// secondViewController.m +// Example +// +// Created by FTET on 14-5-8. +// Copyright (c) 2014年 Toursprung. All rights reserved. +// + +#import "secondViewController.h" + +#import "TSMessage.h" + +@interface secondViewController () + +@end + +@implementation secondViewController + +- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil +{ + self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; + if (self) { + // Custom initialization + } + return self; +} + +- (void)viewDidLoad +{ + [super viewDidLoad]; + // Do any additional setup after loading the view. +} + +- (void)didReceiveMemoryWarning +{ + [super didReceiveMemoryWarning]; + // Dispose of any resources that can be recreated. +} + +/* +#pragma mark - Navigation + +// In a storyboard-based application, you will often want to do a little preparation before navigation +- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender +{ + // Get the new view controller using [segue destinationViewController]. + // Pass the selected object to the new view controller. +} +*/ +- (IBAction)normalDidTap:(id)sender { + [TSMessage showNotificationInViewController:self + title:NSLocalizedString(@"Normal message in Second Tab", nil) + subtitle:NSLocalizedString(@"This message is displayed 100 seconds for test simultaneous", nil) + image:nil + type:TSMessageNotificationTypeWarning + duration:10.0 + callback:nil + buttonTitle:nil + buttonCallback:nil + atPosition:TSMessageNotificationPositionTop + canBeDismissedByUser:YES + simultaneously:NO]; +} + +- (IBAction)simultaneoulyDidTap:(id)sender { + [TSMessage showNotificationInViewController:self + title:NSLocalizedString(@"Simultaneously message in Second Tab", nil) + subtitle:NSLocalizedString(@"This message is displayed 100 seconds for test simultaneous", nil) + image:nil + type:TSMessageNotificationTypeWarning + duration:10.0 + callback:nil + buttonTitle:nil + buttonCallback:nil + atPosition:TSMessageNotificationPositionTop + canBeDismissedByUser:YES + simultaneously:NO]; +} + +@end diff --git a/ExampleProject/Pods/Local Podspecs/TSMessages.podspec b/ExampleProject/Pods/Local Podspecs/TSMessages.podspec index c9f9cdef..d59a56b6 100644 --- a/ExampleProject/Pods/Local Podspecs/TSMessages.podspec +++ b/ExampleProject/Pods/Local Podspecs/TSMessages.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = "TSMessages" - s.version = "0.9.4" + s.version = "0.9.8" s.summary = "Easy to use and customizable messages/notifications for iOS à la Tweetbot." s.description = <<-DESC This framework provides an easy to use class to show little notification views on the top of the screen. (à la Tweetbot). diff --git a/TSMessages/Classes/TSMessage.h b/TSMessages/Classes/TSMessage.h index dc1cd506..cd308c0f 100755 --- a/TSMessages/Classes/TSMessage.h +++ b/TSMessages/Classes/TSMessage.h @@ -59,17 +59,19 @@ typedef NS_ENUM(NSInteger,TSMessageNotificationDuration) { @param message The title of the notification view @param type The notification type (Message, Warning, Error, Success) */ -+ (void)showNotificationWithTitle:(NSString *)message - type:(TSMessageNotificationType)type; ++ (TSMessageView *)showNotificationWithTitle:(NSString *)message + type:(TSMessageNotificationType)type + simultaneously:(BOOL)canSimultaneously; /** Shows a notification message @param title The title of the notification view @param subtitle The text that is displayed underneath the title @param type The notification type (Message, Warning, Error, Success) */ -+ (void)showNotificationWithTitle:(NSString *)title - subtitle:(NSString *)subtitle - type:(TSMessageNotificationType)type; ++ (TSMessageView *)showNotificationWithTitle:(NSString *)title + subtitle:(NSString *)subtitle + type:(TSMessageNotificationType)type + simultaneously:(BOOL)canSimultaneously; /** Shows a notification message in a specific view controller @param viewController The view controller to show the notification in. @@ -78,10 +80,11 @@ typedef NS_ENUM(NSInteger,TSMessageNotificationDuration) { @param subtitle The text that is displayed underneath the title @param type The notification type (Message, Warning, Error, Success) */ -+ (void)showNotificationInViewController:(UIViewController *)viewController - title:(NSString *)title - subtitle:(NSString *)subtitle - type:(TSMessageNotificationType)type; ++ (TSMessageView *)showNotificationInViewController:(UIViewController *)viewController + title:(NSString *)title + subtitle:(NSString *)subtitle + type:(TSMessageNotificationType)type + simultaneously:(BOOL)canSimultaneously; /** Shows a notification message in a specific view controller with a specific duration @param viewController The view controller to show the notification in. @@ -91,11 +94,12 @@ typedef NS_ENUM(NSInteger,TSMessageNotificationDuration) { @param type The notification type (Message, Warning, Error, Success) @param duration The duration of the notification being displayed */ -+ (void)showNotificationInViewController:(UIViewController *)viewController - title:(NSString *)title - subtitle:(NSString *)subtitle - type:(TSMessageNotificationType)type - duration:(NSTimeInterval)duration; ++ (TSMessageView *)showNotificationInViewController:(UIViewController *)viewController + title:(NSString *)title + subtitle:(NSString *)subtitle + type:(TSMessageNotificationType)type + duration:(NSTimeInterval)duration + simultaneously:(BOOL)canSimultaneously; /** Shows a notification message in a specific view controller with a specific duration @param viewController The view controller to show the notification in. @@ -106,12 +110,13 @@ typedef NS_ENUM(NSInteger,TSMessageNotificationDuration) { @param duration The duration of the notification being displayed @param dismissingEnabled Should the message be dismissed when the user taps/swipes it */ -+ (void)showNotificationInViewController:(UIViewController *)viewController - title:(NSString *)title - subtitle:(NSString *)subtitle - type:(TSMessageNotificationType)type - duration:(NSTimeInterval)duration - canBeDismissedByUser:(BOOL)dismissingEnabled; ++ (TSMessageView *)showNotificationInViewController:(UIViewController *)viewController + title:(NSString *)title + subtitle:(NSString *)subtitle + type:(TSMessageNotificationType)type + duration:(NSTimeInterval)duration + canBeDismissedByUser:(BOOL)dismissingEnabled + simultaneously:(BOOL)canSimultaneously; @@ -128,17 +133,18 @@ typedef NS_ENUM(NSInteger,TSMessageNotificationDuration) { @param messagePosition The position of the message on the screen @param dismissingEnabled Should the message be dismissed when the user taps/swipes it */ -+ (void)showNotificationInViewController:(UIViewController *)viewController - title:(NSString *)title - subtitle:(NSString *)subtitle - image:(UIImage *)image - type:(TSMessageNotificationType)type - duration:(NSTimeInterval)duration - callback:(void (^)())callback - buttonTitle:(NSString *)buttonTitle - buttonCallback:(void (^)())buttonCallback - atPosition:(TSMessageNotificationPosition)messagePosition - canBeDismissedByUser:(BOOL)dismissingEnabled; ++ (TSMessageView *)showNotificationInViewController:(UIViewController *)viewController + title:(NSString *)title + subtitle:(NSString *)subtitle + image:(UIImage *)image + type:(TSMessageNotificationType)type + duration:(NSTimeInterval)duration + callback:(void (^)())callback + buttonTitle:(NSString *)buttonTitle + buttonCallback:(void (^)())buttonCallback + atPosition:(TSMessageNotificationPosition)messagePosition + canBeDismissedByUser:(BOOL)dismissingEnabled + simultaneously:(BOOL)canSimultaneously; /** Fades out the currently displayed notification. If another notification is in the queue, the next one will be displayed automatically @@ -152,8 +158,21 @@ typedef NS_ENUM(NSInteger,TSMessageNotificationDuration) { @return YES if the currently displayed notification was successfully dismissed. NO if no notification was currently displayed. */ +/** + * modified by vilyever + * + * this method dismiss last displaying notification, for simultaneously display + */ + (BOOL)dismissActiveNotificationWithCompletion:(void (^)())completion; +/** + * modified by vilyever + * + * this method dismiss specified notification, for this, me change the return type of show* method. + */ ++ (BOOL)dismissNotification:(TSMessageView *)notification; ++ (BOOL)dismissNotification:(TSMessageView *)notification WithCompletion:(void (^)())completion; + /** Use this method to set a default view controller to display the messages in */ + (void)setDefaultViewController:(UIViewController *)defaultViewController; diff --git a/TSMessages/Classes/TSMessage.m b/TSMessages/Classes/TSMessage.m index 65222bda..626f6d3c 100755 --- a/TSMessages/Classes/TSMessage.m +++ b/TSMessages/Classes/TSMessage.m @@ -19,13 +19,15 @@ @interface TSMessage () /** The queued messages (TSMessageView objects) */ @property (nonatomic, strong) NSMutableArray *messages; +/** The queued messages which are displaying (TSMessageView objects) */ +@property (nonatomic, strong) NSMutableArray *displayingMessages; @end @implementation TSMessage static TSMessage *sharedMessage; -static BOOL notificationActive; +static BOOL notificationActive; // this property just mark that normal message is showing, no effect for simultaneously message static BOOL _useiOS7Style; @@ -44,95 +46,106 @@ + (TSMessage *)sharedMessage #pragma mark Public methods for setting up the notification -+ (void)showNotificationWithTitle:(NSString *)title - type:(TSMessageNotificationType)type ++ (TSMessageView *)showNotificationWithTitle:(NSString *)title + type:(TSMessageNotificationType)type + simultaneously:(BOOL)canSimultaneously { - [self showNotificationWithTitle:title - subtitle:nil - type:type]; + return [self showNotificationWithTitle:title + subtitle:nil + type:type + simultaneously:canSimultaneously]; } -+ (void)showNotificationWithTitle:(NSString *)title - subtitle:(NSString *)subtitle - type:(TSMessageNotificationType)type ++ (TSMessageView *)showNotificationWithTitle:(NSString *)title + subtitle:(NSString *)subtitle + type:(TSMessageNotificationType)type + simultaneously:(BOOL)canSimultaneously { - [self showNotificationInViewController:[self defaultViewController] - title:title - subtitle:subtitle - type:type]; + return [self showNotificationInViewController:[self defaultViewController] + title:title + subtitle:subtitle + type:type + simultaneously:canSimultaneously]; } -+ (void)showNotificationInViewController:(UIViewController *)viewController - title:(NSString *)title - subtitle:(NSString *)subtitle - type:(TSMessageNotificationType)type - duration:(NSTimeInterval)duration ++ (TSMessageView *)showNotificationInViewController:(UIViewController *)viewController + title:(NSString *)title + subtitle:(NSString *)subtitle + type:(TSMessageNotificationType)type + duration:(NSTimeInterval)duration + simultaneously:(BOOL)canSimultaneously { - [self showNotificationInViewController:viewController - title:title - subtitle:subtitle - image:nil - type:type - duration:duration - callback:nil - buttonTitle:nil - buttonCallback:nil - atPosition:TSMessageNotificationPositionTop - canBeDismissedByUser:YES]; + return [self showNotificationInViewController:viewController + title:title + subtitle:subtitle + image:nil + type:type + duration:duration + callback:nil + buttonTitle:nil + buttonCallback:nil + atPosition:TSMessageNotificationPositionTop + canBeDismissedByUser:YES + simultaneously:canSimultaneously]; } -+ (void)showNotificationInViewController:(UIViewController *)viewController - title:(NSString *)title - subtitle:(NSString *)subtitle - type:(TSMessageNotificationType)type - duration:(NSTimeInterval)duration - canBeDismissedByUser:(BOOL)dismissingEnabled ++ (TSMessageView *)showNotificationInViewController:(UIViewController *)viewController + title:(NSString *)title + subtitle:(NSString *)subtitle + type:(TSMessageNotificationType)type + duration:(NSTimeInterval)duration + canBeDismissedByUser:(BOOL)dismissingEnabled + simultaneously:(BOOL)canSimultaneously { - [self showNotificationInViewController:viewController - title:title - subtitle:subtitle - image:nil - type:type - duration:duration - callback:nil - buttonTitle:nil - buttonCallback:nil - atPosition:TSMessageNotificationPositionTop - canBeDismissedByUser:dismissingEnabled]; + return [self showNotificationInViewController:viewController + title:title + subtitle:subtitle + image:nil + type:type + duration:duration + callback:nil + buttonTitle:nil + buttonCallback:nil + atPosition:TSMessageNotificationPositionTop + canBeDismissedByUser:dismissingEnabled + simultaneously:canSimultaneously]; } -+ (void)showNotificationInViewController:(UIViewController *)viewController - title:(NSString *)title - subtitle:(NSString *)subtitle - type:(TSMessageNotificationType)type ++ (TSMessageView *)showNotificationInViewController:(UIViewController *)viewController + title:(NSString *)title + subtitle:(NSString *)subtitle + type:(TSMessageNotificationType)type + simultaneously:(BOOL)canSimultaneously { - [self showNotificationInViewController:viewController - title:title - subtitle:subtitle - image:nil - type:type - duration:TSMessageNotificationDurationAutomatic - callback:nil - buttonTitle:nil - buttonCallback:nil - atPosition:TSMessageNotificationPositionTop - canBeDismissedByUser:YES]; + return [self showNotificationInViewController:viewController + title:title + subtitle:subtitle + image:nil + type:type + duration:TSMessageNotificationDurationAutomatic + callback:nil + buttonTitle:nil + buttonCallback:nil + atPosition:TSMessageNotificationPositionTop + canBeDismissedByUser:YES + simultaneously:canSimultaneously]; } -+ (void)showNotificationInViewController:(UIViewController *)viewController - title:(NSString *)title - subtitle:(NSString *)subtitle - image:(UIImage *)image - type:(TSMessageNotificationType)type - duration:(NSTimeInterval)duration - callback:(void (^)())callback - buttonTitle:(NSString *)buttonTitle - buttonCallback:(void (^)())buttonCallback - atPosition:(TSMessageNotificationPosition)messagePosition - canBeDismissedByUser:(BOOL)dismissingEnabled ++ (TSMessageView *)showNotificationInViewController:(UIViewController *)viewController + title:(NSString *)title + subtitle:(NSString *)subtitle + image:(UIImage *)image + type:(TSMessageNotificationType)type + duration:(NSTimeInterval)duration + callback:(void (^)())callback + buttonTitle:(NSString *)buttonTitle + buttonCallback:(void (^)())buttonCallback + atPosition:(TSMessageNotificationPosition)messagePosition + canBeDismissedByUser:(BOOL)dismissingEnabled + simultaneously:(BOOL)canSimultaneously { - // Create the TSMessageView +// Create the TSMessageView TSMessageView *v = [[TSMessageView alloc] initWithTitle:title subtitle:subtitle image:image @@ -143,8 +156,11 @@ + (void)showNotificationInViewController:(UIViewController *)viewController buttonTitle:buttonTitle buttonCallback:buttonCallback atPosition:messagePosition - canBeDismissedByUser:dismissingEnabled]; + canBeDismissedByUser:dismissingEnabled + simultaneously:canSimultaneously]; [self prepareNotificationToBeShown:v]; + + return v; } @@ -163,9 +179,9 @@ + (void)prepareNotificationToBeShown:(TSMessageView *)messageView [[TSMessage sharedMessage].messages addObject:messageView]; - if (!notificationActive) + if (!notificationActive || messageView.canSimultaneously) { - [[TSMessage sharedMessage] fadeInCurrentNotification]; + [ [TSMessage sharedMessage] fadeInCurrentNotification]; } } @@ -177,6 +193,7 @@ - (id)init if ((self = [super init])) { _messages = [[NSMutableArray alloc] init]; + _displayingMessages = [ [NSMutableArray alloc] init]; } return self; } @@ -185,10 +202,33 @@ - (void)fadeInCurrentNotification { if ([self.messages count] == 0) return; - notificationActive = YES; - TSMessageView *currentView = [self.messages objectAtIndex:0]; + if (notificationActive) // if normal message is showing check if this message is simultaneously + { + for (TSMessageView *v in self.messages) + { + if (v.canSimultaneously) + { + currentView = v; + break; + } + } + } + + if (notificationActive && !currentView.canSimultaneously) + { + return; + } + + [self.displayingMessages addObject:currentView]; + [self.messages removeObject:currentView]; + + if (!currentView.canSimultaneously) + { + notificationActive = YES; + } + __block CGFloat verticalOffset = 0.0f; void (^addStatusBarHeightToVerticalOffset)() = ^void() { @@ -198,14 +238,15 @@ - (void)fadeInCurrentNotification verticalOffset += offset; }; - if ([currentView.viewController isKindOfClass:[UINavigationController class]] || [currentView.viewController.parentViewController isKindOfClass:[UINavigationController class]]) +// if ([currentView.viewController isKindOfClass:[UINavigationController class]] || [currentView.viewController.parentViewController isKindOfClass:[UINavigationController class]]) + if ( [TSMessage isControllerInNavigationController:currentView.viewController] ) { - UINavigationController *currentNavigationController; + UINavigationController *currentNavigationController = [TSMessage isControllerInNavigationController:currentView.viewController]; - if([currentView.viewController isKindOfClass:[UINavigationController class]]) - currentNavigationController = (UINavigationController *)currentView.viewController; - else - currentNavigationController = (UINavigationController *)currentView.viewController.parentViewController; +// if([currentView.viewController isKindOfClass:[UINavigationController class]]) +// currentNavigationController = (UINavigationController *)currentView.viewController; +// else +// currentNavigationController = (UINavigationController *)currentView.viewController.parentViewController; BOOL isViewIsUnderStatusBar = [[[currentNavigationController childViewControllers] firstObject] wantsFullScreenLayout]; if (!isViewIsUnderStatusBar && currentNavigationController.parentViewController == nil) { @@ -344,12 +385,20 @@ - (void)fadeOutNotification:(TSMessageView *)currentView animationFinishedBlock: { [currentView removeFromSuperview]; - if ([self.messages count] > 0) + // if ([self.messages count] > 0) + // { + // [self.messages removeObjectAtIndex:0]; + // } + + if ( [self.displayingMessages containsObject:currentView] ) { - [self.messages removeObjectAtIndex:0]; + [self.displayingMessages removeObject:currentView]; } - notificationActive = NO; + if (!currentView.canSimultaneously) + { + notificationActive = NO; + } if ([self.messages count] > 0) { @@ -369,12 +418,34 @@ + (BOOL)dismissActiveNotification + (BOOL)dismissActiveNotificationWithCompletion:(void (^)())completion { - if ([[TSMessage sharedMessage].messages count] == 0) return NO; +// if ([[TSMessage sharedMessage].messages count] == 0) return NO; + if ( [ [TSMessage sharedMessage].displayingMessages count] == 0) return NO; dispatch_async(dispatch_get_main_queue(), ^ { - if ([[TSMessage sharedMessage].messages count] == 0) return; - TSMessageView *currentMessage = [[TSMessage sharedMessage].messages objectAtIndex:0]; + if ([[TSMessage sharedMessage].displayingMessages count] == 0) return; + TSMessageView *currentMessage = [[TSMessage sharedMessage].displayingMessages lastObject]; + if (currentMessage.messageIsFullyDisplayed) + { + [[TSMessage sharedMessage] fadeOutNotification:currentMessage animationFinishedBlock:completion]; + } + }); + return YES; +} + ++ (BOOL)dismissNotification:(TSMessageView *)notification +{ + return [self dismissNotification:notification WithCompletion:nil]; +} + ++ (BOOL)dismissNotification:(TSMessageView *)notification WithCompletion:(void (^)())completion +{ + if ( [ [TSMessage sharedMessage].displayingMessages count] == 0) return NO; + + dispatch_async(dispatch_get_main_queue(), ^ + { + if ([[TSMessage sharedMessage].displayingMessages count] == 0) return; + TSMessageView *currentMessage = notification; if (currentMessage.messageIsFullyDisplayed) { [[TSMessage sharedMessage] fadeOutNotification:currentMessage animationFinishedBlock:^{ @@ -434,4 +505,18 @@ + (BOOL)iOS7StyleEnabled return _useiOS7Style; } ++ (UINavigationController *)isControllerInNavigationController:(UIViewController *)controller +{ + while (controller) + { + if ( [controller isKindOfClass:[UINavigationController class] ] ) + { + return (UINavigationController *)controller; + } + controller = controller.parentViewController; + } + + return nil; +} + @end diff --git a/TSMessages/Views/TSMessageView.h b/TSMessages/Views/TSMessageView.h index b52cf221..5e7416ba 100755 --- a/TSMessages/Views/TSMessageView.h +++ b/TSMessages/Views/TSMessageView.h @@ -42,6 +42,9 @@ /** Is the message currenlty fully displayed? Is set as soon as the message is really fully visible */ @property (nonatomic, assign) BOOL messageIsFullyDisplayed; +/** Is the message can be display simultaneously */ +@property (nonatomic, assign) BOOL canSimultaneously; + /** By setting this delegate it's possible to set a custom offset for the notification view */ @property(nonatomic, assign) id delegate; @@ -68,7 +71,8 @@ buttonTitle:(NSString *)buttonTitle buttonCallback:(void (^)())buttonCallback atPosition:(TSMessageNotificationPosition)position -canBeDismissedByUser:(BOOL)dismissingEnabled; +canBeDismissedByUser:(BOOL)dismissingEnabled + simultaneously:(BOOL)canSimultaneously; /** Fades out this notification view */ - (void)fadeMeOut; diff --git a/TSMessages/Views/TSMessageView.m b/TSMessages/Views/TSMessageView.m index 365c30c2..1101a79d 100755 --- a/TSMessages/Views/TSMessageView.m +++ b/TSMessages/Views/TSMessageView.m @@ -96,6 +96,7 @@ - (id)initWithTitle:(NSString *)title buttonCallback:(void (^)())buttonCallback atPosition:(TSMessageNotificationPosition)position canBeDismissedByUser:(BOOL)dismissingEnabled + simultaneously:(BOOL)canSimultaneously { NSDictionary *notificationDesign = [TSMessageView notificationDesign]; @@ -109,6 +110,7 @@ - (id)initWithTitle:(NSString *)title _messagePosition = position; self.callback = callback; self.buttonCallback = buttonCallback; + self.canSimultaneously = canSimultaneously; CGFloat screenWidth = self.viewController.view.bounds.size.width; NSDictionary *current;