Permalink
Browse files

Updated to version 1.5.2

  • Loading branch information...
1 parent 98c557b commit 5d4030297168c7a8bc0aa3ad138630d4e6a45df6 Nick Lockwood committed Apr 4, 2012
Showing with 72 additions and 31 deletions.
  1. +1 −1 LICENCE.md
  2. +1 −1 README.md
  3. +5 −0 RELEASE NOTES.md
  4. +1 −1 iNotify/iNotify.h
  5. +64 −28 iNotify/iNotify.m
View
@@ -1,6 +1,6 @@
iNotify
-Version 1.5.1, April 4th, 2012
+Version 1.5.2, April 4th, 2012
Copyright (C) 2011 Charcoal Design
View
@@ -101,7 +101,7 @@ The dictionary may also include the following optional keys:
A URL relating to the notification. If the ActionURL is omitted, the message will not feature an action button but will simply have an OK button to dismiss the message.
-Note that the ActionURL can be used to launch other apps, or to trigger behaviour within your app by specifying a custom URL schema handler.
+Note that the ActionURL can be used to launch other apps, or to trigger behaviour within your app by specifying a custom URL schema handler. If the action URL cannot be opened (because the app is not installed), the alert will not be shown.
* ActionButton
View
@@ -1,3 +1,8 @@
+Version 1.5.2
+
+- Improved UIAlertView resizing logic
+- Alert is no longer displayed if ActionURL cannot be opened on the device
+
Version 1.5.1
- Added logic to prevent UIAlertView collapsing in landscape mode
View
@@ -1,7 +1,7 @@
//
// iNotify.h
//
-// Version 1.5.1
+// Version 1.5.2
//
// Created by Nick Lockwood on 26/01/2011.
// Copyright 2011 Charcoal Design
View
@@ -1,7 +1,7 @@
//
// iNotify.m
//
-// Version 1.5.1
+// Version 1.5.2
//
// Created by Nick Lockwood on 26/01/2011.
// Copyright 2011 Charcoal Design
@@ -56,6 +56,8 @@ @interface iNotify()
@property (nonatomic, strong) NSError *downloadError;
@property (nonatomic, strong) id visibleAlert;
+- (BOOL)canOpenURL:(NSURL *)URL;
+
@end
@@ -379,6 +381,12 @@ - (void)downloadedNotificationsData
NSString *actionURL = [notification objectForKey:iNotifyActionURLKey];
NSString *actionButtonLabel = [notification objectForKey:iNotifyActionButtonKey] ?: defaultActionButtonLabel;
+ //check action url can be opened
+ if (actionURL && ![self canOpenURL:[NSURL URLWithString:actionURL]])
+ {
+ return;
+ }
+
//check delegate
if ([self.delegate respondsToSelector:@selector(iNotifyShouldDisplayNotificationWithKey:details:)])
{
@@ -423,15 +431,15 @@ - (void)downloadedNotificationsData
defaultButton:actionButtonLabel
alternateButton:ignoreButtonLabel
otherButton:remindButtonLabel
- informativeTextWithFormat:message];
+ informativeTextWithFormat:@"%@", message];
}
else
{
self.visibleAlert = [NSAlert alertWithMessageText:title
defaultButton:okButtonLabel
alternateButton:nil
otherButton:nil
- informativeTextWithFormat:message];
+ informativeTextWithFormat:@"%@", message];
}
[visibleAlert beginSheetModalForWindow:[[NSApplication sharedApplication] mainWindow]
@@ -514,47 +522,70 @@ - (void)checkForNotifications
#pragma mark UIAlertView methods
#ifdef __IPHONE_OS_VERSION_MAX_ALLOWED
+
+- (BOOL)canOpenURL:(NSURL *)URL
+{
+ return [[UIApplication sharedApplication] canOpenURL:URL];
+}
-- (void)resizeAlert
+- (void)resizeAlertView:(UIAlertView *)alertView
{
- CGFloat offset = 0.0f;
- UIAlertView *alertView = visibleAlert;
- for (UIView *view in alertView.subviews)
+ if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone &&
+ UIInterfaceOrientationIsLandscape([UIApplication sharedApplication].statusBarOrientation))
{
- CGRect frame = view.frame;
- if ([view isKindOfClass:[UILabel class]])
+ CGFloat max = alertView.window.bounds.size.height - alertView.frame.size.height - 10.0f;
+ CGFloat offset = 0.0f;
+ for (UIView *view in alertView.subviews)
{
- UILabel *label = (UILabel *)view;
- if ([label.text isEqualToString:alertView.message])
+ CGRect frame = view.frame;
+ if ([view isKindOfClass:[UILabel class]])
+ {
+ UILabel *label = (UILabel *)view;
+ if ([label.text isEqualToString:alertView.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;
+ if (offset > max)
+ {
+ frame.size.height -= (offset - max);
+ offset = max;
+ }
+ if (offset > max - 10.0f)
+ {
+ frame.size.height -= (offset - max - 10);
+ frame.origin.y += (offset - max - 10) / 2.0f;
+ }
+ }
+ }
+ else if ([view isKindOfClass:[UITextView class]])
{
- 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;
+ view.alpha = 0.0f;
}
+ else if ([view isKindOfClass:[UIControl class]])
+ {
+ frame.origin.y += offset;
+ }
+ view.frame = frame;
}
- 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;
}
- 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];
+ [self performSelectorOnMainThread:@selector(resizeAlertView:) withObject:visibleAlert waitUntilDone:NO];
}
- (void)willPresentAlertView:(UIAlertView *)alertView
{
- [self resizeAlert];
+ [self resizeAlertView:alertView];
}
- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex
@@ -617,6 +648,11 @@ - (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)
}
#else
+
+- (BOOL)canOpenURL:(NSURL *)URL
+{
+ return [[NSWorkspace sharedWorkspace] URLForApplicationToOpenURL:URL] != nil;
+}
- (void)alertDidEnd:(NSAlert *)alert returnCode:(NSInteger)returnCode contextInfo:(void *)contextInfo
{

0 comments on commit 5d40302

Please sign in to comment.