Using CoreBluetooth I am getting these values from CBCentralManagerDelegate's didDiscover peripheral delegate method:
kCBAdvDataTxPowerLevel: 12 (could be other number like 7, 0 or a small negative number)
This one is taken from advertisementData parameter. This key might be absent.
rssi: -68 (or -60, -100, etc)
this is taken from the "rssi" parameter (always present).
I am looking for a formula to calculate approximate distance based on these two numbers. Is that possible?
I know that ideally I need to know rssi0 (rssi at 1 meter), but I don't see how I can get that via CoreBluetooth API or other means (without actually measuring rssi at one meter distance which is not good for me). How could I approximate rssi0 value with "kCBAdvDataTxPowerLevel"?
Selecting any option will automatically load the page
Post
Replies
Boosts
Views
Activity
While playing with this app I found something odd:
let dylib1 = dlopen("/System/Library/Frameworks/CreateMLComponents.framework/CreateMLComponents", O_RDONLY)!
let s1 = dlsym(dylib1, "CreateMLComponentsVersionString")!
var info1 = Dl_info()
let success1 = dladdr(s1, &info1)
precondition(success1 != 0)
print(String(cString: info1.dli_sname!)) // CreateMLComponentsVersionString
let path1 = String(cString: info1.dli_fname!)
print(path1) // /System/Library/Frameworks/CreateMLComponents.framework/Versions/A/CreateMLComponents
let exists1 = FileManager.default.fileExists(atPath: path1)
print(exists1) // true
let dylib2 = dlopen("/System/Library/Frameworks/Foundation.framework/Foundation", O_RDONLY)!
let s2 = dlsym(dylib2, "NSAllocateMemoryPages")! //
var info2 = Dl_info()
let success2 = dladdr(s2, &info2)
precondition(success2 != 0)
print(String(cString: info2.dli_sname!)) // NSAllocateMemoryPages
let path2 = String(cString: info2.dli_fname!)
print(path2) // /System/Library/Frameworks/Foundation.framework/Versions/C/Foundation
let exists2 = FileManager.default.fileExists(atPath: path2)
print(exists2) // false
The app runs fine and prints true for exists1 and false for exists2. That means that while both dlsym calls succeed and both dladdr calls return paths (within CreateMLComponents.framework and Foundation.framework correspondingly) the first file exists while the second file doesn't exist.
This raises quite a few questions:
Why some of the dylib files (in fact – most dylibs inside /System/Library/Frameworks hirerarchy) don't exist at the expected locations?
Why do we have symbolic link files (like Foundation.framework/Foundation) that point to those non-existent locations? What is the purpose of those symbols links?
Where are those missing dylib files in fact? They must be somewhere, no?! I guess to figure out the answer I could search the whole disk raw bytes for a particular byte pattern to know the answer but hope there's an easier way to know the truth!
Why do we have some exceptional cases like "CreateMLComponents.framework" and a couple of others that don't follow the rules established by the rest?
Thanks!
how do i make TextEditor autoscrolled? i want to implement a log view based on it - when the scroll position is at bottom, adding new lines shall autoscroll it upwards so the newly added lines are visible. and when the scroll position is not at bottom - adding new lines shall not autoscroll it.
Is it possible to use network from within iOS Thumbnail Extension?
I tried - it works fine under simulator, but I'm getting this error when running on real device:
networkd_settings_read_from_file Sandbox is preventing this process from reading networkd settings file at "/Library/Preferences/com.apple.networkd.plist", please add an exception.
Adding "App Transport Security Settings / Allow Arbitrary Loads" plist entry didn't help. As the error seems to be specific access to a particular file I tried adding "com.apple.security.temporary-exception.files.absolute-path.read-only" but it didn't help and looks like it couldn't help on iOS: "Note: This chapter describes property list keys specific to the macOS implementation of App Sandbox. They are not available in iOS."
Topic:
App & System Services
SubTopic:
General
Tags:
Extensions
QuickLook Thumbnailing
App Sandbox
Network
I am struggling to see why the following low-level audio recording function - which is based on tn2091 - Device input using the HAL Output Audio Unit - (a great article, btw, although a bit dated, and it would be wonderful if it was updated to use Swift and non deprecated stuff at some point!) fails to work under macOS:
func createMicUnit() -> AUAudioUnit {
let compDesc = AudioComponentDescription(
componentType: kAudioUnitType_Output,
componentSubType: kAudioUnitSubType_HALOutput, // I am on macOS, os this is good
componentManufacturer: kAudioUnitManufacturer_Apple,
componentFlags: 0, componentFlagsMask: 0)
return try! AUAudioUnit(componentDescription: compDesc, options: [])
}
func startMic() {
// mic permision is already granted at this point, but let's check
let status = AVCaptureDevice.authorizationStatus(for: AVMediaType.audio)
precondition(status == .authorized) // yes, all good
let unit = createMicUnit()
unit.isInputEnabled = true
unit.isOutputEnabled = false
precondition(!unit.canPerformInput) // can't record yet, and know why?
print(deviceName(unit.deviceID)) // "MacBook Pro Speakers" - this is why
let micDeviceID = defaultInputDeviceID
print(deviceName(micDeviceID)) // "MacBook Pro Microphone" - this is better
try! unit.setDeviceID(micDeviceID) // let's switch device to mic
precondition(unit.canPerformInput) // now we can record
print("\(String(describing: unit.channelMap))") // channel map is "nil" by default
unit.channelMap = [0] // not sure if this helps or not
let sampleRate = deviceActualFrameRate(micDeviceID)
print(sampleRate) // 48000.0
let format = AVAudioFormat(
commonFormat: .pcmFormatFloat32, sampleRate: sampleRate,
channels: 1, interleaved: false)!
try! unit.outputBusses[1].setFormat(format)
unit.inputHandler = { flags, timeStamp, frameCount, bus in
fatalError("never gets here") // now the weird part - this is never called!
}
try! unit.allocateRenderResources()
try! unit.startHardware() // let's go!
print("mic should be working now... why it doesn't?")
// from now on the (UI) app continues its normal run loop
}
All sanity checks pass with flying colors but unit's inputHandler is not being called. Any idea why?
Thank you!
Where's CBAdvDataManufacturerData format documented?
It looks like there's the company code stored in little endian order in the first two bytes (referencing the companies found in company_identifiers.yaml on bluetooth site). And the rest is arbitrary?
I'd like to see the official documentation about this.
Thank you.
How do I download a folder from opensource.apple.com without going inside recursively and downloading individual files?
e.g. one from here: "https://opensource.apple.com/source/Libm/"
PS. no idea what's the proper tag for this post, and as forum insists on having a non-empty tag field I'm using "Foundation" arbitrarily.
Posting this on behalf of my colleague, who has a project in mind that requires a huge amount of RAM. Is it true that modern Mac Pro's can only have up to 192GB of RAM which is about 8 times less than 5 years old intel based Mac Pros?
I'm getting "unsatisfied (Local network prohibited)" when trying accessing my local http server running on mac (http://192.168.0.12:8000/test.txt) from an app running on iPhone with iOS 18.4. That's using URLSession, nothing fancy.
This is the contents of the plist file of the app:
NSAppTransportSecurity
NSExceptionAllowsInsecureHTTPLoads true
NSAllowsArbitraryLoads true
NSAllowsLocalNetworking true
NSExceptionDomains
192.168.0.12
NSIncludesSubdomains true
NSAllowsLocalNetworking true
NSExceptionAllowsInsecureHTTPLoads true
NSLocalNetworkUsageDescription Hello
The app correctly "prompts" the alert on the first app run, asking if I want to access local network, to which I say yes. Afterwards I could see that Local Network is enabled in iOS settings for the app, yet getting those "Local network prohibited" errors.
From testing other global IP + 'http only" sites it feels like NSAllowsArbitraryLoads no longer works as it used to work before. But specifying other test "global" HTTP-only IP addresses in NSExceptionDomains work alright, it's just the local address doesn't.
I could access that IP from iOS safari with no problem. The local web site is HTTP only.
Googling reveals tons of relevant hits including FAQ articles from Quinn, but whatever I tried so far based on those hits doesn't seem to work.
Topic:
App & System Services
SubTopic:
Networking
I'm experiencing some rare crash but only if I enable Xcode's "thread performance checker". The crash typically ends with these lines:
std::_1::hash_table<std::_1::hash_value_type<long
qosWaiterSignallerInvariantCheck
...
and sometimes with "findPrimitiveInfoNoAssert" on the second line.
I wonder if I am doing anything wrong, or is it a (hopefully known) issue in thread performance checker itself? It does look like some sort of data race bug, if to guess there's some internal dictionary that's not properly protected with a mutex or something.
I'm using Xcode 16.4 running on macOS 15.5, building and running an app on iPhone with iOS 18.5.
Cheers!
i thought it is impossible to have CallKit show system UI for outgoing calls. but then i saw this:
"For incoming and outgoing calls, CallKit displays the same interfaces as the Phone app..."
https://developer.apple.com/documentation/callkit
how do i present it though? or is this a documentation error?
Our app has "allow arbitrary loads" in the "App Transport Security Settings" and generally allows both "http" and "https" connections. I want to restrict basic authentication usage to secure connections only, what is the best way to do that?
I have URLSessionTaskDelegate's:
func urlSession(_ session: URLSession, task: URLSessionTask, didReceive challenge: URLAuthenticationChallenge, completionHandler: @escaping (URLSession.AuthChallengeDisposition, URLCredential?) -> Void) {
where I can put the relevant logic, but how do I check if the connection attempt in question is happening over TLS or not? I can check task.currentRequest.url scheme being "http" vs "https", and port being nil vs 80 vs 443, but I hope there is a more robust check.
Hi, is it possible to have the SwiftUI's NavigationView set to show both panels side by side in landscape mode on iPhone Plus/Max sized devices? Similar to how Messages.app does it. Thank you.
When calling CBCentralManager's connectPeripheral:options: with some Bluetooth devices I'm getting the "Bluetooth Pairing Request" alert on iOS and a similar "Connection Request from:" alert on macOS. Is there a way to determine upfront if the alert is going to be presented or not? Alternatively is there a way to prohibit presenting this alert (in which case the connect request could fail, which is totally fine)? I tried specifying these options:
var manager: CBCentralManager
...
manager.connect(
peripheral,
options: [
CBConnectPeripheralOptionNotifyOnConnectionKey: false,
CBConnectPeripheralOptionNotifyOnDisconnectionKey: false,
CBConnectPeripheralOptionNotifyOnNotificationKey: false
]
)
but those didn't help (and by the doc they shouldn't help as they relate to the use case of app running in background, which is not applicable in my case – my app runs and calls connect when it is in foreground, the unwanted alert is displayed immediately).
I'm creating a simple p2p server to advertise a service:
// server
let txtRecord = NWTXTRecord(["key": "value"])
NWListener.Service(name: name, type: "_p2p._tcp", domain: nil, txtRecord: txtRecord)
and client to look that service up:
// client
switch result.endpoint {
case let .service(name: name, type: type, domain: domain, interface: interface):
print(result.metadata)
The client is getting the advertisement ok, but metadata is nil. I expected to see a txt record there, is that not supported?
public let metadata: NWBrowser.Result.Metadata
/// Additional metadata provided to the browser by a service. Currently,
/// only Bonjour TXT records are supported.
Is the above server making a Bonjour TXT record or something else?
Basically what I want is to pass a short key/value data as part of advertisement.