本文介绍了iOS的9 UIPasteboard不会在后台工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
9 iOS版的 [UIPasteboard generalPasteboard] .string
将成为空当应用程序在运行的后台任务或今天插件的背景。
iOS 9's [UIPasteboard generalPasteboard].string
will become null when the app is in the background running a background task or Today widget.
我们不能检索后台剪贴板文本了吗?
Can't we retrieve a clipboard text in the background any more?
推荐答案
你能解释一下你在哪里发动generalPasteboard?
Can you explain where do you launch generalPasteboard?.
这是我会做什么:
在您的应用程序委托的applicationdidBecomeActive方法把这个code:
In your app delegate's applicationdidBecomeActive method put in this code:
[[NSNotificationCenter defaultCenter] postNotificationName:@"appDidBecomeActive" object:nil];
接下来,在您的当前活动视图控制器的init方法订阅通知。
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(returnFromBg)
name:@"appDidBecomeActive"
object:nil];
- (void)returnFromBg {
UIPasteboard *appPasteBoard = [UIPasteboard generalPasteboard];
yourTextField.text = [appPasteBoard string;
}
PS不要忘了删除观察者当视图控制器被删除:
PS Don't forgot to remove the observer when the view controller is removed:
[[NSNotificationCenter defaultCenter] removeObserver:self];
这篇关于iOS的9 UIPasteboard不会在后台工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!