ios - Iphone detecting bluetooth devices -
i doing iphone app , need nearby bluetooth devices. i'm using corebluetooth framework , doesn't work. know framework low energy bluetooth, bought bluetooth 4.0 usb adapter support low-energy. i'm testing app in iphone 5. code
- (void)centralmanagerdidupdatestate:(cbcentralmanager *)central{ nsstring *messtoshow; switch (central.state) { case cbcentralmanagerstateunknown: { messtoshow=[nsstring stringwithformat:@"state unknown, update imminent."]; break; } case cbcentralmanagerstateresetting: { messtoshow=[nsstring stringwithformat:@"the connection system service momentarily lost, update imminent."]; break; } case cbcentralmanagerstateunsupported: { messtoshow=[nsstring stringwithformat:@"the platform doesn't support bluetooth low energy"]; break; } case cbcentralmanagerstateunauthorized: { messtoshow=[nsstring stringwithformat:@"the app not authorized use bluetooth low energy"]; break; } case cbcentralmanagerstatepoweredoff: { messtoshow=[nsstring stringwithformat:@"bluetooth powered off."]; break; } case cbcentralmanagerstatepoweredon: { messtoshow=[nsstring stringwithformat:@"bluetooth powered on , available use."]; [mgr scanforperipheralswithservices:[nsarray arraywithobject:[cbuuid uuidwithstring:@"180a"]] options:[nsdictionary dictionarywithobject:[nsnumber numberwithbool:no] forkey:cbcentralmanagerscanoptionallowduplicateskey]]; [mgr retrieveconnectedperipherals]; break; } } nslog(messtoshow); } - (void)centralmanager:(cbcentralmanager *)central diddiscoverperipheral: (cbperipheral *)peripheral advertisementdata:(nsdictionary *)advertisementdata rssi:(nsnumber *)rssi { nslog(@"did discover peripheral. peripheral: %@ rssi: %@, uuid: %@ advertisementdata: %@ ", peripheral, rssi, peripheral.uuid, advertisementdata); [mgr retrieveperipherals:[nsarray arraywithobject:(id)peripheral.uuid]]; } -(void)centralmanager:(cbcentralmanager *)central didretrieveperipherals:(nsarray *)peripherals{ nslog(@"this it!"); }
this print "bluetooth powered on , available use.", doesn't find usb bluetooth or other nearby bluetooth device. need solution this, im getting crazy. thank much.
are sure 180a right service?
if not try:
[mgr scanforperipheralswithservices:nil options:[nsdictionary dictionarywithobject:[nsnumber numberwithbool:no] forkey:cbcentralmanagerscanoptionallowduplicateskey]];
Comments
Post a Comment