IOS Access system Clipboard

Source: Internet
Author: User
Tags reverse dns

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.