More about Implementing Growl in a Cocoa Application

The Growl Developer documentation has a mostly nice article setting out how to do this. But it’s a bit vague in spots and assumes you’re an experienced Cocoa developer. If you’re not, here are the steps I followed to implement Growl:

  1. Install the Growl.Framework into your app’s Xcode project. Use the procedure at the very bottom of the Implementing Growl article.
  2. Decide which object in your app will send notifications to Growl.
    It will be your Growl delegate object.
  3. Open the delegate’s header file (.h) and import the Growl framework by adding the line:
    #import "Growl/Growl.h".
  4. With the header file still open, state it implement’s the GrowlApplicationBridgeDelegate protocol. That is, state the protocol in the interface declaration by adding:
    <GrowlApplicationBridgeDelegate>.
    For example, @interface Controller : NSObject<GrowlApplicationBridgeDelegate>
  5. Open the delegate’s implementation file (.m) and locate the - init method. Add the lines:
    [GrowlApplicationBridge setGrowlDelegate: self]; and
    [self registrationDictionaryForGrowl];.
  6. Still editing the implementation file (.m) file, implement these methods:
    - registrationDictionaryForGrowl and
    - applicationNameForGrowl.
    See the Implementing Growl for info about these methods, and other optional methods you can use.

That’s it. All you have to do now is send a notification to Growl using [GrowlApplicationBridge notifyWithTitle: ...].

I hope this saves you some time. It would have been nice if the Implementing Growl article could have provided these steps for less experienced developers. But anyway.

Happy St Patrick’s Day!

NB This article has been updated to fix a copy/paste issue, and to adopt class/instance terminology for the methods used.

Advertisements

3 comments so far

  1. boredzo on

    Some points:

    (1) You should be using rather than “” for a framework-based import or include.

    (2) The protocol is named GrowlApplicationBridgeDelegate. The word ‘Delegate’ isn’t optional – not even inside the . Therefore the interface should read:

    @interface Controller : NSObject

    (3) Methods’ argument lists do not have () around them, and it is a good idea to always make clear whether you are talking about an instance method or a class method. There is no init(), only -init. This goes for -registrationDictionaryForGrowl and -applicationNameForGrowl as well.

  2. boredzo on

    Ergh. Sorry; didn’t know that it takes out <>. Here’s hoping it handles entities and lists.

    You should be using <> rather than “” for a framework-based import or include.
    The protocol is named GrowlApplicationBridgeDelegate. The word “Delegate” isn’t optional — not even inside the <>. Therefore the interface should read:

    @interface Controller : NSObject<GrowlApplicationBridgeDelegate>

    Methods’ argument lists do not have () around them, and it is a good idea to always make clear whether you are talking about an instance method or a class method. There is no init(), only -init. This goes for -registrationDictionaryForGrowl and -applicationNameForGrowl as well.

    And I hit ‘Submit Comment’ by accident while I was writing this version. I hope I stopped it in time; I really didn’t mean to post three comments. 😦

  3. gild on

    Thanks for the comments boredzo.

    WordPress doesn’t handle < and > brackets well, and this caused my to copy/paste the wrong protocol name. I’ve just fixed it.

    I don’t know what I was thinking using (brackets) instead of (braces )! Thanks for the tip about using class/instance method names. I’ve updated the article to adopt this style.

    You were obviously quick enough to cancel the Submit button as I only ended up with 2 comments 🙂


Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: