3
Abstract: A subclass of UINavigationController that handles the UI needed for a user to
4
browse for Bonjour services.
5
It contains list view controllers for domains and service instances.
6
It allows the user to add their own domains.
10
Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple
11
Inc. ("Apple") in consideration of your agreement to the following
12
terms, and your use, installation, modification or redistribution of
13
this Apple software constitutes acceptance of these terms. If you do
14
not agree with these terms, please do not use, install, modify or
15
redistribute this Apple software.
17
In consideration of your agreement to abide by the following terms, and
18
subject to these terms, Apple grants you a personal, non-exclusive
19
license, under Apple's copyrights in this original Apple software (the
20
"Apple Software"), to use, reproduce, modify and redistribute the Apple
21
Software, with or without modifications, in source and/or binary forms;
22
provided that if you redistribute the Apple Software in its entirety and
23
without modifications, you must retain this notice and the following
24
text and disclaimers in all such redistributions of the Apple Software.
25
Neither the name, trademarks, service marks or logos of Apple Inc. may
26
be used to endorse or promote products derived from the Apple Software
27
without specific prior written permission from Apple. Except as
28
expressly stated in this notice, no other rights or licenses, express or
29
implied, are granted by Apple herein, including but not limited to any
30
patent rights that may be infringed by your derivative works or by other
31
works in which the Apple Software may be incorporated.
33
The Apple Software is provided by Apple on an "AS IS" basis. APPLE
34
MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION
35
THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS
36
FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND
37
OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS.
39
IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL
40
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
41
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
42
INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION,
43
MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED
44
AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE),
45
STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE
46
POSSIBILITY OF SUCH DAMAGE.
48
Copyright (C) 2009 Apple Inc. All Rights Reserved.
52
#import "BonjourBrowser.h"
53
#import "BrowserViewController.h"
54
#import "DomainViewController.h"
57
@interface BonjourBrowser ()
58
@property(nonatomic, retain, readwrite) BrowserViewController* bvc;
59
@property(nonatomic, retain, readwrite) DomainViewController* dvc;
60
@property(nonatomic, retain, readwrite) NSString* type;
61
@property(nonatomic, retain, readwrite) NSString* domain;
62
@property(nonatomic, assign, readwrite) BOOL showDisclosureIndicators;
63
@property(nonatomic, assign, readwrite) BOOL showCancelButton;
64
- (void) setupBrowser;
68
@implementation BonjourBrowser
71
@synthesize bvc = _bvc;
72
@synthesize dvc = _dvc;
73
@synthesize type = _type;
74
@synthesize domain = _domain;
75
@synthesize showDisclosureIndicators = _showDisclosureIndicators;
76
@synthesize showCancelButton = _showCancelButton;
79
- (id) initForType:(NSString*)type inDomain:(NSString*)domain
80
customDomains:(NSMutableArray*)customDomains
81
showDisclosureIndicators:(BOOL)showDisclosureIndicators
82
showCancelButton:(BOOL)showCancelButton {
84
// Create some strings that will be used in the DomainViewController.
85
NSString *domainsTitle = NSLocalizedString(@"Domains", @"Domains title");
86
NSString *domainLabel = NSLocalizedString(@"Added Domains", @"Added Domains label");
87
NSString *addDomainTitle = NSLocalizedString(@"Add Domain", @"Add Domain title");
88
NSString *searchingForServicesString = NSLocalizedString(@"Searching for services", @"Searching for services string");
90
// Initialize the DomainViewController, which uses a NSNetServiceBrowser to look for Bonjour domains.
91
DomainViewController* dvc = [[DomainViewController alloc] initWithTitle:domainsTitle showDisclosureIndicators:YES customsTitle:domainLabel customs:customDomains addDomainTitle:addDomainTitle showCancelButton:showCancelButton];
93
if (dvc && (self = [super initWithRootViewController:dvc])) {
95
self.showDisclosureIndicators = showDisclosureIndicators;
96
self.showCancelButton = showCancelButton;
97
self.searchingForServicesString = searchingForServicesString;
99
[self.dvc setDelegate:self];
100
[self.dvc searchForBrowsableDomains]; // Tells the DomainViewController's NSNetServiceBrowser to start a search for domains that are browsable via Bonjour and the computer's network configuration.
102
if ([domain length]) {
103
self.domain = domain;
104
[self setupBrowser]; // Initiate a search for Bonjour services of the type self.type.
105
[self pushViewController:self.bvc animated:NO];
114
- (NSString*) searchingForServicesString {
115
return _searchingForServicesString;
118
// This property holds a string that displays the status of the service search to the user.
119
- (void) setSearchingForServicesString:(NSString*)searchingForServicesString {
120
if (_searchingForServicesString != searchingForServicesString) {
121
[_searchingForServicesString release];
122
_searchingForServicesString = [searchingForServicesString copy];
125
self.bvc.searchingForServicesString = _searchingForServicesString;
130
- (void) setDelegate:(id<BonjourBrowserDelegate>)delegate {
131
__delegate = delegate;
132
super.delegate = delegate;
136
- (id<BonjourBrowserDelegate>) delegate {
137
assert(__delegate == super.delegate);
142
- (BOOL) showTitleInNavigationBar {
143
return _showTitleInNavigationBar;
147
- (void) setShowTitleInNavigationBar:(BOOL)show {
148
_showTitleInNavigationBar = show;
150
self.bvc.navigationItem.prompt = self.title;
151
self.dvc.navigationItem.prompt = self.title;
153
self.bvc.navigationItem.prompt = nil;
154
self.dvc.navigationItem.prompt = nil;
159
- (void) browserViewController:(BrowserViewController*)bvc didResolveInstance:(NSNetService*)service {
160
assert(bvc == self.bvc);
161
[self.delegate bonjourBrowser:self didResolveInstance:service];
164
// Create a BrowserViewController, which manages a NSNetServiceBrowser configured to look for Bonjour services.
165
- (void) setupBrowser {
166
BrowserViewController* aBvc = [[BrowserViewController alloc] initWithTitle:self.domain showDisclosureIndicators:self.showDisclosureIndicators showCancelButton:self.showCancelButton];
167
aBvc.searchingForServicesString = self.searchingForServicesString;
168
aBvc.delegate = self;
169
// Calls -[NSNetServiceBrowser searchForServicesOfType:inDomain:].
170
[aBvc searchForServicesOfType:self.type inDomain:self.domain];
172
// Store the BrowerViewController in an instance variable.
175
if (self.showTitleInNavigationBar)
176
self.bvc.navigationItem.prompt = self.title;
179
// This method will be invoked when the user selects one of the domains from the list.
180
// The domain parameter will be the selected domain or nil if the user taps the 'Cancel' button (if shown).
181
- (void) domainViewController:(DomainViewController*)dvc didSelectDomain:(NSString*)domain {
184
[self.delegate bonjourBrowser:self didResolveInstance:nil];
188
self.domain = domain;
190
[self pushViewController:self.bvc animated:YES];
199
[_searchingForServicesString release];