objective c - iOS Bluetooth Dilemma. CoreLocation vs. CoreBluetooth -
i'm creating ios app triggers server call whenever come bluetooth proximity of iphone running app. each ios device should have unique bluetooth advertisement identifier (e.g major/minor combo) appropriate server/db call can made.
my first plan use standard ibeacon api (corebluetooth + corelocation). worked charm hit standstill when realized can't advertise bluetooth while app in background using method.
method 1 //create nsuuid object nsuuid *uuid = [[nsuuid alloc] initwithuuidstring:@"6ca7d72e-824e-45d1-99e9-02bd33599a81"]; //initialize beacon region self.mybeaconregion = [[clbeaconregion alloc] initwithproximityuuid:uuid major:1 minor:1 identifier:@"com.emjoseph.test"]; //get beacon data advertise self.mybeacondata = [self.mybeaconregion peripheraldatawithmeasuredpower:nil]; //start peripheral manager self.peripheralmanager = [[cbperipheralmanager alloc] initwithdelegate:self queue:nil options:nil]; -(void)peripheralmanagerdidupdatestate:(cbperipheralmanager *)peripheral{ if(peripheral.state == cbperipheralmanagerstatepoweredon){ //bluetooth on - start broadcasting [self.peripheralmanager startadvertising:self.mybeacondata]; }
}
my second attempt using instrument/vicinity api set bentford on github replicates ibeacon api solely using corebluetooth. solved issue of being able advertise in background. problem though couldn't figure out how send equivalent of major or minor in bluetooth advertisement data , limiting because receiving phone needs unique identifier of device received data can make appropriate server/db call. seems have access uuid , name property in advertisement data.
method 2 nsdictionary *advertisingdata = @{cbadvertisementdatalocalnamekey:@"emjoseph", cbadvertisementdataserviceuuidskey:@[cbuuid], }; // start advertising on ble [peripheralmanager startadvertising:advertisingdata];
any hunches on how can achieve desired setup? thought using method 2's cbadvertisementdatalocalnamekey property string unique id, has limits.
also i'd users of app on same uuid filter out unwanted signals.
to reiterate once more, basic flow of app is: when person gets close person b's phone, person receives unique id person b via bluetooth (e.g major/minor combo) , person uses unique id retrieve relevant information db/server. stipulation i'd process happen when app running in background well.
Comments
Post a Comment