I'm writing a keyboard APP , I want to get the text in pasteboard , so i use UIPasteboard
and this function [UIPasteboard generalPasteboard]
.
- (void)viewDidLoad {
[super viewDidLoad];
UIPasteboard *paste = [UIPasteboard generalPasteboard];
self.outputLabel.text = paste.string;
it works , I can get the string and i know the string i paste is on pasteboard . So i want get the string in paste real-time,i use observe and
- (void)viewDidLoad {
[super viewDidLoad];
UIPasteboard *paste = [UIPasteboard generalPasteboard];
self.paste = paste;
self.outputLabel.text = paste.string;
[paste addObserver:self forKeyPath:@"key" options:NSKeyValueObservingOptionNew context:nil];
}
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary<NSString *,id> *)change context:(void *)context{
self.outputLabel.text = self.paste.string;
}
but it doesn't work , even the function doesn't run .
Can anybody help me?
Also if anybody have written APP like keyboard , you can send email to me , let's discuss the bug in keyboard :) .My email is yuyanganhui@outlook.com !