Reputation: 21
When using my app on iOS 13 the manufacturer data has changed format.
When accessing kCBAdvDataManufacturerData in iOS 12 I get in this format:
<13376400>
but in iOS 13 I get this format:
{length = 4, bytes = 0x13376400}
Does anyone know why this has changed?
How can I retrieve the "1337" part as a string?
This is how I access and print the data:
NSData *manufacturerData = [advertisementData objectForKey:kCBAdvDataManufacturerData];
NSString *manufacturerString = [NSString stringWithFormat:@"%@", manufacturerData];
NSString *companyIdentifier = [manufacturerString substringWithRange:NSMakeRange(1, 4)];
NSLog(@"%@", companyIdentifier);
Prints: leng
I tried manufacturerData.bytes but it gives me EXC_BAD_ACCESS error.
Upvotes: 1
Views: 1069
Reputation: 1706
Since iOS 13, the description of the kCBAdvDataManufacturerData
NSData
has been changed.
To be able to extract and parse the advertisementData
you should not base on description
any more.
Following is a Swift solution version that is working on both iOS 13 and old iOS versions:
According to your code above, you are able to extract the manufacturerData NSData
.
let publicData = Data(bytes: manufacturerData.bytes, count: Int(manufacturerData.length))
let publicDataAsHexString = publicData.dataToHexString // this result is same what ever the iOS version.
//// Data extension
extension Data {
var dataToHexString: String {
return reduce("") {$0 + String(format: "%02x", $1)}
}
}
Upvotes: 3