Named UIPasteboard between apps?

十年热恋 提交于 2019-11-27 21:26:13

问题


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!


回答1:


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"];



回答2:


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.




回答3:


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.



来源:https://stackoverflow.com/questions/12360895/named-uipasteboard-between-apps

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!