I am trying to use ScreenCaptureKit to select this window automatically rather than having the user do it.
Delve into the world of built-in app and system services available to developers. Discuss leveraging these services to enhance your app's functionality and user experience.
Selecting any option will automatically load the page
Post
Replies
Boosts
Views
Activity
I am writing to address a concern regarding the background permission functionality in my app, which is critical for ensuring user safety as they navigate various terrains. This feature also enables users to smoothly record their navigation tracks for review after their activities. Recently, I've noticed that this functionality is not working as seamlessly as before.
Additionally, I observed that the app is not categorized under 'health and fitness'—could reclassifying it improve background activity? Before I delve into a detailed code review, I wanted to check if this issue might be related to sync or settings on the App Store side, such as permission configurations, app updates, or other related factors. Or, is it more likely an issue stemming from the app’s codebase?
Topic:
App & System Services
SubTopic:
Maps & Location
Tags:
Maps Web Snapshots
Health and Fitness
Core Location
Background Tasks
I have a very cheap Bluetooth-connected printer. And I want to print out a word or two via Core Bluetooth. It's an iOS app with the SwiftUI framework. The following is what I have for an ObservableObject class.
import Foundation
import CoreBluetooth
class BluetoothManager: NSObject, ObservableObject, CBCentralManagerDelegate, CBPeripheralDelegate {
@Published var connectedDevices: [CBPeripheral] = []
@Published var powerOn = false
@Published var peripheralConnected = false
private var centralManager: CBCentralManager!
private var peripheralName = "LX-D02"
private var connectedPeripheral: CBPeripheral?
private var writeCharacteristic: CBCharacteristic?
private let serviceUUID = CBUUID(string:"5833FF01-9B8B-5191-6142-22A4536EF123")
private let characteristicUUID = CBUUID(string: "FFE1")
override init() {
super.init()
self.centralManager = CBCentralManager(delegate: self, queue: nil)
}
func startScanning() {
if centralManager.state == .poweredOn {
centralManager.scanForPeripherals(withServices: nil, options: nil)
}
}
func centralManagerDidUpdateState(_ central: CBCentralManager) {
if central.state == .poweredOn {
powerOn = true
print("Bluetooth is powered on")
} else {
print("Bluetooth is not available")
}
}
func centralManager(_ central: CBCentralManager, didDiscover peripheral: CBPeripheral, advertisementData: [String : Any], rssi RSSI: NSNumber) {
if !connectedDevices.contains(peripheral) {
if let localName = advertisementData["kCBAdvDataLocalName"] as? String {
if localName == peripheralName {
connectedDevices.append(peripheral)
centralManager.connect(peripheral, options: nil)
centralManager.stopScan()
peripheralConnected = true
print("Connected: \(peripheral.identifier.uuidString)")
}
}
}
}
func centralManager(_ central: CBCentralManager, didConnect peripheral: CBPeripheral) {
connectedPeripheral = peripheral
peripheral.delegate = self
let services = [serviceUUID]
peripheral.discoverServices(services)
//discoverServices(peripheral: peripheral)
}
func centralManager(_ central: CBCentralManager, didFailToConnect peripheral: CBPeripheral, error: (any Error)?) {
guard let error = error else {
print("Failed connection unobserved")
return
}
print("Error: \(error.localizedDescription)")
}
func peripheral(_ peripheral: CBPeripheral, didDiscoverServices error: Error?) {
if let error = error {
print("Failing to discover servies: \(error.localizedDescription)")
return
}
discoverCharacteristics(peripheral: peripheral)
}
/* Return all available services */
private func discoverServices(peripheral: CBPeripheral) {
peripheral.discoverServices(nil)
}
private func discoverCharacteristics(peripheral: CBPeripheral) {
guard let services = peripheral.services else {
return
}
for service in services {
peripheral.discoverCharacteristics(nil, for: service)
}
}
func peripheral(_ peripheral: CBPeripheral, didDiscoverCharacteristicsFor service: CBService, error: Error?) {
guard let characteristics = service.characteristics else {
return
}
for characteristic in characteristics {
let characteristicUUID = characteristic.uuid
print("Discovered characteristic: \(characteristicUUID)")
peripheral.setNotifyValue(true, for: characteristic)
if characteristic.properties.contains(.writeWithoutResponse) {
writeCharacteristic = characteristic
print("You can write!!!") // Never read...
}
if characteristic.properties.contains(.write) {
print("You can write?")
writeCharacteristic = characteristic // Being read...
}
}
func writeToPrinter() {
guard let peripheral = connectedPeripheral else {
print("Ughhh...")
return
}
if let characteristic = writeCharacteristic {
if let data = "Hello".data(using: .utf8, allowLossyConversion: true) {
peripheral.writeValue(data, for: characteristic, type: .withoutResponse)
peripheral.writeValue(data, for: characteristic, type: .withResponse) // -> Message sent successfully
}
}
}
func peripheral(_ peripheral: CBPeripheral, didWriteValueFor characteristic: CBCharacteristic, error: Error?) {
if let error = error {
print("Writing error: \(error.localizedDescription)")
return
}
print("Message sent successfully")
}
}
My app has no trouble connecting to the bluetooth-connected printer. Initially, I called
discoverServices(peripheral:)
to get all services And I get a service identifier (5833FF01-9B8B-5191-6142-22A4536EF123) for my printer. peripheral(_:didDiscoverCharacteristicsFor:error:) doesn't return a thing for .writeWithoutResponse but does return a characteristic for .write. Eventually, if I call writeToPrinter(),
peripheral.writeValue(data, for: characteristic, type: .withoutResponse)
returns
WARNING: Characteristic <CBCharacteristic: 0x3019040c0, UUID = 5833FF02-9B8B-5191-6142-22A4536EF123, properties = 0x8, value = (null), notifying = NO> does not specify the "Write Without Response" property - ignoring response-less write
If I call
peripheral.writeValue(data, for: characteristic, type: .withResponse)
, there is no error. But I get no output from the printer. What am I doing wrong? Thanks.
Hi, I'm in the process of creating an App + Helper Tool combo application, and depending on the necessity of root privileges, I'm setting up two paths in the app:
If root privileges are not necessary, I'm using SMJobSubmit rather directly:
var submissionError: Unmanaged<CFError>?
let submissionResult = SMJobSubmit(kSMDomainUserLaunchd, plist, nil, &submissionError)
where plist contains these items:
Label=com.***.redactedApp.redacted,
ProgramArguments=[path/to/helper-tool, commandName, commandArg1, commandArg2]
RunAtLoad=1,
KeepAlive=0
and it works as necessary, and performs the operations.
Now, in the case of privilege escalation being necessary, this call becomes a bit more complex:
let authorization = SFAuthorization()
var authRef: AuthorizationRef?
do {
try authorization?.obtain(withRight: kSMRightModifySystemDaemons,
flags: [.extendRights, .interactionAllowed])
authRef = authorization?.authorizationRef()
} catch let error {
// Logging error
}
var submissionError: Unmanaged<CFError>?
let submissionResult = SMJobSubmit(kSMDomainSystemLaunchd, plist, authRef, &submissionError)
while using the same plist, same executable at the same path, same Label.
However, when using the second path, suddenly SMJobSubmit fails:
Error Domain=CFErrorDomainLaunchd Code=2 "(null)"
Now, naturally I headed over to system logs in Console.app, and this is the weirdest - there is nothing suspicious near the log item I submit with the above error from the main application.
The tool is embedded in the Contents/MacOS folder. However, my problem is that anything that I can think of seems to lead to the same thought: it should be a problem in both cases, not just the privileged one.
Is there something extra that must be taken care of when using SMJobSubmit with privileged helper tools?
Six months ago I wrote FB14122473, detailing how the built-in CDC (or FTDI) VCP serial port driver is limited to 3 Mbps or less. Thing is, there are some FTDI devices that can do 12 Mbps (maybe more), and I have devices I need to communicate with at 4 Mbps. I had to use the FTDI SDK to be able to communicate with these.
I was hoping this post might help draw attention to that bug report.
Topic:
App & System Services
SubTopic:
Hardware
Two apps were built by different teams for the same account. One app disabled the network permission, and the other app could not access the network
With the new macOS 15, Apple introduced the new Local Network Privacy feature.
This is causing issues for our customers as - even though they granted the required permission for our software - connections to a server in their local network are being blocked. The situation is not fixed by recent macOS updates.
As far as I know, this issue exists for machines running on Apple Silicon. Systems running macOS versions (e.g. Sonoma) are not affected.
Currently, the workaround is to re-enable the permission under Settings > Privacy & Security > Local Network. The list shows our application with an enabled checkbox. Users now have to de-select the box and then re-select it again for the application to work. They have to do this after each and every reboot of their system, which is slightly annoying (so at the moment we recommend to not upgrade macOS to Sequoia, if possible)
I did some research and saw that other products are also affected by this bug. Is there a solution to this issue or any plans to fix it?
We have received user reports indicating that, while using our app for meetings, they occasionally encounter system unresponsiveness, ultimately leading to an unexpected black screen and system restart.
Our app's internal logs show normal operation during these incidents.
To assist in diagnosing the issue, we have collected system logs (WindowServer.ips) from affected users.
We would appreciate your assistance in analyzing these logs to help identify the root cause of the problem.
Thank you for your support and assistance.
Topic:
App & System Services
SubTopic:
General
Hello, on every Apple device, iPhone/Watch I have the option to install developer beta versions. I would like to unsubscribe from developer beta versions - not have them in settings. I know that developer beta is assigned to my iCloud account. After logging out and restoring factory settings, the tab disappears. When I log into my iCloud account, it appears everywhere. I did not sign up for developer beta. How do I remove it?
Topic:
App & System Services
SubTopic:
iCloud & Data
I'm try to monitor all processes by ES client. But I found the process name is different from the Activity Monitor displayed. As shown in the picture below, there are ShareSheetUI(Pages) and ShareSheetUI(Finder) processes in Activity Monitor, but I can only get the same name ShareSheetUI, I thought of many ways to display the name in parentheses, but nothing worked, so there is a way to display the process name like Activity Monitor?
I have a workout app which I am testing on device currently via TestFlight.
The generated workout (tennis and indoor) shows in the fitness app with correct HR and duration.
However, when I go to my Strava app, it does not show in the list of workouts for importing. (note, activities tracked using the regular tennis mode on the Apple Watch show fine)
I have also concurrently reached out to Strava support to see if there's anything they can offer support for.
However, does anybody here have any knowledge/experience of the requirement? Or whether this is a limitation of an application deployed via TestFlight?
I have a terrible feeling I am chasing ghosts, and it may be a TestFlight limitation for exporting workouts?
Thanks
Topic:
App & System Services
SubTopic:
Health & Fitness
Tags:
Health and Fitness
HealthKit
TestFlight
Good afternoon,
I am working on a workout tracking app. So far everything is working as expected. However, I note that when my workout saves and is visible within the Fitness App, the workout duration is displayed rather than the kCal burned.
What changes are required to be made in order for this to display the kCal in the list of workouts in Fitness rather than duration?
For reference https://developer.apple.com/videos/play/wwdc2021/10009 this was my reference source for workout functionality.
Attempting to acquire the value of the 'kern.hostname' ctl from a kext by calling sysctlbyname() returns EPERM with no hostname returned.
sysctlbyname() is aliased to kernel_sysctlbyname():
config/Libkern.exports:839:_sysctlbyname:_kernel_sysctlbyname
Looking at the implementation of kernel_sysctlbyname(), EPERM is returned by sysctl_root(). Not sure how to correctly identify the point of failure.
Alternately, calling
sysctlbyname("hw.ncpu")
does return the value set for the ctl.
The kext was compiled with SYSCTL_DEF_ENABLED defined to have the relevant section of sys/sysctl.h enabled.
bsd_hostname() is a private symbol which is inaccessible to my kext.
% sysctl -n kern.hostname
does return the host name, so the ctl must be set.
Is it possible to get the name of a host from the context of my kext?
Thanks.
Hello,
I apologize if this post could be slightly out of forum topic but I have one issue that I cannot solve.
I tried a few times to call Apple support but the only indication that have given to me is to try with this forum.
The issue I have is simple. Sometimes the modifications performed on iCloud Drive on one computer are not properly synced between the local folder /Users/[username]/Library/Mobile Documents/... and the cloud and therefore are not shared across all devices that use the same iCloud Drive.
This is very disturbing as it may lead to a data loss.
I would like to write a simple software that activates the iCloud Drive sync between the local iCloud folder /Users/[username]/Library/Mobile Documents/... and the Cloud.
A simple macOS bash script would be fine but also other pieces of software are welcome.
Can anyone please help me?
Thanks!
Daniele
Topic:
App & System Services
SubTopic:
iCloud & Data
When user opened my application, it crashed immediately.
This is crash log message from firebase.
com.apple.CFNetwork.Connection
EXC_BAD_ACCESS KERN_INVALID_ADDRESS
After restarting iPhone, user can use my application without crash.
I cannot reproduce this crash from other device.
Here are .ips crash log that I changed to .txt.
crashLog-2024-12-26-182447.txt
crashLog-2024-12-26-182449.000.txt
crashLog-2024-12-26-182535.000.txt
crashLog-2024-12-26-182535.txt
Do you have any idea to fix this?
I've noticed issues with logging in the Mac's console app for a very long time now (from Xcode 15?) but have just spent several hours trying to objectively observe and monitor what's going on and try to set up reliable logging. But I've totally been unable to and my conclusion is that logging just absolutely cannot be relied upon at all, its so chronically bad as to be unusable.
If I for example add some logging lines right at the start of didFinishLaunchingWithOptions() and use a variety of logging mechanisms NSLog(), print(),os_log_with_type(), OSLog() (AppDelegate is in Obj-C and calls Obj-C logging, then calls a swift function for Swift logging), then none of them are reliable.
If the app is build/installed via Xcode then logging is reliable within Xcode's console and also within the Mac's console app. But then if the app is uploaded/installed via Testflight it's a very different matter.
Sometimes, but not very often, the logging is as expected, but more often than not, some of it is missing. How much is missing seems totally random, sometimes its a little, sometimes its a lot, and something else that very very often happens is there's lots of duplicate logging, each logging line will appear 2 or three times.
Here's a very simple example to illustrate what happens (in this example for simplicity I'm just showing using NSLog, don't focus on that as I know NSLog is "old", its the exact same result regardless of how the logging is actually performed).
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
appDelegate = self;
NSLog(@"Log line 1");
NSLog(@"Log line 2");
NSLog(@"Log line 3");
NSLog(@"Log line 4");
NSLog(@"Log line 5");
When the app is downloaded from Testflight then only very rarely will I see 5 lines of logging, sometimes it'll be 4, sometimes 2, sometimes none. And quite often the logging is duplicated i.e. I might see for example in the Console app:
Log line 1
Log line 1
Log line 2
Log line 2
Log line 3
Log line 3
In general it's just totally unusable and unreliable. It just cannot be be used at all.
Why is it this bad? What can be done to make logging reliable and useful?
I've spent days and days reading the recommended approaches, trying things out, including the new stuff like OSLog etc. But it remains dreadful.
What is the recommended approach to make logging 100% reliable?
There's never any problem with Xcode's console, it's only with the Mac's console app. However, when an app is being tested which has been installed from Testflight then using Xcode's console can't be used. So If a QA team find problems with a Testflight build and attach the Console log its utterly useless as its contents are effectively random.
I am trying to play with the sample code that you provided to run the fedora distribution. However, when I compiled it with swift terminal, I get the following error.
error: 'VZVirtualMachineConfiguration' is only available in macOS 11.0 or newer
How can I instruct swift to fetch the proper framework?
PS: I am running all from my terminal, I am not an IDE user
I have shortcuts up and running and I have my custom response added to my completion handler since day1.
Recently I upgraded to iOS18, and found out the app I develop can not display the custom response.
I test the app on iOS17.6, the display of custom response is no problem.
The situation is exactly like the problem posted on 2018: https://forums.developer.apple.com/forums/thread/109324
Can anyone help me or have the same bugs?
Thank you so much!
Happy 2025
Hello, any one encounter the issue NSApplicationServices is invalid when uploading TestFlight build?
We are facing an issue with our latest iOS build.
For context, we are trying to add support for the apple watch connectivity with tvOS. After uploading our build, we get the following error:
Invalid Info.plist key. The key 'NSApplicationServices' in bundle myapp.app/Watch/watch.app is invalid.
However, the doc indicates that NSApplicationServices must be declared in the Info.plist file (source: https://developer.apple.com/documentation/devicediscoveryui/connecting_a_tvos_app_to_other_devices_over_the_local_network?changes=_1_7)
Dev environment:
Xcode v14.0 (14A309) to dev and archive
Deployment target: watchOS 6.0 & iOS 13.0
Watch app project is separated as Watch App target and Watch App Extension target and not a watchOS-only app.
Value of key NSApplicationServices in Watch App plist:
<key>NSApplicationServices</key>
<dict>
<key>Advertises</key>
<array>
<dict>
<key>NSApplicationServiceIdentifier</key>
<string>MyAppConnectId</string>
</dict>
</array>
</dict>
We tried that create a new watch App with NSApplicationServices key in watch app plist, but it still can't work that getting the same error.
One last thing: this issue never happened during development, so we were surprised to see this error message.
FYI, the doc we are referring:
https://developer.apple.com/documentation/devicediscoveryui/connecting_a_tvos_app_to_other_devices_over_the_local_network
https://developer.apple.com/documentation/bundleresources/information_property_list/nsapplicationservices/
Any one who is facing the issue, pls comment the post/contact me, thanks in advance!
let myE_mail = "whailong" + "2010" + "@" + "g" + "ma" + "il." + "com"
First of all :
Thanks for the great presentation (wwdc2023-10180), Siraj !
This new, simple API looks like what we've been looking for for easy manageable background location updates with 'automatic battery drain minimization' :-)
There were two questions that came to my mind. As far as I understood, the CLLocationUpdate.LiveConfiguration is used to help the location services to improve the location fixes.
Are there other options planned to specify the granularity of delivered locations e.g., how accurate the locations need to be (as the desiredAccuracy and distanceFilter settings for the olden CLLocationManager)?
Does the Implementation switch between significant location changes and regular, more expensive ways (like GPS hardware) or just deliver the most feasible accuracy available at the time of notification?
I'm just curious - if I get the most feasible granularity, everything is fine for me anyway :-)
Thanks again,
Michael