ios6 - iOS 6 peripheral disconnect immediately after connected -
ok, i'm using core bluetooth connect i-pad ble sensor. scan , detect when want establish connection, "did connect peripheral" method called during 30 sec if i've called disconnection... , result stay same select or deselect "app communicates using corebluetooth" in required background mode.
- (id) init { self = [super init]; if (self) { pendinginit = yes; centralmanager = [[cbcentralmanager alloc] initwithdelegate:self queue:dispatch_get_main_queue()]; foundperipherals = [[nsmutablearray alloc] init]; connectedservices = [[nsmutablearray alloc] init]; } return self; } - (void) centralmanagerdidupdatestate:(cbcentralmanager *)central { static cbcentralmanagerstate previousstate = -1; switch ([centralmanager state]) { case cbcentralmanagerstateunsupported: { nslog(@"nscentralmanager state unsupported..."); break; } case cbcentralmanagerstatepoweredoff: { nslog(@"nscentralmanager state powered off"); [self cleardevices]; [discoverperipheraldelegate discoverydidrefresh]; if (previousstate != -1) { [discoverperipheraldelegate discoverystatepoweredoff]; } break; } case cbcentralmanagerstateunauthorized: { nslog(@"nscentralmanager state unauthorized: application not allowed"); break; } case cbcentralmanagerstateunknown: { nslog(@"nscentralmanager state unknown... bad news..."); break; } case cbcentralmanagerstatepoweredon: { nslog(@"nscentralmanager state powered on!"); pendinginit = no; [self loadsaveddevices]; [centralmanager retrieveconnectedperipherals]; [discoverperipheraldelegate discoverydidrefresh]; break; } case cbcentralmanagerstateresetting: { nslog(@"cbcentralmanager state resetting"); [self cleardevices]; [discoverperipheraldelegate discoverydidrefresh]; [peripheraldelegate alarmservicedidreset]; pendinginit = yes; break; } } previousstate = [centralmanager state]; } - (void) loadsaveddevices { storeddevices = [[nsarray alloc] initwithobjects:kpressureserviceuuidstring, nil]; (id deviceuuidstring in storeddevices) { if (![deviceuuidstring iskindofclass:[nsstring class]]) continue; cfuuidref uuid = cfuuidcreatefromstring(null, (cfstringref)deviceuuidstring); if (!uuid) continue; storeduuids = [[nsmutablearray alloc] initwitharray:[[nsuserdefaults standarduserdefaults] objectforkey:@"storeduuids"]]; (int = 0; < storeduuids.count; i++) { nsarray * tempstoreduuids = storeduuids[i]; storeduuids[i] = [tempstoreduuids mutablecopy]; } [centralmanager scanforperipheralswithservices:nil options:nil]; storeduuids = [[nsmutablearray alloc] init]; [[nsuserdefaults standarduserdefaults] setobject:storeduuids forkey:@"storeduuids"]; } } - (void)centralmanager:(cbcentralmanager *)central diddiscoverperipheral:(cbperipheral *)peripheral advertisementdata:(nsdictionary *)advertisementdata rssi:(nsnumber *)rssi { nsstring * finaluuids = [nsstring stringwithformat:@"%@",peripheral.uuid]; if (storeduuids.count == 0) { storeduuids = [[nsmutablearray alloc] initwithobjects:finaluuids, nil]; [centralmanager stopscan]; [centralmanager connectperipheral:peripheral options:nil]; } } - (void) centralmanager:(cbcentralmanager *)central didconnectperipheral:(cbperipheral *)peripheral { nslog(@"connected"); }
here console. don't have warning, error or deallocating just:
2013-05-14 09:21:14.925 pressure[262:907] connected 2013-05-14 09:21:14.927 pressure[262:907] service (sensor) connected 2013-05-14 09:21:44.994 pressure[262:907] service (sensor) disconnected
how can avoid peripheral disconnected after connection please? drives me crazy!
you have [peripheral retain] on diddiscoverperipheral or put retain property. released right after connect ble framework.
Comments
Post a Comment