tags:

views:

143

answers:

4

this code is from a sample in .h part :

@interface ViewController : UITableViewController < NSNetServiceBrowserDelegate > {
        NSMutableArray * tableData;
        NSNetServiceBrowser * _browser;
        NSMutableArray * _foundServices;

        NSURLConnection * _connection;
        NSInputStream * _consumerStream;
        NSString * controllerHostName;
}
@property (nonatomic, retain) NSMutableArray * tableData;
@property (nonatomic, retain) NSNetServiceBrowser * _browser;
@property (nonatomic, retain) NSMutableArray * _foundServices;
@property (nonatomic, retain) NSURLConnection * connection;
@property (nonatomic, retain) NSInputStream * consumerStream;
@property (nonatomic, retain) NSString * controllerHostName;

in the .m part

    #import "ViewController.h"
    #include <sys/socket.h>
    #include <netinet/in.h>
    #include <unistd.h>
    #include <CFNetwork/CFNetwork.h>

    @synthesize tableData;
    @synthesize _browser;
    @synthesize _foundServices;
    @synthesize consumerStream = _consumerStream;
    @synthesize connection = _connection;
    @synthesize controllerHostName;

    - (void)viewWillAppear:(BOOL)animated {
            [super viewWillAppear:animated];

            _browser = [[NSNetServiceBrowser alloc] init];
            [_browser setDelegate:self];
            [_browser searchForServicesOfType:@"_service._tcp" inDomain:@""];
            [super viewWillAppear:animated];
    }


    - (void)viewWillDisappear:(BOOL)animated {
            [super viewWillDisappear:animated];

            [_browser stop];
            _browser.delegate = nil;
            [_browser release];
            _browser = nil;

            [_foundServices removeAllObjects];
    }
    - (void)netServiceBrowser:(NSNetServiceBrowser *)netServiceBrowser didFindService:(NSNetService *)netService moreComing:(BOOL)moreServicesComing
    {
            self.controllerHostName = [NSString stringWithFormat:@"%@.%@", netService.name, netService.domain];
            NSLog(@"ControllerHost String is: %@", self.controllerHostName);
            NSLog(@"URL to use is === %@.%@", netService.name, netService.domain);
            if (!_foundServices) {
                    _foundServices = [[NSMutableArray alloc] init];
            }

            [_foundServices addObject:netService];

            [self.tableView reloadData];
    }

    - (void)netServiceBrowser:(NSNetServiceBrowser *)netServiceBrowser didRemoveService:(NSNetService *)netService moreComing:(BOOL)moreServicesComing
    {
            [_foundServices removeObject:netService];
    }

    - (void)netServiceBrowserDidStopSearch:(NSNetServiceBrowser *)aNetServiceBrowser
    {

        [_foundServices removeAllObjects];
}

I declaration all the header as the sample does But I got error message "Cannot find protocol declaration for "NSNetServiceDelegate" in .h

interface ViewController : UITableViewController < NSNetServiceBrowserDelegate > 

So did I missing anything to declaration ? The sample doesn't has any warning or error

+1  A: 

I thought it's defined in "NSNetServices.h" instead?

Nevin
That's weird...the apple references libary says : Declared InNSNetServices.h,But I can't include or import it...
WebberLai
+1  A: 

Add this to your header:

#import <Foundation/NSNetServices.h>

I got this from the BonjourWeb Apple sample code project.

Shaggy Frog
still error ,But I remove < NSNetServiceBrowserDelegate >
WebberLai
If you are saying you deleted the `< NSNetServiceBrowserDelegate >` part but still get the compilation error, then either you didn't save the file, or you are referencing `NSNetServiceBrowserDelegate` somewhere else in your code.
Shaggy Frog
Oh I mean when I remove < NSNetServiceBrowserDelegate > ,It's ok no error,But It't won't find any service or return any Log(even it can't find)
WebberLai
It's there any relation about "Base SDK Missing" ?I update my xcode to 4.1 than the sdk was missing
WebberLai
Probably. Installing the 4.1 SDK removes the 4.0 SDK, and so you'll need to update the Base SDK build setting for your project.
Shaggy Frog
I already done this...I can't select "Simulator" > "Debug" >SDK missing.But If I change to "Release" > it become Simulator - 3.2 |Release|...
WebberLai
You need to change the build setting across All Configurations.
Shaggy Frog
I check the return data,Only _browser will return <NSNetServiceBrowser: 0x5f050a0>,other return null...so that means some void doesn't running ?
WebberLai
A: 

I found something like answer ,JUST REMOVE

- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
    [_browser stop];
    _browser.delegate = nil;
    [_browser release];
    _browser = nil;

    [_foundServices removeAllObjects];
}

The program will get Netservice I want... WHY ?

WebberLai
I can see the console result:found service <NSNetService 0x4904f40> local. _envoservice._tcp. envo_eeepcenvoControllerHost String is: envo_eeepc.localURL to use is === envo_eeepc.local.ControllerHostName IS envo_eeepc.local.but simulator crash Immediately ????????????
WebberLai
To post more information, edit your question and add it there, instead of posting an answer.
Shaggy Frog
A: 

shit ....the problem is a unused function....Just delete
[self.tableView reloadData]; It will be fine !!!!!

WebberLai
Ha ....THIS IS THE ANSWER...I FOUND IT YESTERDAY
WebberLai