NSNotificationCenter PasteboardChangedNotification Not Firing

前端 未结 2 1795
死守一世寂寞
死守一世寂寞 2021-02-10 11:15

I\'m writing a custom keyboard for iOS and I\'d like to detect when the user copies some text. I\'ve read that you can use the NSNotificationCenter along with

2条回答
  •  夕颜
    夕颜 (楼主)
    2021-02-10 12:13

    You cannot use NSNotificationCenter since the keyboard extension is a different process.

    Cocoa includes two types of notification centers: The NSNotificationCenter class manages notifications within a single process. The NSDistributedNotificationCenter class manages notifications across multiple processes on a single computer.

    Try this solution: https://stackoverflow.com/a/28436058/649379 which uses CFNotifications. Don't forget to enable App Groups to get access to the shared container.

    More code here: https://github.com/cxa/AppExtensionCommunicator & https://github.com/mutualmobile/MMWormhole

提交回复
热议问题