NSDistributedNotification won't send with a NSDictionary

Discussion in 'Mac Programming' started by djdrake2, Sep 3, 2011.

  1. djdrake2, Sep 3, 2011
    Last edited by a moderator: Sep 3, 2011

    djdrake2 macrumors newbie

    Aug 6, 2011
    I have created a plugin for TextEdit and used SIMBL to load it. I am trying to send a notification to NSDistributedNotificationCenter.

    To send the notification I am using:
    NSString *observedObject = @"com.drake.DDX";
    NSDistributedNotificationCenter *center =[NSDistributedNotificationCenter defaultCenter];
    [center postNotificationName:@"DDXNotification" object:observedObject userInfo:nil deliverImmediately:YES];
    I am using an application called NotificationWatcher to view all the NSNotifications posted, the code above successfully posts the notification however as soon as I add an NSDictionary in userInfo: the notification is not sent.

    To create the dictionary I have been using
    NSDictionary *userInfo = [NSDictionary dictionaryWithObject:@"TextEdit" forKey:@"applicationName"];
    I do not understand why the notification will not post with a dictionary.
  2. chown33 macrumors 604

    Aug 9, 2009
    Sailing beyond the sunset
    Make a simplified test case. Run it. Post it.

    Here's mine:
    #import <Foundation/Foundation.h>
    int main(int arcgc, char *argv[])
    	NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
    	NSString *observedObject = @"com.drake.DDX";
    	NSDictionary *info = nil;
    [COLOR="Red"]//	info = [NSDictionary dictionaryWithObject:@"TextEdit" forKey:@"applicationName"];
    	NSDistributedNotificationCenter *center =[NSDistributedNotificationCenter defaultCenter];
    	[center postNotificationName:@"DDXNotification" 
    		object:observedObject userInfo:info deliverImmediately:YES];
    	[pool drain];
    	return 0;
    When I run it with the red-hilited code commented out, or with it uncommented, it works in both cases. As observed in Notification Watcher.

    If I had to guess, I'd say the actual NSDictionary you're sending isn't plist conformant. I'd also guess that you didn't post your real complete code.

    See the discussion of the posting method in the class reference doc for NSDistributedNotificationCenter:
    The notificationInfo dictionary is serialized as a property list, so it can be passed to another task. In the receiving task, it is deserialized back into a dictionary. This serialization imposes some restrictions on the objects that can be placed in the notificationInfo dictionary. See XML Property Lists for details. (emphasis added)

Share This Page