Android Code
AdvertiseSettings settings = new AdvertiseSettings.Builder()
.setAdvertiseMode( AdvertiseSettings.ADVERTISE_MODE_LOW_LATENCY )
.setConnectable( true )
.build();
//UUID to differentiate from other apps advertising
ParcelUuid pUuid = new ParcelUuid( UUID.fromString( getString( R.string.ble_test ) ) );
//converting our random number into byte array
ByteBuffer b = ByteBuffer.allocate(4);
b.putInt(num);
byte[] chunk= b.array();
int res=ByteBuffer.wrap(chunk).getInt();
d(TAG,"DATA to be sent:"+res);
//Building data which will be advertising and manufacturer id at which data is received
AdvertiseData data = new AdvertiseData.Builder()
.setIncludeDeviceName(false)
.setIncludeTxPowerLevel(false)
.addServiceUuid(pUuid)
.addManufacturerData(1, chunk)
.build();
//callback for advertising
AdvertiseCallback callback=new AdvertiseCallback() {
@Override
public void onStartSuccess(AdvertiseSettings settingsInEffect) {
super.onStartSuccess(settingsInEffect);
d(TAG,"Advertising onSuccess");
Toast.makeText(MainActivity.this,"Advertising Success",Toast.LENGTH_LONG).show();
d(TAG,settingsInEffect.toString());
isadvertising=true;
}
IOS Code
func centralManager(_ central: CBCentralManager, didDiscover peripheral: CBPeripheral, advertisementData: [String : Any], rssi RSSI: NSNumber) {
pheripheralFound = peripheral
central.stopScan()
print(RSSI)
print(advertisementData)
print(advertisementData["kCBAdvDataManufacturerData"]!)
let input = "0x0100c8360000"
let data = input.data(using: .utf8)
let manufacturerId:Range<Int> = 8..<14
let subdata1 = data?.subdata(in: manufacturerId)
let str1 = String(data: subdata1!, encoding:.utf8)
print(str1!)
print(peripheral.identifier)
}
so I am advertising a data for example 83284312 and then I am converting into byte array and advertising from and android device but when I am trying to decode on iOS its showing wrong as "36000" example or sometimes "xftess"