In my application I want to get notified if something is added into the NSPasteboard. If I copy an text from any other program I want my application to know about it.
Somewhere I read it can't be done that way. I should create a timer and check the content of the NSPasteboard myself.
Is this the way to do? Or are there any kind of notifications?
Да, вам, по сути, нужно опросить монтажный стол, чтобы узнать, не изменилось ли его содержимое. Это не идеально, но возможно. По сути, у вас есть таймер, который срабатывает один или два раза в секунду и проверяет -[NSPasteboard changeCount]
. Если изменяется changeCount
, это означает, что содержимое монтажного стола также изменилось (или, по крайней мере, появился новый владелец).