I want to develop a clipboard manger for iOS. Currently I listen to clipboard changes like this:
class AppDelegate: UIResponder, UIApplicationDelegate {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {
print("Listening for clipboard changes")
NotificationCenter.default.addObserver(self, selector: #selector(clipboardChanged), name: UIPasteboard.changedNotification, object: nil)
return true
}
@objc func clipboardChanged() {
if let pasteboardString = UIPasteboard.general.string {
print("Copied text: \(pasteboardString)")
}
}
}
Is it possible to listen for clipboard changes continuously from a background service? From my understanding you can create following types of background tasks. Which one would fit here or is it just not possible, because only short running tasks are allowed?
It’s not something your app can do in the background. You also require user approval to access the contents of the clipboard each time because continual clipboard snooping is a privacy risk.