gpt4 book ai didi

swift - UIPasteboard 在后台返回 nil

转载 作者:行者123 更新时间:2023-11-28 11:38:21 27 4
gpt4 key购买 nike

我试图在 AppDelegate 的 applicatioDidEnterBackground 部分读取粘贴板 5 次。要打印字符串,我使用 print(UIPasteboard.general.string!) 但它仅适用于函数,不适用于其他嵌套函数。让我解释一下:

func applicationDidEnterBackground(_ application: UIApplication) {
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.

print(UIPasteboard.general.string!) //here it works perfectly and prints the string correctly

for _ in 0...5 {
print(UIPasteboard.general.string!) //here it returns nil
}

}

我读过其他与我的类似的问题,但没有一个对我有帮助。我不知道这是否是安全限制,但如果你能帮助我,我将不胜感激 🙂

最佳答案

iOS 9 更改了 UIPasteboard 以禁止后台访问:

据推测,他们进行此更改是为了防止后台应用程序监视您的粘贴板内容。有时人们使用粘贴板将密码从一个应用程序复制到另一个应用程序,因此阻止后台粘贴板访问是一个安全问题。

此外,众所周知,一些应用程序(如 Facebook)会收集尽可能多的用户数据,同时其隐私政策比 Apple 的要宽松得多。阻止后台粘贴板访问是一种降低 Facebook 监视您的非 Facebook 事件的能力的方法。

关于swift - UIPasteboard 在后台返回 nil,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54484540/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com