diff --git a/Examples/iPhone Demo/Classes/iNotifyViewController.m b/Examples/iPhone Demo/Classes/iNotifyViewController.m index d8feefc..6a7af60 100644 --- a/Examples/iPhone Demo/Classes/iNotifyViewController.m +++ b/Examples/iPhone Demo/Classes/iNotifyViewController.m @@ -10,4 +10,9 @@ @implementation iNotifyViewController +- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation +{ + return YES; +} + @end diff --git a/LICENCE.md b/LICENCE.md index ea2c859..01ea840 100644 --- a/LICENCE.md +++ b/LICENCE.md @@ -1,6 +1,6 @@ iNotify -Version 1.5, March 16th, 2012 +Version 1.5.1, April 4th, 2012 Copyright (C) 2011 Charcoal Design diff --git a/RELEASE NOTES.md b/RELEASE NOTES.md index d60da5c..1730fd4 100644 --- a/RELEASE NOTES.md +++ b/RELEASE NOTES.md @@ -1,3 +1,7 @@ +Version 1.5.1 + +- Added logic to prevent UIAlertView collapsing in landscape mode + Version 1.5 - Included localisation for French, German, Italian, Spanish and Japanese diff --git a/iNotify/iNotify.h b/iNotify/iNotify.h index 1cddbb7..45c4832 100644 --- a/iNotify/iNotify.h +++ b/iNotify/iNotify.h @@ -1,7 +1,7 @@ // // iNotify.h // -// Version 1.5 +// Version 1.5.1 // // Created by Nick Lockwood on 26/01/2011. // Copyright 2011 Charcoal Design @@ -138,6 +138,8 @@ static NSString *const iNotifyMessageMaxVersionKey = @"MaxVersion"; BOOL checkAtLaunch; BOOL debug; id __AH_WEAK delegate; + id visibleAlert; + NSString *message; } #endif diff --git a/iNotify/iNotify.m b/iNotify/iNotify.m index bd66a0e..b83c88a 100644 --- a/iNotify/iNotify.m +++ b/iNotify/iNotify.m @@ -1,7 +1,7 @@ // // iNotify.m // -// Version 1.5 +// Version 1.5.1 // // Created by Nick Lockwood on 26/01/2011. // Copyright 2011 Charcoal Design @@ -54,6 +54,8 @@ @interface iNotify() @property (nonatomic, copy) NSDictionary *notificationsDict; @property (nonatomic, strong) NSError *downloadError; +@property (nonatomic, strong) id visibleAlert; +@property (nonatomic, strong) NSString *message; @end @@ -75,7 +77,8 @@ @implementation iNotify @synthesize checkAtLaunch; @synthesize debug; @synthesize delegate; - +@synthesize visibleAlert; +@synthesize message; + (iNotify *)sharedInstance { @@ -134,6 +137,11 @@ - (iNotify *)init name:UIApplicationWillEnterForegroundNotification object:nil]; } + + [[NSNotificationCenter defaultCenter] addObserver:self + selector:@selector(didRotate) + name:UIDeviceOrientationDidChangeNotification + object:nil]; #else //register for mac application events [[NSNotificationCenter defaultCenter] addObserver:self @@ -267,6 +275,8 @@ - (void)dealloc AH_RELEASE(ignoreButtonLabel); AH_RELEASE(remindButtonLabel); AH_RELEASE(defaultActionButtonLabel); + AH_RELEASE(visibleAlert); + AH_RELEASE(message); AH_SUPER_DEALLOC; } @@ -368,7 +378,7 @@ - (void)downloadedNotificationsData //get notification details NSString *title = [notification objectForKey:iNotifyTitleKey]; - NSString *message = [notification objectForKey:iNotifyMessageKey]; + NSString *_message = [notification objectForKey:iNotifyMessageKey]; NSString *actionURL = [notification objectForKey:iNotifyActionURLKey]; NSString *actionButtonLabel = [notification objectForKey:iNotifyActionButtonKey] ?: defaultActionButtonLabel; @@ -381,54 +391,59 @@ - (void)downloadedNotificationsData } } -#ifdef __IPHONE_OS_VERSION_MAX_ALLOWED - - UIAlertView *alert = [[UIAlertView alloc] initWithTitle:title - message:message - delegate:self - cancelButtonTitle:nil - otherButtonTitles:nil]; - if (actionURL) + if (!visibleAlert) { - [alert addButtonWithTitle:actionButtonLabel]; - [alert addButtonWithTitle:remindButtonLabel]; - [alert addButtonWithTitle:ignoreButtonLabel]; - alert.cancelButtonIndex = 2; - } - else - { - [alert addButtonWithTitle:okButtonLabel]; - alert.cancelButtonIndex = 0; - } + self.message = _message; + +#ifdef __IPHONE_OS_VERSION_MAX_ALLOWED - [alert show]; - AH_RELEASE(alert); + UIAlertView *alert = [[UIAlertView alloc] initWithTitle:title + message:message + delegate:self + cancelButtonTitle:nil + otherButtonTitles:nil]; + if (actionURL) + { + [alert addButtonWithTitle:actionButtonLabel]; + [alert addButtonWithTitle:remindButtonLabel]; + [alert addButtonWithTitle:ignoreButtonLabel]; + alert.cancelButtonIndex = 2; + } + else + { + [alert addButtonWithTitle:okButtonLabel]; + alert.cancelButtonIndex = 0; + } + + self.visibleAlert = alert; + [visibleAlert show]; + AH_RELEASE(alert); + #else - NSAlert *alert = nil; - - if (actionURL) - { - alert = [NSAlert alertWithMessageText:title - defaultButton:actionButtonLabel - alternateButton:ignoreButtonLabel - otherButton:remindButtonLabel - informativeTextWithFormat:message]; - } - else - { - alert = [NSAlert alertWithMessageText:title - defaultButton:okButtonLabel - alternateButton:nil - otherButton:nil - informativeTextWithFormat:message]; - } - - [alert beginSheetModalForWindow:[[NSApplication sharedApplication] mainWindow] - modalDelegate:self - didEndSelector:@selector(alertDidEnd:returnCode:contextInfo:) - contextInfo:nil]; + + if (actionURL) + { + self.visibleAlert = [NSAlert alertWithMessageText:title + defaultButton:actionButtonLabel + alternateButton:ignoreButtonLabel + otherButton:remindButtonLabel + informativeTextWithFormat:message]; + } + else + { + self.visibleAlert = [NSAlert alertWithMessageText:title + defaultButton:okButtonLabel + alternateButton:nil + otherButton:nil + informativeTextWithFormat:message]; + } + + [visibleAlert beginSheetModalForWindow:[[NSApplication sharedApplication] mainWindow] + modalDelegate:self + didEndSelector:@selector(alertDidEnd:returnCode:contextInfo:) + contextInfo:nil]; #endif - + } } } @@ -500,10 +515,52 @@ - (void)checkForNotifications } #pragma mark - -#pragma mark UIAlertViewDelegate methods +#pragma mark UIAlertView methods #ifdef __IPHONE_OS_VERSION_MAX_ALLOWED +- (void)resizeAlert +{ + CGFloat offset = 0.0f; + UIAlertView *alertView = visibleAlert; + for (UIView *view in alertView.subviews) + { + CGRect frame = view.frame; + if ([view isKindOfClass:[UILabel class]]) + { + UILabel *label = (UILabel *)view; + if ([label.text isEqualToString:self.message]) + { + label.alpha = 1.0f; + label.lineBreakMode = UILineBreakModeWordWrap; + label.numberOfLines = 0; + [label sizeToFit]; + offset = label.frame.size.height - frame.size.height; + frame.size.height = label.frame.size.height; + } + } + else if ([view isKindOfClass:[UIControl class]]) + { + frame.origin.y += offset; + } + view.frame = frame; + } + CGRect frame = alertView.frame; + frame.origin.y -= roundf(offset/2.0f); + frame.size.height += offset; + alertView.frame = frame; +} + +- (void)didRotate +{ + [self performSelectorOnMainThread:@selector(resizeAlert) withObject:nil waitUntilDone:NO]; +} + +- (void)willPresentAlertView:(UIAlertView *)alertView +{ + [self resizeAlert]; +} + - (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex { NSString *key = [self nextNotificationInDict:notificationsDict]; @@ -558,6 +615,9 @@ - (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger) //open URL [[UIApplication sharedApplication] openURL:[NSURL URLWithString:actionURL]]; } + + //release alert + self.visibleAlert = nil; } #else