Dear all,

Sorry to send the email again!

I forget mentioning that Monitor was also changed. The notification is
registered to defaultCenter instead of NSWorkspace notificationCenter.

Could you help me what's wrong with the asynchronous notification?

Thanks so much!
Bing


On Mon, May 16, 2011 at 4:49 PM, Bing Li <lbl...@gmail.com> wrote:

> Dear Michael, Chase, Seth and all,
>
> I appreciate so much for your help! After changing the WorkingApp as
> follows, the notification works. One of the reasons I made such a mistake is
> that I could not get sufficient materials to learn the techniques although I
> have got more than 10 books about Cocoa. I hope Apple could improve on this.
>
>     import "WorkingApp.h"
>     @implementation WorkingApp
>
>     - (void) Print
>     {
>         NSLog(@"I am doing a tough job!");
>         [[NSNotificationCenter defaultCenter] postNotificationName:@"Done"
> object:self];
>     }
>     @end
>
> However, when trying to use asynchronous notification, I got problems
> again. Now WorkingApp is updated as follows.
>
>     import "WorkingApp.h"
>
>    @implementation WorkingApp
>
>     - (void) Print
>     {
>         NSLog(@"I am doing a tough job!");
> //      [[[NSNotificationQueue alloc]
> initWithNotificationCenter:[NSNotificationCenter defaultCenter]]
> enqueueNotification: [NSNotification notificationWithName:@"Done"
> object:self] postingStyle:NSPostNow]; // This is also sychronous.
>         [[[NSNotificationQueue alloc]
> initWithNotificationCenter:[NSNotificationCenter defaultCenter]]
> enqueueNotification: [NSNotification notificationWithName:@"Done"
> object:self] postingStyle:NSPostWhenIdle];
>         NSLog(@"I need to leave!");
>     }
>
> The commented line is the same as a synchronous notification. It works. But
> the later line must be an asynchronous notification. However, the
> AppController does not get notified. I don't understand what's wrong with
> the code.
>
> Could you give me some hints?
>
> Best regards,
> Bing
>
> @end
>
>
>
> On Mon, May 16, 2011 at 7:47 AM, Michael Babin <mba...@orderndev.com>wrote:
>
>> On May 15, 2011, at 5:31 PM, Bing Li wrote:
>>
>> An object, WorkingApp, prints a line and posts a notification as follows.
>>
>>    import "WorkingApp.h"
>>
>>    @implementation WorkingApp
>>
>>    - (void) Print
>>    {
>>        NSLog(@"I am doing a tough job!");
>>        [[NSNotificationCenter defaultCenter] postNotificationName:@"Done"
>> object:self];
>>    }
>>
>>    @end
>>
>>
>>
>>   - (void) setUpNotification: (NSString *) notification withSelector:
>> (SEL) methodName
>>    {
>>        [[[NSWorkspace sharedWorkspace] notificationCenter]
>> addObserver:self
>> selector:methodName name:notification object:nil];
>>    }
>>
>>
>> Why are you adding the observer to NSWorkspace's notification center, as
>> opposed to NSNotificationCenter's default center (where you are posting the
>> notification)?
>>
>>
>>
>
_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to