Apple (via Jeff Nadeau):
Prepare your app for an upcoming feature in macOS that alerts a person using a device when your app programmatically reads the general pasteboard. The system shows the alert only if the pasteboard access wasn’t a result of someone’s input on a UI element that the system considers paste-related. This behavior is similar to how
UIPasteboard
behaves in iOS. Newdetect
methods inNSPasteboard
andNSPasteboardItem
make it possible for an app to examine the kinds of data on the pasteboard without actually reading them and showing the alert.NSPasteboard
also adds anaccessBehavior
property to determine if programmatic pasteboard access is always allowed, never allowed, or if it prompts an alert requesting permission. You can adopt these APIs ahead of the change, and set a user default to test the new behavior on your Mac. To do so, launch Terminal and enter the commanddefaults write
to enable the behavior for your app.EnablePasteboardPrivacyDeveloperPreview -bool yes
The Swift and Objective-C APIs are different.
Long ago when I was still at Apple I filed a radar suggesting something like this when I found out the Facebook iOS app would look into the pasteboard as soon as it was brought forward and suggest posting any URL the user might have there.
This is incredibly hard to get right since there’s no straightforward way for the OS to know if a paste op is legit.
Previously: