Swift UIPasteboard在后台返回nil

Swift UIPasteboard在后台返回nil,swift,appdelegate,uipasteboard,ios-background-mode,Swift,Appdelegate,Uipasteboard,Ios Background Mode,我试图在AppDelegate的ApplicationDidentBackground部分中读取粘贴板5次。要打印字符串,我使用print(UIPasteboard.general.string!),但它只在函数中起作用,在其他嵌套函数中不起作用。让我解释一下: func applicationDidEnterBackground(_ application: UIApplication) { // Use this method to release shared resources,

我试图在AppDelegate的
ApplicationDidentBackground
部分中读取粘贴板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)可以收集尽可能多的用户数据,同时隐私政策也比苹果宽松得多。阻止后台粘贴板访问是一种降低Facebook监视您非Facebook活动的能力的方法。

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

他们做出这一改变大概是为了防止后台应用程序监视你的粘贴板内容。有时人们使用粘贴板将密码从一个应用程序复制到另一个应用程序,因此阻止后台粘贴板访问是一个安全问题

此外,一些应用程序(如Facebook)可以收集尽可能多的用户数据,同时隐私政策也比苹果宽松得多。阻止后台粘贴板访问是一种降低Facebook监视您非Facebook活动能力的方法