UIPasteboard顽固地坚持,无论我做什么

发布于 2024-12-08 13:36:16 字数 312 浏览 8 评论 0原文

我正在创建一个应用程序 UIPasteboard,并按照文档中的建议使用我的应用程序标识符作为名称(例如 com.example.app.pboard)。

所有的复制和粘贴都有效,但该死的东西永远不会消失。每次访问它以将某些内容复制到其上时,我都会将其 persistent 属性显式设置为 NO,甚至每次我的应用程序启动时都会调用 UIPasteboard 的 +removePasteboardWithName:

但每次我查看它时,尽管应用程序重新启动,我复制到它上面的最新内容始终都在那里。

什么给?

I am creating a application UIPasteboard with my app's identifier as a name (e.g. com.example.app.pboard) as suggested in the docs.

All the copying and pasting works, but the damn thing never goes away. I set its persistent property explicitly to NO every time I access it to copy something onto it, and I even call UIPasteboard's +removePasteboardWithName: every time my app starts.

But every time I look at it, the most recent thing I copied onto it is always there, despite app restarts.

What gives?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

风渺 2024-12-15 13:36:16

不知道为什么您正在尝试的方法不起作用,这里有两个猜测和一个可能的解决方案:

  • 删除粘贴板可能会在退出应用程序时执行,因此它不会执行直到应用程序终止或进入后台?
  • 调用删除然后请求项目可能会在同一“位置”再次重新创建它,因此项目仍然保留。

您也许可以通过在离开或进入应用程序时将粘贴板的 items 设置为 nil 来解决此问题。

No idea why what you are trying isn't working, here are two guesses and a possible solution:

  • Removing the paste board may be expected to be executed on exit from the app, so it doesn't execute until the app is terminated or backgrounded?
  • Calling remove and then asking for the items may be recreating it again in the same "place" so the items still remain.

You could perhaps solve this by setting the pasteboard's items to nil when leaving or entering the app.

睫毛溺水了 2024-12-15 13:36:16

您可以将 UIPasteboard 设置为持久。根据Apple的文档

设置持久性:
一个布尔值,指示粘贴板是否持久。
当粘贴板持久存在时,它会在应用程序终止和系统重新启动后继续存在。不持久的应用程序粘贴板只会持续到拥有(创建)的应用程序退出为止。系统范围的通用粘贴板是持久的。命名的、特定于应用程序的粘贴板不是持久的。

更新:对于 iOS 10,UIPasteboard 自动设置持久性。

注意
从 iOS 10 开始,系统自动设置粘贴板持久性。如果您尝试在粘贴板上设置 setPersistent: 属性,Xcode 会发出弃用警告。
使用共享容器,而不是命名的持久粘贴板,如本文档的概述部分所述。

You can set UIPasteboard to persistent. Accord to Apple's document,

setPersistent:
A Boolean value that indicates whether the pasteboard is persistent.
When a pasteboard is persistent, it continues to exist past app terminations and across system reboots. App pasteboards that are not persistent only last until the owning (creating) app quits. The system wide general pasteboard is persistent. Named, app-specific pasteboards are not persistent.

Update: For iOS 10, UIPasteboard set persistence automatically.

Note
Starting in iOS 10, the system sets pasteboard persistence automatically. If you try to set the setPersistent: property on a pasteboard, Xcode issues a deprecation warning.
Instead of named persistent pasteboards, use shared containers, as described in the Overview section of this document.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文