On 16 Mar '08, at 12:25 AM, Jason Ellemor wrote:

I guess, I don't fully understand the code posted enough because I can't seem to access the dictionary object created and posted to the notifications with the previous example.

The code is sending the dictionary as the object of the notification. So your observer method would access it as [n object]:

- (void) yourObserver: (NSNotfication*)n
{
        NSDictionary *dict = [n object];
NSData *packet = [dict objectForKey: @"NSFileHandleNotificationDataItem"];
        ...
}

However, I would suggest that you *not* use the existing notification name NSFileHandleReadCompletionNotification for this, because your method would also receive those notifications posted by any NSFileHandles in your application, and in that case the notification object would be the NSFileHandle instance, not a dictionary. Instead, make up your own notification name, and post and listen for that.

Secondly, the device has "Null" bytes in the output stream and I am guessing if I get the data into a NSString object, when trying to parse the string, it will terminate because of the Null.

(1) The code you posted doesn't put the data in an NSString; it's in an NSData. Which is appropriate if it consists of binary data. If there are pieces of it that are strings, you can extract those bits out of the NSData and convert them to NSStrings.

(2) But in any case, NSString doesn't mind embedded null bytes. (It's not null-terminated like a C string; the string object remembers the length separately.) That doesn't mean you should store binary data in an NSString, though. NSData is better for that.

—Jens

Attachment: smime.p7s
Description: S/MIME cryptographic signature

_______________________________________________

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 [EMAIL PROTECTED]

Reply via email to