1

我正在尝试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 
    }

}

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

4

1 回答 1

4

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

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

此外,众所周知,某些应用程序(如 Facebook)会尽可能多地收集有关用户的数据,同时拥有比 Apple 宽松得多的隐私政策。阻止后台粘贴板访问是一种减少 Facebook 监视您的非 Facebook 活动的能力的方法。

于 2019-02-01T17:49:10.597 回答