iOS 9 的 [UIPasteboard generalPasteboard].string
当应用程序在后台运行后台任务或今日小部件时,将变为 null。
我们不能再在后台检索剪贴板文本了吗?
最佳答案
你能解释一下你在哪里启动generalPasteboard吗?
这就是我要做的:
在您的 应用委托(delegate)的 applicationdidBecomeActive 方法 输入这段代码:
[[NSNotificationCenter defaultCenter] postNotificationName:@"appDidBecomeActive" object:nil];
接下来,在您的 当前事件 View Controller 的初始化方法订阅通知。
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(returnFromBg)
name:@"appDidBecomeActive"
object:nil];
- (void)returnFromBg {
UIPasteboard *appPasteBoard = [UIPasteboard generalPasteboard];
yourTextField.text = [appPasteBoard string;
}
PS当 View Controller 被移除时不要忘记移除观察者:
[[NSNotificationCenter defaultCenter] removeObserver:self];
关于background - iOS 9 UIPasteboard 无法在后台运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31920597/