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

PUBLISHING A SERVICE

With all the views and outlets wired up, you can publish a service using the NSNetService class. The following Try It Out shows you how.

TRY IT OUT: Publishing a Service on the Network

  1. Using the same project created in the previous section, add the following bold statements to the BonjourAppDelegate.h file:
    #import <UIKit/UIKit.h>
    
    @class BonjourViewController;
    
    @interface BonjourAppDelegate : UIResponder
    <UIApplicationDelegate, NSNetServiceDelegate>
    {
        NSNetService *netService;
    }
    
    @property (strong, nonatomic) UIWindow *window;
    
    @property (strong, nonatomic) BonjourViewController *viewController;
    
    @end
  2. In the BonjourAppDelegate.m file, add the following statements in bold:
    #import“BonjourAppDelegate.h”
    
    #import“BonjourViewController.h”
    
    @implementation BonjourAppDelegate
    
    @synthesize window = _window;
    @synthesize viewController = _viewController;
    
    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:
     (NSDictionary *)launchOptions
    {
        //---publish the service---
        netService = [[NSNetService alloc]
                     initWithDomain:@“”
                     type:@“_MyService._tcp.”
                     name:@“iOS 5 Simulator”
                     port:9876];
        netService.delegate = self;
        [netService publish]; self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease]; // Override point for customization after application launch. self.viewController = [[[BonjourViewController alloc] initWithNibName: @“BonjourViewController”bundle:nil] autorelease]; self.window.rootViewController = self.viewController; ...

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