我正在尝试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
}
}
我读过与我的类似的其他问题,但没有一个对我有帮助。我不知道这是否是安全限制,但如果你能帮助我,我将不胜感激