skip to Main Content

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


  1. Chosen as BEST ANSWER

    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.


  2. 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.

    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?

    Choose Product > Archive and export from the archive.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search