The pasteboard provides a core OS feature for sharing data across applications. Users can copy and paste across apps, or you can set up copy and paste only in this app to protect privacy.
The Uipasteboard class allows access to the shared device pasteboard as well as the contents, and the following code returns to the generic system pasteboard, which is suitable for most generic copy-and-paste applications.
Uipasteboard *PD = [Uipasteboard Generalpasteboard];
Using Pasteboardwithuniquename to create an application-specific pasteboard, only applications that know and use the Pasteboard name key can use the same pasteboard.
Using pasteboardwithname:create: To create a custom pasteboard, he returns a pasteboard with the specified name. Use the reverse DNS naming method for the pasteboard. This type of pasteboard can persist beyond the operation of a single application, and can be created again to set the persistent property to Yes. You can use Removepasteboardwithname: Destroy the Pasteboard and release the resources that are used by him.
You can use the UTI to specify the type of data that the Pasteboard stores.
You can send a pasteboardtype message to the Pasteboard, query the available types of the pasteboard, and this will return an array:
Nsarray *types = [PB pasteboardtypes];
You can set the data on the Pasteboard and pass a NSData object and a UTI that describes the type of data being adapted
[[Uipasteboard Generalpasteboard] Setdata:thedata Forpasteboardtype:theuti];
In fact, in the process of development, it is seldom used in the development of pasteboard, mainly for the user to simplify the operation, but also ready to share with other applications of the content.
The following example shows that when you enter content in TextView, the clipboard automatically puts the input into the pasteboard, which can be done by TextView delegate method (Textviewdidchange:).
- (void) updatepasteboard{if(enablewatcher) [Uipasteboard Generalpasteboard].string=Textview.text;}- (void) Textviewdidchange: (Uitextview *) textview{[self updatepasteboard];}- (void) Toggle: (Uibarbuttonitem *) bbi{Enablewatcher= !Enablewatcher; Bbi.title= Enablewatcher?@"Stop Watching":@"Watch";}- (void) loadview{[Super Loadview]; Self.view.backgroundColor=[Uicolor Whitecolor]; TextView=[[Uitextview alloc] Initwithframe:cgrectzero]; TextView.Delegate=Self ; [Self updatepasteboard]; [Self.view Addsubview:textview];
IOS Access system Clipboard