I have a Macos app I am developing where I created a button that programmatically pastes the user’s clipboard to wherever their selection is. This behavior works fine in Xcode local debugging but doesn’t paste at all when in TestFlight.
Also is there an easier way to have a closer to ‘real-life’ scenario when debugging locally to avoid the discrepancy between TestFlight and building locally?
func pasteText() {
DispatchQueue.main.async {
let source = CGEventSource(stateID: .combinedSessionState)
let vDown = CGEvent(keyboardEventSource: source, virtualKey: CGKeyCode(9), keyDown: true)
vDown?.flags = .maskCommand // Add Command modifier
let vUp = CGEvent(keyboardEventSource: source, virtualKey: CGKeyCode(9), keyDown: false)
vDown?.post(tap: .cgAnnotatedSessionEventTap)
vUp?.post(tap: .cgAnnotatedSessionEventTap)
}}
2
Answers
I ended up fixing this issue by playing around with the privacy and security settings for the app. It seems like even though I gave accessibility permissions for the app while running the app locally, I had to delete the permissions and add them again for TestFlight even though the permission still appeared to be granted.
The reason this fails for TestFlight build is probably that you are sandboxed. Your app needs a user permission in the Privacy settings to control the computer.
Choose Product > Archive and export from the archive.