Explore the core architecture of the operating system, including the kernel, memory management, and process scheduling.

Posts under Core OS subtopic

Post

Replies

Boosts

Views

Activity

Does peripheralManager.updateValue Actually Send Data to the Central?
https://developer.apple.com/documentation/corebluetooth/cbperipheralmanager/updatevalue(_:for:onsubscribedcentrals:) I want to record the timestamp when an iOS peripheral sends data to a central device. Here’s what I did: let startDate = Date() if peripheralManager.updateValue(packet, for: characteristic, onSubscribedCentrals: nil) { let sentTime = Date().timeIntervalSince(startDate) } However, the recorded time is nearly 0.1 ms. If I send 244 bytes per update, this suggests a throughput of 2.44 MB/s, which seems too high. Did I make a mistake, or is updateValue() not actually sending the data at that moment?
1
0
23
1d
BLE scan response persists after advertisements stop
I'm experimenting with advertising packets using Core Bluetooth on iOS as a Peripheral. I'm using an iPhone 13 mini as my test device. I've found that if I set a 128-bit CBAdvertisementDataServiceUUIDsKey, and a 8 byte CBAdvertisementDataLocalNameKey and call CBPeripheralManager::startAdvertising() I can see both data elements in a advertising report of type "legacy advertising indication", when scanning from another device. But if I add one or more extra bytes, the "Local Name" field is no longer in the same report. Instead, it is moved to the scan response. This is good, but a funky thing happens when I stop advertising. The legacy advertising indication becomes empty, however, the scan response, with the same data, continues to appear in every scan by the other device! I've tried calling stopAdvertising(), ending the debug session, closing the app, and force quitting (slide up from app choser), The only thing that seems to stop them is turning off Bluetooth in Settings. Is this normal behaviour?
2
0
24
3d
How can I trigger the Full Disk Access prompt to write to a raw block device?
I want to write a disk image (ISO, img) to an SD card, but I always get permission errno 13 (permission denied). let diskPath = "/dev/rdisk99" guard let diskHandle = FileHandle(forWritingAtPath: diskPath) else { throw NSError(domain: "DiskWriter", code: Int(errno), userInfo: [NSLocalizedDescriptionKey: "errno \(errno)"]) } It seems that when other macOS applications try to read from a raw block device it triggers an Access Removable Media prompt and when other applications try to write to a raw block device it triggers a Full Disk Access prompt. How can I trigger that prompt? And then how do I elevate my write to use that permission? P.S. I'm not a Swift coder, but I'd like to be... if it weren't that every "simple" thing I've tried launches me directly into a brick wall. :slight_smile: (not a criticism, just that the kinds of problems I like to solve tend towards uncommon and not as well supported in the ecosystem) What I've tried I did change Sandbox App to NO in MyApp.entitlements I have tried manually adding my Debug Archive to Full Disk Access Why? As to why I'm I interested in this: Well, it just seems silly that UI tools that do what dd does are hundreds of megabytes. Can't we do this in a UI that uses all the default macOS libraries and is just a few kilobytes (or megabytes at worst)?
2
0
31
3d
Increased Memory Limit, Extended Virtual Addressing affects on recent iPadOS 18.3
Hello Apple Forum, We were testing out the following entitlements: 'Increased Memory Limit', 'Extended Virtual Addressing', 'Extended Virtual Addressing(Debug)' when we realized the maximum allocation amount of the memory dropped from our previous test of 32GB to 16GB. We were testing these on the following devices: iPad Pro 12.9(6th Gen) 18.4(Beta, 22E4232a) iPad Pro 11 M4 18.3.2 Each device has 16GB of physical RAM and because we are able to reach 16GB of allocation usage until app crashes, we believe the entitlements are applied correctly. Each test device was on charging mode and battery mode with 60, 80 100% battery. We understand allocating memory is complex and os is more optimized for battery efficiency, hence possibly limiting max usage of memory. However, through the same testing method we have done on iPadOS 18.3 and 4, we were able to allocate 31~32GB of RAM on testing done on January this year. (iPadOS 18.0, or maybe 18.1?) which make us wonder, has there been a change in core os that handles memory allocation since 18.0? And what can be the cause of this drop? The code we ran for our memory testing is as follows: private var allocatedMemory: [UnsafeMutableRawPointer] = [] public func allocate1GBMemory() { let sizeInBytes = 1024 * 1024 * 1024 if let pointer = malloc(sizeInBytes) { for i in 0..<sizeInBytes { pointer.advanced(by: i).storeBytes(of: UInt8(i % 256), as: UInt8.self) } allocatedMemory.append(pointer) logger.print("Allocated 1GB of memory. Total allocated: \(allocatedMemory.count)GB") } else { logger.print("Failed to allocate memory") } } Each functions call increases memory usage by allocating 1GB of space and we have called this function until it reaches 16GB then the app crashes.
6
0
86
5d
CoreBluetooth and Swift strict concurrency checking
As of iOS 18.3 SDK, Core Bluetooth is still mostly an Objective-C framework: key objects like CBPeripheral inherit from NSObjectProtocol and does not conform to Sendable. CBCentralManager has a convenience initializer that allows the caller to provide a dispatch_queue for delegate callbacks. I want my Swift package that implements Core Bluetooth to conform to Swift 6 strict concurrency checking. It is unsafe to dispatch the delegate events onto my own actor, as the passed in objects are presumably not thread-safe. What is the recommended concurrency safe way to implement Core Bluetooth in Swift 6 with strict concurrency checking enabled?
0
0
54
6d
The host app appears in Accessibility Permission
I'm learning XPC by inspecting the GitHub Copilot project. I figured out that the schema works as follows: The host app with a UI to manage settings A Service Extension that controls the Xcode Editor A communication bridge cli app that connects the first two As far as I understand an app appears in the Accessibility Permission when it calls the next method: let key = kAXTrustedCheckOptionPrompt.takeRetainedValue() as NSString AXIsProcessTrustedWithOptions([key: true] as CFDictionary) This method is only called by the Service Extension. However, when I run a release build from the /Application folder (where launch agents point to), there are two records appearing in the Accessibility Permission list: The host app The needed Service Extension I compared all metadata files from Copilot with my copy line-by-line, but still can't figure out why the host app record appears in the Accessibility Permission, since the host app does not call the AXIsProcessTrustedWithOptions() method at all. Could you give me any clue to help me wrap my head around it?
2
0
25
1w
Inquiry on Implementing Energy Monitoring for iOS Apps and Calculating Energy Impact
I am reaching out to inquire about the implementation of an energy monitoring solution similar to Xcode's Energy Impact tool for iOS apps. Specifically, I would like to understand the following aspects to address issues like overheating and rapid battery drain: How can we achieve monitoring and calculation of CPU, GPU, and network usage over a period of time within an app? How is the current energy consumption level of an app determined? Additionally, how are the weights for various factors like CPU, GPU, network, and location usage allocated when calculating the overall energy impact? Any guidance or resources you could provide regarding these questions would be greatly appreciated. Thank you for your assistance.
2
0
31
1w
Inquiry on Implementing Energy Monitoring for iOS Apps and Calculating Energy Impact
Dear Apple Support Team, I am reaching out to inquire about the implementation of an energy monitoring solution similar to Xcode's Energy Impact tool for iOS apps. Specifically, I would like to understand the following aspects to address issues like overheating and rapid battery drain: How can we achieve monitoring and calculation of CPU, GPU, and network usage over a period of time within an app? How is the current energy consumption level of an app determined? Additionally, how are the weights for various factors like CPU, GPU, network, and location usage allocated when calculating the overall energy impact? Any guidance or resources you could provide regarding these questions would be greatly appreciated. Thank you for your assistance.
2
0
24
1w
File Provider Extension Conflict Resolution
Hi all, i am trying to implement File Provider Extension. I have some questions about conflict resolution Same file is changed at user local and remote storage before it's synced. File has 2 different version at user local and remote storage. After trigger a new enumeration by calling signalEnumerator for the extension, I want to move user's local version to new conflicted copy (with new itemIdentifier: NSFileProviderItemIdentifier) and import remote storage version to user local (with current itemIdentifier: NSFileProviderItemIdentifier). Then users local version should uploaded to remote storage server with new conflicted copy name Any suggestion about this scenario? Or any documentation about conflict resolution
1
0
92
1w
Technical Inquiry about CoreBluetooth Scanning
Issue: We noticed inconsistent BLE device discovery times (ranging from 0.5s to 1.5s) despite the peripheral advertising at 2Hz (500ms interval). Questions: Does iOS regulate the BLE scan interval or duty cycle internally? If yes, what factors affect this behavior (e.g., foreground/background state, connected devices)? Are there recommended practices to reduce discovery latency for peripherals with fixed advertising intervals? Is there a way to configure scan parameters (e.g., scan window/interval) programmatically, similar to Android's BluetoothLeScanner? Test Context: Device: iPhone 13 mini (iOS 17.6.1) Code: CBCentralManager.scanForPeripherals(withServices: nil, options: [CBCentralManagerScanOptionAllowDuplicatesKey: true])
0
0
77
1w
synchronize a file's state with that on disk
Hello Dev, The App, which I am working on, uses fcopyfile() to copy file from external storage (USB, thunderbolt) to internal disk. Looks like this call provides the best performance. fcopyfile(from, to, nullptr, COPYFILE_DATA); I need to be sure the data is copied after the call. Are there any necessity to synchronize a file's state with that on disk the data? (e.g. call fsync()) Thank you in advance! Pavel
2
0
127
1w
NSFileProviderPartialContentFetching on iOS
We're experimenting with FileProvider on MacOS and iOS. One of our requirements is to support downloading partial content of files. However, this looks to be supported only on MacOS as per https://developer.apple.com/documentation/fileprovider/nsfileproviderpartialcontentfetching?language=objc. Is there an alternative for NSFileProviderPartialContentFetching on iOS? If not, can you please share any standard practice on how to accomplish this on iOS? Sample code that works on MacOS - #import &lt;FileProvider/FileProvider.h&gt; @interface FileProviderExtension : NSObject&lt;NSFileProviderReplicatedExtension, NSFileProviderPartialContentFetching&gt; For iOS platform, NSFileProviderPartialContentFetching isn't available and build fails.
1
0
82
1w
Force background suspension
Hi all, I've been trying to test the suspension -> resume behaviour of our app, on iPad (iPadOS 18.3.1), however I'm unable to reliably get the application into a suspended state. Things I've read that do not work reliably: Backgrounding the application and waiting ~1 minute Backgrounding the application and opening a bunch of other applications Sometimes it will work consistently, then other times I can be waiting for 30 minutes or more and it still won't suspend. If it matters - I'm launching the app via xcode & it's also a capacitor app with a web sockets connection. Is there any way to reliably suspend an app? Thanks
3
0
144
1w
Can an iOS app programmatically detect if it's built for release or debug?
Is it possible for an iOS app to programmatically detect if its built for TestFlight/App Store distribution versus built for development? The motivation for doing this is so that the app can detect if a push server should send pushes using the Apple production server or the sandbox server - when the app sends the push token to the server, I'd like it to additionally send an indicator to the server so the server knows which of the Apple servers to use. Is there a way to achieve this? TIA
3
0
173
1w
NSFileProviderReplicatedExtension does not work in Shared iPad setup
Can be reproduced with a shared iPad setup (https://support.apple.com/de-de/guide/deployment/dep9a34c2ba2/web) and the example app provided by Apple (https://developer.apple.com/documentation/fileprovider/synchronizing-files-using-file-provider-extensions). The issue is that when using the File Provider extension implemented with 'NSFileProviderReplicatedExtension', the content of the share does not display in the iPadOS Files app. The 'NSFileProviderEnumerating.enumerator' function is invoked, but none of the functions of the returned 'NSFileProviderEnumerator' are executed: neither 'currentSyncAnchor', 'enumerateChanges', nor 'enumerateItems'. Instead, the 'NSFileProviderEnumerator' is immediately invalidated. This issue can be reproduced with iPadOS 18.3 and a shared iPad setup. Maybe i missing some additional steps/ settings in my extension to work properly on Shared iPads. Created also a post on the feedbackassistent: FB16587660 (NSFileProviderReplicatedExtension does not work in Shared iPad setup) Steps to reproduce: iPad with a Shared iPad profile Enroll the iPad and log in as a Guest user Turn on developer mode Install the example app from Apple (as mentioned above) Add some test files to the FruitBasket storage Add this FruitBasket domain to the FruitBasket-iOS app You may need to provide "Privacy - Local Network Usage Description" in the Info.plist of the FruitBasket-iOS example app to be able to find local FruitBasket storage. Check in the Files app to see that the FruitBasket share is empty -> The expected behavior is that the FruitBasket share should contain the test files added previously. (This works fine without a shared iPad setup).
0
0
80
1w
NSPOSIXErrorDomain code 12 while downloading a folder having sub directories and large number of files
Hi, I have a file provider based MacOS application where i have a drive added and am trying to download a folder from that drive. The folder has sub folders and large files in it. After some time of download started, i keep getting below error. error: ["The operation could not be completed. Cannot allocate memory", [code: 12, domain: "NSPOSIXErrorDomain"] The download action is triggered via Finder's download icon(cloud icon with down arrow). I am using native URLSession to download the files from server. No third party library is used. What could be the possible reasons for "can not allocate memory" issue?
4
0
274
1w