background - iOS 9 UIPasteboard 无法在后台运行

标签 background clipboard ios9

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/

相关文章:

iOS9 beta 中 Javascript 数组总是返回空数组

css - 手机网站,后台不缩放

CSS 背景图片未出现在 Safari 中

c++ - 在 Qt 中,如何将 QString 注册到我的系统剪贴板,包括引用和非引用?

ios - 如何在不上传到 Appstore 的情况下检查 iOS 中的应用切片功能

facebook - 试图从 Facebook 获取用户生日,但我没有得到。我究竟做错了什么?

macos - LSUIElement 应用程序具有响应能力

swift - 垂直移动 Swift 背景中的黑线

python - 应用程序退出后未设置剪贴板?

compression - 有什么方法可以预测 png 大小吗?