Getting list of bluetooth devices nearby on iphone sdk

牧云@^-^@ 提交于 2020-01-06 03:33:26

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/2270418/getting-list-of-bluetooth-devices-nearby-on-iphone-sdk

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!