Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
471 views
in Technique[技术] by (71.8m points)

ios - Named UIPasteboard between apps?

Is it possible to use a named UIPasteboard (ie, not the global one) to transfer data between two apps?

  • the apps are completely independent of each other, so have different bundle IDs from different vendors
  • I'd like to use a named pasteboard, so the user's own content in the global pasteboard is not overwritten

Apple's docs say:

Pasteboards may be public or private. Public pasteboards are called system pasteboards; private pasteboards are created by applications, and hence are called application pasteboards.

The implication is that a pasteboard can be either "global and public" or "named and private".

I created two apps, with different bundle IDs, and seem to be able to pass stuff from one app to the other using a private named pasteboard. But is that just a feature of the iOS Simulator, or something which really supported but not well documented?

Thanks for any insight!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You can set a custom string for your pasteboard value and use that across your apps so your apps have to access the value with your unique string:

UIPasteboard *pasteboard = [UIPasteboard pasteboardWithName:@"youruniquestring" create:YES];

[pasteboard setPersistent:YES];

//save the unique identifier string that we created earlier
[pasteboard setString:@"your message"];

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...