Re: how to archive NSNetService?
Re: how to archive NSNetService?
- Subject: Re: how to archive NSNetService?
- From: Chris Parker <email@hidden>
- Date: Fri, 16 Jan 2009 14:46:55 -0800
Hi Allyn,
On 16 Jan 2009, at 2:00 PM, Allyn Bauer wrote:
I'm writing a fairly simple server <-> client app. The server
publishes a network name using Bonjour and clients get a list of
names. They choose one (for now). After this choice, I would like the
selection to somehow be saved using NSUserDefaults. I'm assuming the
easiest way to do this is to get the name of the saved network and
save that string. Is this assumption correct? If not, how would you
suggest I accomplish this? Is there anyway to save the enough network
information to reconnect to the same server even if the network name
has been changed?
The goal is to be able to automatically reconnect to an already chosen
network -- if there's one saved -- when the app loads.
I'm still learning this stuff, but it's becoming slightly easier.
Thanks for the help.
NSNetService instances aren't archivable, so you can't directly encode
them. You can write out your own dictionary which would contain the
domain and name of the selected service (presumably you're always
browsing for the same type, so you don't necessarily have to write
that out - if you're browsing for the same domain all the time, then
that's not necessary either).
When the user runs the application again, retrieve the dictionary and
use those values to call -[NSNetService initWithDomain:type:name:].
That call returns an NSNetService suitable for resolution.
.chris
--
Chris Parker
Cocoa Frameworks
Apple Inc.
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
This email sent to email@hidden