iOS复制和粘贴

我正在创建一个应用程序,以便在我在iOS设备上复制内容时保存复制的项目。

无论如何我可以创建一个事件,以便我可以随时从iOS设备上的任何应用程序复制某些内容,将其保存到我的应用程序中吗?

我希望它能随时复制文本,以便将其粘贴到我的应用程序文本框中。

- (void)copy { UIPasteboard *pasteboard = [UIPasteboard generalPasteboard]; pasteboard.string = @"String"; } - (void)paste { UIPasteboard *pasteboard = [UIPasteboard generalPasteboard]; NSString *string = pasteboard.string; NSLog(@"%@",string"); } 

请参阅此链接UIPasteBoard

看看UIResponderStandardEditActions非正式协议:

https://developer.apple.com/library/ios/documentation/uikit/reference/UIResponderStandardEditActions_Protocol/UIResponderStandardEditActions.html

关键是要确保您的视图控制器可以成为第一响应者,然后实现以下方法:

 - (void)copy:(id)sender; - (void)paste:(id)sender; 
  UIPasteboard *pb = [UIPasteboard generalPasteboard]; NSDictionary *CellData = [NSDictionary dictionaryWithDictionary:[ArrayName objectAtIndex:SelectedIndexPath.row]]; NSString* strText = [(NSDictionary*)[(NSString*)[CellData objectForKey:@"Key"] JSONValue] objectForKey:@"english"]; [pb setString:strText];