Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Updated to version 1.5.2

  • Loading branch information...
commit 5d4030297168c7a8bc0aa3ad138630d4e6a45df6 1 parent 98c557b
Nick Lockwood authored
2  LICENCE.md
Source Rendered
... ... @@ -1,6 +1,6 @@
1 1 iNotify
2 2
3   -Version 1.5.1, April 4th, 2012
  3 +Version 1.5.2, April 4th, 2012
4 4
5 5 Copyright (C) 2011 Charcoal Design
6 6
2  README.md
Source Rendered
@@ -101,7 +101,7 @@ The dictionary may also include the following optional keys:
101 101
102 102 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.
103 103
104   -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.
  104 +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.
105 105
106 106 * ActionButton
107 107
5 RELEASE NOTES.md
Source Rendered
... ... @@ -1,3 +1,8 @@
  1 +Version 1.5.2
  2 +
  3 +- Improved UIAlertView resizing logic
  4 +- Alert is no longer displayed if ActionURL cannot be opened on the device
  5 +
1 6 Version 1.5.1
2 7
3 8 - Added logic to prevent UIAlertView collapsing in landscape mode
2  iNotify/iNotify.h
... ... @@ -1,7 +1,7 @@
1 1 //
2 2 // iNotify.h
3 3 //
4   -// Version 1.5.1
  4 +// Version 1.5.2
5 5 //
6 6 // Created by Nick Lockwood on 26/01/2011.
7 7 // Copyright 2011 Charcoal Design
92 iNotify/iNotify.m
... ... @@ -1,7 +1,7 @@
1 1 //
2 2 // iNotify.m
3 3 //
4   -// Version 1.5.1
  4 +// Version 1.5.2
5 5 //
6 6 // Created by Nick Lockwood on 26/01/2011.
7 7 // Copyright 2011 Charcoal Design
@@ -56,6 +56,8 @@ @interface iNotify()
56 56 @property (nonatomic, strong) NSError *downloadError;
57 57 @property (nonatomic, strong) id visibleAlert;
58 58
  59 +- (BOOL)canOpenURL:(NSURL *)URL;
  60 +
59 61 @end
60 62
61 63
@@ -379,6 +381,12 @@ - (void)downloadedNotificationsData
379 381 NSString *actionURL = [notification objectForKey:iNotifyActionURLKey];
380 382 NSString *actionButtonLabel = [notification objectForKey:iNotifyActionButtonKey] ?: defaultActionButtonLabel;
381 383
  384 + //check action url can be opened
  385 + if (actionURL && ![self canOpenURL:[NSURL URLWithString:actionURL]])
  386 + {
  387 + return;
  388 + }
  389 +
382 390 //check delegate
383 391 if ([self.delegate respondsToSelector:@selector(iNotifyShouldDisplayNotificationWithKey:details:)])
384 392 {
@@ -423,7 +431,7 @@ - (void)downloadedNotificationsData
423 431 defaultButton:actionButtonLabel
424 432 alternateButton:ignoreButtonLabel
425 433 otherButton:remindButtonLabel
426   - informativeTextWithFormat:message];
  434 + informativeTextWithFormat:@"%@", message];
427 435 }
428 436 else
429 437 {
@@ -431,7 +439,7 @@ - (void)downloadedNotificationsData
431 439 defaultButton:okButtonLabel
432 440 alternateButton:nil
433 441 otherButton:nil
434   - informativeTextWithFormat:message];
  442 + informativeTextWithFormat:@"%@", message];
435 443 }
436 444
437 445 [visibleAlert beginSheetModalForWindow:[[NSApplication sharedApplication] mainWindow]
@@ -514,47 +522,70 @@ - (void)checkForNotifications
514 522 #pragma mark UIAlertView methods
515 523
516 524 #ifdef __IPHONE_OS_VERSION_MAX_ALLOWED
  525 +
  526 +- (BOOL)canOpenURL:(NSURL *)URL
  527 +{
  528 + return [[UIApplication sharedApplication] canOpenURL:URL];
  529 +}
517 530
518   -- (void)resizeAlert
  531 +- (void)resizeAlertView:(UIAlertView *)alertView
519 532 {
520   - CGFloat offset = 0.0f;
521   - UIAlertView *alertView = visibleAlert;
522   - for (UIView *view in alertView.subviews)
  533 + if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone &&
  534 + UIInterfaceOrientationIsLandscape([UIApplication sharedApplication].statusBarOrientation))
523 535 {
524   - CGRect frame = view.frame;
525   - if ([view isKindOfClass:[UILabel class]])
  536 + CGFloat max = alertView.window.bounds.size.height - alertView.frame.size.height - 10.0f;
  537 + CGFloat offset = 0.0f;
  538 + for (UIView *view in alertView.subviews)
526 539 {
527   - UILabel *label = (UILabel *)view;
528   - if ([label.text isEqualToString:alertView.message])
  540 + CGRect frame = view.frame;
  541 + if ([view isKindOfClass:[UILabel class]])
  542 + {
  543 + UILabel *label = (UILabel *)view;
  544 + if ([label.text isEqualToString:alertView.message])
  545 + {
  546 + label.alpha = 1.0f;
  547 + label.lineBreakMode = UILineBreakModeWordWrap;
  548 + label.numberOfLines = 0;
  549 + [label sizeToFit];
  550 + offset = label.frame.size.height - frame.size.height;
  551 + frame.size.height = label.frame.size.height;
  552 + if (offset > max)
  553 + {
  554 + frame.size.height -= (offset - max);
  555 + offset = max;
  556 + }
  557 + if (offset > max - 10.0f)
  558 + {
  559 + frame.size.height -= (offset - max - 10);
  560 + frame.origin.y += (offset - max - 10) / 2.0f;
  561 + }
  562 + }
  563 + }
  564 + else if ([view isKindOfClass:[UITextView class]])
529 565 {
530   - label.alpha = 1.0f;
531   - label.lineBreakMode = UILineBreakModeWordWrap;
532   - label.numberOfLines = 0;
533   - [label sizeToFit];
534   - offset = label.frame.size.height - frame.size.height;
535   - frame.size.height = label.frame.size.height;
  566 + view.alpha = 0.0f;
536 567 }
  568 + else if ([view isKindOfClass:[UIControl class]])
  569 + {
  570 + frame.origin.y += offset;
  571 + }
  572 + view.frame = frame;
537 573 }
538   - else if ([view isKindOfClass:[UIControl class]])
539   - {
540   - frame.origin.y += offset;
541   - }
542   - view.frame = frame;
  574 + CGRect frame = alertView.frame;
  575 + frame.origin.y -= roundf(offset/2.0f);
  576 + frame.size.height += offset;
  577 + alertView.frame = frame;
543 578 }
544   - CGRect frame = alertView.frame;
545   - frame.origin.y -= roundf(offset/2.0f);
546   - frame.size.height += offset;
547   - alertView.frame = frame;
548 579 }
549 580
550 581 - (void)didRotate
551 582 {
552   - [self performSelectorOnMainThread:@selector(resizeAlert) withObject:nil waitUntilDone:NO];
  583 + [self performSelectorOnMainThread:@selector(resizeAlertView:) withObject:visibleAlert waitUntilDone:NO];
553 584 }
554 585
555 586 - (void)willPresentAlertView:(UIAlertView *)alertView
556 587 {
557   - [self resizeAlert];
  588 + [self resizeAlertView:alertView];
558 589 }
559 590
560 591 - (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex
@@ -617,6 +648,11 @@ - (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)
617 648 }
618 649
619 650 #else
  651 +
  652 +- (BOOL)canOpenURL:(NSURL *)URL
  653 +{
  654 + return [[NSWorkspace sharedWorkspace] URLForApplicationToOpenURL:URL] != nil;
  655 +}
620 656
621 657 - (void)alertDidEnd:(NSAlert *)alert returnCode:(NSInteger)returnCode contextInfo:(void *)contextInfo
622 658 {

0 comments on commit 5d40302

Please sign in to comment.
Something went wrong with that request. Please try again.