Hopefully this will help you.  Sorry for the bad formatting... trying out
Opera.

  [ObjectiveCMessage("init")]
  public override Id Init()
  {

      ObjectiveCRuntime.SendMessageSuper<IntPtr>(this, ControllerClass,
"init");

NSNotificationCenter.DefaultCenter.AddObserverSelectorNameObject(this,
ObjectiveCRuntime.Selector("doAuth:"), "doAuth", null);

      return this;

  }


  [ObjectiveCMessage("doAuth:")]
  public void SelectionChanged(NSNotification notification)
  {
  NSArray loginParms = notification.UserInfo.ObjectForKey(new
NSString("params")).CastTo<NSArray>();
  Session.DoAuthenticate(loginParms[0].CastTo<NSString>(),
loginParms[1].CastTo<NSString>());
  }

In the .m:

  NSString *username = [usernameTextField stringValue];
  NSString *password = [passwordTextField stringValue];

  NSArray *loginParams = [NSArray arrayWithObjects:username, password, nil];
  NSDictionary* dict = [NSDictionary dictionaryWithObject:loginParams
forKey:@"params"];
  NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
  [nc postNotificationName:@"doAuth" object:nil userInfo:dict];


Duane

On Thu, Oct 9, 2008 at 9:22 AM, Miguel De Buf <[EMAIL PROTECTED]>wrote:

>  Hi,
>
> I am trying to use NSDistributedNotificationCenter to send a notification
> to a listener application.  I am stuck since I do not know what to pass to
> the AddObserverSelectorNameObject() function. I could not find an example or
> more info on how to use this function.  Here is my code (which fails to
> compile) :
>
> using System;
> using System.Collections.Generic;
> using System.Text;
>
> using Monobjc;
> using Monobjc.Cocoa;
>
> namespace ipc_listener
> {
>     class Program : NSObject
>     {
>         private static Listener l = null;
>
>         static void Main(string[] args)
>         {
>             ObjectiveCRuntime.LoadFramework("Cocoa");
>             ObjectiveCRuntime.Initialize();
>             NSApplication.Initialize();
>
>             l = new Listener();
>             l.run();
>
>             NSApplication.RunApplication();
>         }
>     }
>
>     class Listener : NSObject
>     {
>         private NSNotificationCenter nc = null;
>         private delegate void NotificationHandler(NSNotification n);
>
>         public void run()
>         {
>             nc = NSDistributedNotificationCenter.DefaultCenter;
>             NotificationHandler h = handler;
>
>             nc.AddObserverSelectorNameObject((Id)this, h, (NSString)null,
> (Id)null);
>         }
>
>         void handler(NSNotification n)
>         {
>             Console.WriteLine("name=" + n.Name);
>         }
>     }
> }
>
>
> What fails is the nc.AddObserverSelectorNameObject() call, since the
> delegate h cannot be converted to an IntPtr.  I have no idea what that
> IntPtr actially represents.  I am sorry if this is a simple question, but I
> am very new to MacOSX programming and Cocoa, and do not know ObjC at all.
>
> Many thanks,
> Miguel
>
> --
>
>
>  *Miguel De Buf*
> Chief Technology Officer
> Aventiv NV, creators of NomaDesk(R) <http://www.NomaDesk.com/>
> Tel. +32 9 233 68 86 (*Belgium*)
> Fax +32 9 240 10 39 (*Belgium*)
> [EMAIL PROTECTED]
>
> Confidentiality Notice:
> *This message, together with any attachments, is intended only for the use
> of the individual or entity to which it is addressed. It may contain
> information that is confidential and prohibited from disclosure. If you are
> not the intended recipient, you are hereby notified that any dissemination
> or copying of this message or any attachment is strictly prohibited. If you
> have received this item in error, please notify the original sender and
> destroy this item, along with any attachments.*
>
>
>

Reply via email to