我试着在applicatioDidEnterBackground的AppDelegate部分读了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
}
}我读过其他类似于矿井的问题,但没有人帮助我。我不知道这是不是安全限制,但如果你能帮我,我会很感激
发布于 2019-02-01 17:49:10
iOS 9将UIPasteboard更改为不允许后台访问:
据推测,他们做出这一改变是为了防止后台应用程序监视你的纸板内容。有时,人们会使用黑板将密码从一个应用程序复制到另一个应用程序,因此阻止后台pasteboard访问是一个安全问题。
另外,一些应用程序(比如Facebook)可以收集尽可能多的关于用户的数据,同时比苹果的隐私政策宽松得多。阻断背景面板访问是降低Facebook监视非Facebook活动能力的一种方法。
https://stackoverflow.com/questions/54484540
复制相似问题