当应用程序在后台运行后台任务或今日小工具时,iOS 9的[UIPasteboard generalPasteboard].string
将变为空。
我们不能再在后台检索剪贴板文本了吗?
发布于 2016-02-09 21:39:03
你能解释一下在哪里启动generalPasteboard吗?
这就是我要做的:
在您的应用程序代理的applicationdidBecomeActive方法中,放入以下代码:
[[NSNotificationCenter defaultCenter] postNotificationName:@"appDidBecomeActive" object:nil];
接下来,在您的当前活动视图控制器的初始化方法中订阅通知。
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(returnFromBg)
name:@"appDidBecomeActive"
object:nil];
- (void)returnFromBg {
UIPasteboard *appPasteBoard = [UIPasteboard generalPasteboard];
yourTextField.text = [appPasteBoard string;
}
PS当视图控制器被移除时,不要忘记移除观察者:
[[NSNotificationCenter defaultCenter] removeObserver:self];
https://stackoverflow.com/questions/31920597
复制相似问题