UIPasteboardChangedNotification を使用して、ユーザーが強調表示されたテキストをコピーしたことを検出しました
-(void)viewDidLoad {
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(receiveClipBoardNotification:)
name:@"UIPasteboardChangedNotification"
object:nil];
}
これは iOS 6 では完全に機能しますが、appPasteBoard.string は iOS 5 では nil を返します。
-(void)receiveClipBoardNotification:(NSNotification *) notification {
UIPasteboard *appPasteBoard = [UIPasteboard generalPasteboard];
NSLog(@"%@", appPasteBoard.string);
}
この問題は、xls および xlsx ファイルでのみ発生します。pdf、docx、pptx、rtf、ページ、キーなどの他のタイプのファイルでもうまく機能します。