From 6de05be26cda8b14b4203e8b0a7fe51a468c4b66 Mon Sep 17 00:00:00 2001 From: Sean Bedford Date: Mon, 13 Jul 2015 09:23:08 +0100 Subject: [PATCH 1/2] Replace code deprecated in iOS7 --- Example/TSMessages/TSDemoViewController.m | 34 ++++++++++- Pod/Classes/TSMessage.m | 73 +++++++++++++---------- 2 files changed, 73 insertions(+), 34 deletions(-) diff --git a/Example/TSMessages/TSDemoViewController.m b/Example/TSMessages/TSDemoViewController.m index 1460a5ad..eb5be8b1 100755 --- a/Example/TSMessages/TSDemoViewController.m +++ b/Example/TSMessages/TSDemoViewController.m @@ -19,10 +19,40 @@ - (void)viewDidLoad [TSMessage setDefaultViewController:self]; [TSMessage setDelegate:self]; - self.wantsFullScreenLayout = YES; + [self setFullscreenLayout:YES]; + [self.navigationController.navigationBar setTranslucent:YES]; } +- (void)setFullscreenLayout:(bool)wantsFullscreen { + if ([self respondsToSelector:@selector(edgesForExtendedLayout)]) { + if (wantsFullscreen) { + self.edgesForExtendedLayout = UIRectEdgeAll; + } + else { + self.edgesForExtendedLayout = UIRectEdgeNone; + } + } + else { + #pragma clang diagnostic push + #pragma clang diagnostic ignored "-Wdeprecated-declarations" + self.wantsFullScreenLayout = wantsFullscreen; + #pragma clang diagnostic pop + } +} + +- (bool)isFullscreen { + if ([self respondsToSelector:@selector(edgesForExtendedLayout)] && self.edgesForExtendedLayout == UIRectEdgeAll) { + return YES; + } + else { + #pragma clang diagnostic push + #pragma clang diagnostic ignored "-Wdeprecated-declarations" + return self.wantsFullScreenLayout; + #pragma clang diagnostic pop + } +} + - (IBAction)didTapError:(id)sender { [TSMessage showNotificationWithTitle:NSLocalizedString(@"Something failed", nil) @@ -82,7 +112,7 @@ - (IBAction)didTapToggleNavigationBarAlpha:(id)sender - (IBAction)didTapToggleWantsFullscreen:(id)sender { - self.wantsFullScreenLayout = !self.wantsFullScreenLayout; + [self setFullscreenLayout:![self isFullscreen]]; [self.navigationController.navigationBar setTranslucent:!self.navigationController.navigationBar.isTranslucent]; } diff --git a/Pod/Classes/TSMessage.m b/Pod/Classes/TSMessage.m index 02deac66..2ffefe7f 100755 --- a/Pod/Classes/TSMessage.m +++ b/Pod/Classes/TSMessage.m @@ -151,7 +151,7 @@ + (void)prepareNotificationToBeShown:(TSMessageView *)messageView { NSString *title = messageView.title; NSString *subtitle = messageView.subtitle; - + for (TSMessageView *n in [TSMessage sharedMessage].messages) { if (([n.title isEqualToString:title] || (!n.title && !title)) && ([n.subtitle isEqualToString:subtitle] || (!n.subtitle && !subtitle))) @@ -159,9 +159,9 @@ + (void)prepareNotificationToBeShown:(TSMessageView *)messageView return; // avoid showing the same messages twice in a row } } - + [[TSMessage sharedMessage].messages addObject:messageView]; - + if (!notificationActive) { [[TSMessage sharedMessage] fadeInCurrentNotification]; @@ -183,33 +183,42 @@ - (id)init - (void)fadeInCurrentNotification { if ([self.messages count] == 0) return; - + notificationActive = YES; - + TSMessageView *currentView = [self.messages objectAtIndex:0]; - + __block CGFloat verticalOffset = 0.0f; - + void (^addStatusBarHeightToVerticalOffset)() = ^void() { - + if (currentView.messagePosition == TSMessageNotificationPositionNavBarOverlay){ return; } - + CGSize statusBarSize = [UIApplication sharedApplication].statusBarFrame.size; verticalOffset += MIN(statusBarSize.width, statusBarSize.height); }; - + if ([currentView.viewController isKindOfClass:[UINavigationController class]] || [currentView.viewController.parentViewController isKindOfClass:[UINavigationController class]]) { UINavigationController *currentNavigationController; - + if([currentView.viewController isKindOfClass:[UINavigationController class]]) currentNavigationController = (UINavigationController *)currentView.viewController; else currentNavigationController = (UINavigationController *)currentView.viewController.parentViewController; - - BOOL isViewIsUnderStatusBar = [[[currentNavigationController childViewControllers] firstObject] wantsFullScreenLayout]; + + BOOL isViewIsUnderStatusBar; + if ([[[currentNavigationController childViewControllers] firstObject] respondsToSelector:@selector(edgesForExtendedLayout)]) { + isViewIsUnderStatusBar = [[currentNavigationController childViewControllers] firstObject].edgesForExtendedLayout == UIRectEdgeAll; + } + else { + #pragma clang diagnostic push + #pragma clang diagnostic ignored "-Wdeprecated-declarations" + isViewIsUnderStatusBar = [[[currentNavigationController childViewControllers] firstObject] wantsFullScreenLayout]; + #pragma clang diagnostic pop + } if (!isViewIsUnderStatusBar && currentNavigationController.parentViewController == nil) { isViewIsUnderStatusBar = ![TSMessage isNavigationBarInNavigationControllerHidden:currentNavigationController]; // strange but true } @@ -237,17 +246,17 @@ - (void)fadeInCurrentNotification addStatusBarHeightToVerticalOffset(); } } - + CGPoint toPoint; if (currentView.messagePosition != TSMessageNotificationPositionBottom) { CGFloat navigationbarBottomOfViewController = 0; - + if (self.delegate && [self.delegate respondsToSelector:@selector(messageLocationOfMessageView:)]) { navigationbarBottomOfViewController = [self.delegate messageLocationOfMessageView:currentView]; } - + toPoint = CGPointMake(currentView.center.x, navigationbarBottomOfViewController + verticalOffset + CGRectGetHeight(currentView.frame) / 2.0); } @@ -260,14 +269,14 @@ - (void)fadeInCurrentNotification } toPoint = CGPointMake(currentView.center.x, y); } - + if (self.delegate && [self.delegate respondsToSelector:@selector(customizeMessageView:)]) { [self.delegate customizeMessageView:currentView]; } - - - + + + dispatch_block_t animationBlock = ^{ currentView.center = toPoint; if (![TSMessage iOS7StyleEnabled]) { @@ -277,7 +286,7 @@ - (void)fadeInCurrentNotification void(^completionBlock)(BOOL) = ^(BOOL finished) { currentView.messageIsFullyDisplayed = YES; }; - + if (![TSMessage iOS7StyleEnabled]) { [UIView animateWithDuration:kTSMessageAnimationDuration delay:0.0 @@ -295,12 +304,12 @@ - (void)fadeInCurrentNotification completion:completionBlock]; #endif } - + if (currentView.duration == TSMessageNotificationDurationAutomatic) { currentView.duration = kTSMessageAnimationDuration + kTSMessageDisplayTime + currentView.frame.size.height * kTSMessageExtraDisplayTimePerPixel; } - + if (currentView.duration != TSMessageNotificationDurationEndless) { dispatch_async(dispatch_get_main_queue(), ^ @@ -334,7 +343,7 @@ - (void)fadeOutNotification:(TSMessageView *)currentView animationFinishedBlock: [NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(fadeOutNotification:) object:currentView]; - + CGPoint fadeOutToPoint; if (currentView.messagePosition != TSMessageNotificationPositionBottom) { @@ -345,7 +354,7 @@ - (void)fadeOutNotification:(TSMessageView *)currentView animationFinishedBlock: fadeOutToPoint = CGPointMake(currentView.center.x, currentView.viewController.view.bounds.size.height + CGRectGetHeight(currentView.frame)/2.f); } - + [UIView animateWithDuration:kTSMessageAnimationDuration animations:^ { currentView.center = fadeOutToPoint; @@ -355,19 +364,19 @@ - (void)fadeOutNotification:(TSMessageView *)currentView animationFinishedBlock: } completion:^(BOOL finished) { [currentView removeFromSuperview]; - + if ([self.messages count] > 0) { [self.messages removeObjectAtIndex:0]; } - + notificationActive = NO; - + if ([self.messages count] > 0) { [self fadeInCurrentNotification]; } - + if(animationFinished) { animationFinished(); } @@ -382,7 +391,7 @@ + (BOOL)dismissActiveNotification + (BOOL)dismissActiveNotificationWithCompletion:(void (^)())completion { if ([[TSMessage sharedMessage].messages count] == 0) return NO; - + dispatch_async(dispatch_get_main_queue(), ^ { if ([[TSMessage sharedMessage].messages count] == 0) return; @@ -429,7 +438,7 @@ + (NSArray *)queuedMessages + (UIViewController *)defaultViewController { __strong UIViewController *defaultViewController = _defaultViewController; - + if (!defaultViewController) { defaultViewController = [UIApplication sharedApplication].keyWindow.rootViewController; } @@ -445,7 +454,7 @@ + (BOOL)iOS7StyleEnabled #if __IPHONE_OS_VERSION_MAX_ALLOWED >= 70000 iOS7SDK = YES; #endif - + _useiOS7Style = ! (TS_SYSTEM_VERSION_LESS_THAN(@"7.0") || !iOS7SDK); }); return _useiOS7Style; From 9c5502835665f754c340216f285e45df5b13e47e Mon Sep 17 00:00:00 2001 From: Luis Vivas Date: Thu, 19 Nov 2015 10:14:07 +0000 Subject: [PATCH 2/2] Updated platform version in podspec --- TSMessages.podspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/TSMessages.podspec b/TSMessages.podspec index 600b8513..a4384ff4 100644 --- a/TSMessages.podspec +++ b/TSMessages.podspec @@ -23,7 +23,7 @@ There are 4 different types already set up for you: Success, Error, Warning, Mes s.source = { :git => "https://github.com/KrauseFx/TSMessages.git", :tag => s.version.to_s } s.social_media_url = 'https://twitter.com/KrauseFx' - s.platform = :ios, '5.0' + s.platform = :ios, '7.0' s.requires_arc = true s.source_files = 'Pod/Classes'