views:

575

answers:

1

Hi Guys,

I need to be able to search for all bluetooth devices nearby and just get there ids. I don't need to pair at all. I am using iphone 2.3 beta.

Is this possible l have tried using GameKit and no luck does anyone know how to do this.

 BOOL result = NO;
if (!session) {
    session = [[GKSession alloc] initWithSessionID:@"SCANNER" 
                                        displayName:nil 
                                        sessionMode:GKSessionModePeer];
    self.session.delegate = self;
    [self.session setDataReceiveHandler:self withContext:nil];
    self.session.available = YES;
    result = YES;
}

it dies on [self.session setDataReceiveHandler:self withContext:nil];

with the following error

Scanner[42754:207] Error: 30500 -- Invalid parameter for -setDataReceiveHandler:withContext:.

then ~ DNSServiceRegister callback: Ref=471fa40, Flags=2, ErrorType=0 name=00rusor1A..iPhone Simulator regtype=_q1eu29voete9jf._udp. domain=local.

A: 

Does self implement the required method

- (void) receiveData:(NSData *)data fromPeer:(NSString *)peer inSession: (GKSession *)session context:(void *)context;

somewhere? Otherwise, it is unable to satisfy the needs of the -setDataReceiveHandler:withContext: method. Also, I don't believe you can access Bluetooth functions from within the iPhone Simulator.

Overall, I don't think this will do what you want. GameKit uses Bonjour discovery to detect other iPhones / iPod touches running similar game sessions within a local Bluetooth network. It will not detect all Bluetooth devices in the vicinity. You can use lower-level Bonjour discovery yourself to find all Bonjour devices that are network-accessible via WiFi or Bluetooth, but Bluetooth access itself is abstracted away from you.

Brad Larson
Cheers brad. Yeah l know that you cant get it to work on the sim. I dont need to detech all just as many as possible does not need to be perfect. How do u use bonjor to detect all bluetooth?
Michael Cindric
Bonjour will not differentiate between network types on the iPhone, it will simply report back all Bonjour-responding devices on any available network (Bluetooth, WiFi, or otherwise). There's no way to get it to return only Bluetooth devices, short of shutting off the WiFi and cellular interfaces. It also will only find Bonjour devices, which few Bluetooth devices are. See the NSNetServices and CFNetServices Programming Guide: http://developer.apple.com/iphone/library/documentation/Networking/Conceptual/NSNetServiceProgGuide/Articles/BrowsingForServices.html#//apple_ref/doc/uid/20001077
Brad Larson