6

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!

Matthew
  • 1,363
  • 11
  • 21

3 Answers3

10

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"];
rooster117
  • 5,502
  • 1
  • 21
  • 19
  • Thanks for your answer. You specifically say "your apps", but I'm more concerned about "any two apps", not necessarily two apps from the same vendor. – Matthew Sep 11 '12 at 20:29
  • 1
    Whether the apps are both yours or from anyone as long as they are aware of the key then you are fine. This is the same method that OpenUDID uses which is a way to share a unique key amongst any app using this method. – rooster117 Sep 11 '12 at 20:31
  • 12
    This has changed with ios7. https://developer.apple.com/library/ios/releasenotes/General/RN-iOSSDK-7.0/ "pasteboardWithName now unique the given name to allow only those apps in the same application group to access the pasteboard. If the developer attempts to create a pasteboard with a name that already exists and they are not part of the same app suite, they will get their own unique and private pasteboard" – russau Nov 22 '13 at 15:56
  • 1
    @russau I'm assuming this means apps need to be signed with the same bundle seed ID, not that they need to be in the same App Group (an iOS 8 feature). – JW. Dec 02 '15 at 00:16
1

It’s supported. Keep in mind, though, that the named pasteboard will disappear if both apps that set it up are deleted, so don’t use it to store anything you don’t have a backup of.

Noah Witherspoon
  • 57,021
  • 16
  • 130
  • 131
  • Hmm, I don't understand why there would be any association with a named pasteboard and two apps. Unless iOS keeps track of which apps access a particular named pasteboard. (And that sounds a bit bonkers) #brainhurts – Matthew Sep 11 '12 at 20:34
  • @Noah: i was searching for this, but i couldn't find it, but i observed it... is it documented somewhere? Can i also ask if the pasteboards persist even after a backup/clean/restore? – LolaRun Jan 14 '13 at 22:49
  • I don’t believe it’s documented anywhere—just discovered by experimentation. Pretty sure backup/restore will wipe the pasteboards as well. – Noah Witherspoon Jan 15 '13 at 00:29
  • 1
    I just tried create a pasteboard. Accessed it using two different apps. Removed both apps. Installed one of the apps again. The pasteboard was still there. – bobmoff Jan 21 '15 at 13:19
0

If you use named pasteboard then the data can be transferred from your app to other app with same team IDs. I haven't tested yet but I don't think so you can do the same for apps of different vendors!

Apple doc says:

You can create named pasteboards with the class methods init(name:create:) and withUniqueName() for sharing data within your app and from your app to other apps that have the same Team ID.

SUMIT NIHALANI
  • 387
  • 1
  • 10