O'Reilly logo

Beginning iOS 5 Application Development by Wei-Meng Lee

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

BROWSING FOR SERVICES

Now that you have seen how to publish a service, this section demonstrates how you can browse for services that have been published on the network. You will use the NSNetServiceBrowser class to discover services published on the network.

TRY IT OUT: Browsing for Services on the Network

  1. Using the Bonjour project from the previous Try it Out, add the following bold statements to the BonjourViewController.h importfile:
    #import <arpa/inet.h>
    
    @interface BonjourViewController : UIViewController
    <UITableViewDelegate, UITableViewDataSource,
     NSNetServiceDelegate, NSNetServiceBrowserDelegate>
    {
        IBOutlet UITableView *tbView;
        IBOutlet UITextView *debug;
        NSNetServiceBrowser *browser;
        NSMutableArray *services;
    }
    
    @property (nonatomic, retain) UITableView *tbView;
    @property (nonatomic, retain) UITextView *debug;
    @property (nonatomic, retain) NSNetServiceBrowser *browser;
    @property (nonatomic, retain) NSMutableArray *services;
    
    -(void) resolveIPAddress:(NSNetService *)service;
    -(void) browseServices;
    
    @end
  2. In the BonjourViewController.m file, add the following bold statements:
    #import“BonjourViewController.h”
    
    @implementation BonjourViewController
    
    @synthesize tbView;
    @synthesize debug;
    
    @synthesize browser;
    @synthesize services;
    
    -(NSInteger) tableView:(UITableView *)tableView
      numberOfRowsInSection:(NSInteger)section {
        return [self.services count];
    }
    
    -(UITableViewCell *) tableView:(UITableView *)tableView  cellForRowAtIndexPath:
             (NSIndexPath *)indexPath {
        static NSString *CellIdentifier ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required