Posts

Post not yet marked as solved
5 Replies
288 Views
Am I calling this right? host_priv_t hostPriv = 0; int err = host_get_host_priv_port(mach_host_self(), &hostPriv); err = host_processors(hostPriv, &processorList, &processorCount); host_get_host_priv_port above returns 4 "(os/kern) invalid argument". Tried with App Sandbox enabled and disabled.
Posted Last updated
.
Post marked as solved
6 Replies
610 Views
Hi, Given pthread_id (†), is there a way to find the associated NSThread (when the one exists)? Perhaps using an undocumented / unsupported method – I don't mind. Thank you! (†) the pthread_id is neither of the current nor of the main thread.
Posted Last updated
.
Post not yet marked as solved
2 Replies
277 Views
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).
Posted Last updated
.
Post not yet marked as solved
4 Replies
365 Views
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"?
Posted Last updated
.
Post marked as solved
3 Replies
291 Views
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.
Posted Last updated
.
Post not yet marked as solved
2 Replies
1.8k Views
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.
Posted Last updated
.
Post not yet marked as solved
3 Replies
1.3k Views
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!
Posted Last updated
.
Post not yet marked as solved
1 Replies
1.5k Views
Tried to ask as a comment in the other thread: https://developer.apple.com/forums/thread/650386?answerId=628394022#reply-to-this-question But can't leave a comment in there for some reason (the thread is locked?). Asking exactly the same question, now for iOS 15. Anything changed in this area? When selecting a stroke path for object on PKCanvas, the option "Snap to Shape" appears. I understand this function is still in beta and has not made available natively to other PencilKit app. Is there a way using Stroke API to call this function directly after the user hold pencil for half a second when stroke is done drawing, just like how it behaves in native apps?
Posted Last updated
.
Post not yet marked as solved
0 Replies
880 Views
In the following simplified app I want to change the status bar color from default black to white (the main iPhone theme is light) but nothing else. I'm partly succeeded doing so, but the theme of keyboard is wrong: when it is first appeared it is good (light) and as soon as i start typing it changes itself to unwanted dark. Is there a way to change just the status bar color but nothing else? Note that I want the status bar color be dynamic - sometimes white, sometimes black depending upon what the app is doing. import SwiftUI struct ContentView: View {     @State var string = "Hello, World"     var body: some View {         TextField("EditableText", text: $string)             .font(.largeTitle)             .frame(maxHeight: 1000)             .navigationTitle("Hello, World")             .background(                 Color(red: 1, green: 0.7, blue: 0.7, opacity: 1)             )             .colorScheme(.light) // attempt to "undo" the effect             .preferredColorScheme(.dark)     } } @main struct NavBarTestApp: App {     var body: some Scene {         WindowGroup {             ContentView()         }     } } PS. I don't mind dropping to UIKit for status bar handling if it is not possible to do it in SwiftUI. The rest of app itself is SwiftUI and it is quite big, here I am showing a stripped down version.
Posted Last updated
.
Post marked as solved
4 Replies
785 Views
Given an arbitrary memory address how do I find (in runtime) the nature of memory block it belongs to? For stack addresses I guess there's some "stack start" and "stack end" of the current thread. For other threads' stacks - I guess I'd have to enumerate all threads to get those ranges. I also found that I can use malloc_size and sometimes it gives me correct result (the size if non zero at least), although it doesn't give me the beginning of the block memory address belongs to. For anything else I have no clue at the moment. Ideal method I am looking for: struct MemoryBlock { let type: MemoryBlockType // stack, heap, unmapped, etc let start: UnsafeRawPointer let size: Int let attributes // e.g. red / write } func findMemoryBlock(_ address: UnsafeRawPointer) -> MemoryBlock PS. the language doesn't matter (e.g. can be C) so long as this method works in a swift/obj-c app.
Posted Last updated
.
Post not yet marked as solved
11 Replies
6.5k Views
i have a list like this: id: 1, image: image1, title: title1, badge: 0 id: 2, image: image2, title: title2, badge: 0 id: 3, image: image3, title: title3, badge: 0 ... is my understanding correct that in order to do a smooth "expected" animation when I want to change both the badge of the item and its order i have to manually split this "big" update into two smaller updates (first change then move, or vice versa)? this is somewhat surprising, i would expect a diffable implementation to have a notion of "identity" (in the example above it's "id") and calculate the differences based on that identity plus ite equivalence check rather than just based on the hash/equality check for the whole item.
Posted Last updated
.
Post not yet marked as solved
4 Replies
1.2k Views
is this a bug that NSDateFormatter knows about leap days but not about leap seconds? let f = DateFormatter() f.timeZone = TimeZone(identifier: "UTC") f.dateFormat = "yyyy/MM/dd HH:mm:ss" // last leap year let t1 = f.date(from: "2020/02/29 00:00:00") // 2020-02-29 00:00:00 UTC // last leap second let t2 = f.date(from: "2016/12/31 23:59:60") // nil
Posted Last updated
.