Posted By

jgarnham on 11/14/10


Tagged

cocoa growl obj-c notifications


Versions (?)

Growl Example


 / Published in: Objective C
 

  1. /*
  2.  * All information taken from: http://growl.info/documentation/developer/implementing-growl.php?lang=cocoa
  3.  * Class written by Daniel Baucom (http://www.loud-soft.com)
  4.  */
  5.  
  6. #import <Cocoa/Cocoa.h>
  7. #import "Growl.framework/Headers/GrowlApplicationBridge.h"
  8.  
  9. @interface growlExample :NSObject <GrowlApplicationBridgeDelegate> {}
  10. -(void) growlAlert:(NSString *)message title:(NSString *)title;
  11. -(void) growlAlertWithClickContext:(NSString *)message title:(NSString *)title;
  12. -(void) exampleClickContext;
  13. @end
  14.  
  15. @implementation growlExample
  16.  
  17. /* Init method */
  18. - (id) init {
  19. if ( self = [super init] ) {
  20. /* Tell growl we are going to use this class to hand growl notifications */
  21. [GrowlApplicationBridge setGrowlDelegate:self];
  22. }
  23. return self;
  24. }
  25.  
  26. /* Begin methods from GrowlApplicationBridgeDelegate */
  27. - (NSDictionary *) registrationDictionaryForGrowl { /* Only implement this method if you do not plan on just placing a plist with the same data in your app bundle (see growl documentation) */
  28. NSArray *array = [NSArray arrayWithObjects:@"example", @"error", nil]; /* each string represents a notification name that will be valid for us to use in alert methods */
  29. NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:
  30. [NSNumber numberWithInt:1], /* growl 0.7 through growl 1.1 use ticket version 1 */
  31. @"TicketVersion", /* Required key in dictionary */
  32. array, /* defines which notification names our application can use, we defined example and error above */
  33. @"AllNotifications", /*Required key in dictionary */
  34. array, /* using the same array sets all notification names on by default */
  35. @"DefaultNotifications", /* Required key in dictionary */
  36. nil];
  37. return dict;
  38. }
  39.  
  40. - (void) growlNotificationWasClicked:(id)clickContext{
  41. if (clickContext && [clickContext isEqualToString:@"exampleClickContext"])
  42. [self exampleClickContext];
  43. return;
  44. }
  45.  
  46. /* These methods are not required to be implemented, so we will skip them in this example
  47. - (NSString *) applicationNameForGrowl;
  48. - (NSData *) applicationIconDataForGrowl;
  49. - (void) growlNotificationTimedOut:(id)clickContext;
  50. */
  51. /* There is no good reason not to rely on the what Growl provides for the next two methods, in otherwords, do not override these methods
  52. - (void) growlIsReady;
  53. - (void) growlIsInstalled;
  54. */
  55. /* End Methods from GrowlApplicationBridgeDelegate */
  56.  
  57. /* Simple method to make an alert with growl that has no click context */
  58. -(void) growlAlert:(NSString *)message title:(NSString *)title{
  59. [GrowlApplicationBridge notifyWithTitle:title /* notifyWithTitle is a required parameter */
  60. description:message /* description is a required parameter */
  61. notificationName:@"example" /* notification name is a required parameter, and must exist in the dictionary we registered with growl */
  62. iconData:nil /* not required, growl defaults to using the application icon, only needed if you want to specify an icon. */
  63. priority:0 /* how high of priority the alert is, 0 is default */
  64. isSticky:NO /* indicates if we want the alert to stay on screen till clicked */
  65. clickContext:nil]; /* click context is the method we want called when the alert is clicked, nil for none */
  66. }
  67.  
  68. /* Simple method to make an alert with growl that has a click context */
  69. -(void) growlAlertWithClickContext:(NSString *)message title:(NSString *)title{
  70. [GrowlApplicationBridge notifyWithTitle:title /* notifyWithTitle is a required parameter */
  71. description:message /* description is a required parameter */
  72. notificationName:@"example" /* notification name is a required parameter, and must exist in the dictionary we registered with growl */
  73. iconData:nil /* not required, growl defaults to using the application icon, only needed if you want to specify an icon. */
  74. priority:0 /* how high of priority the alert is, 0 is default */
  75. isSticky:NO /* indicates if we want the alert to stay on screen till clicked */
  76. clickContext:@"exampleClickContext"]; /* click context is the method we want called when the alert is clicked, nil for none */
  77. }
  78.  
  79. /* An example click context */
  80. -(void) exampleClickContext{
  81. /* code to execute when alert is clicked */
  82. return;
  83. }
  84.  
  85. /* Dealloc method */
  86. - (void) dealloc {
  87. [super dealloc];
  88. }
  89. @end

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: dzarchana on July 1, 2011

hi all

i am looking some help on iphone app development .I am developing a registration screen.in that screen we have some text filed and image upload .after filling the all required field when i am going to click 0n upload image button it will navigate to another screen. once i choose image and then back to the screen it will be display blank.

so, please help me how can i retain the all information on registration screen once i back after uploading the image.

please help me as soon as possible.I am waiting your response.

Thanks Archana

You need to login to post a comment.