我知道这是可能的,因为 Tapbots Pastebot 会这样做。当我的 iPhone 应用程序在后台运行时,我试图抓取 UIPasteboard 并将其添加到 UITableView 就像 Pastebot 一样,但我也试图缩短链接,如果它是一个 URL 并将其复制回 UIPastboard 以便它准备好供用户粘贴到任何地方。现在,Pastebot 显然通过播放音频文件 10 分钟在后台运行。我已经在 applicationDidFinishLaunching 中设置了 NSNotificationCenter
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(pasteboardChangedNotification:) name:UIPasteboardChangedNotification object:[UIPasteboard generalPasteboard]];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(pasteboardChangedNotification:) name:UIPasteboardRemovedNotification object:[UIPasteboard generalPasteboard]];
- (void)pasteboardChangedNotification:(NSNotification*)notification {
pasteboardChangeCount_ = [UIPasteboard generalPasteboard].changeCount;
}
- (void)applicationDidBecomeActive:(UIApplication *)application
{
if (pasteboardChangeCount_ != [UIPasteboard generalPasteboard].changeCount) {
[[NSNotificationCenter defaultCenter] postNotificationName:UIPasteboardChangedNotification object:[UIPasteboard generalPasteboard]];
}
}
谁能指出我抓住 UIPasteboard 和缩短链接的方向,如果它是一个 URL 并将其发送回 UIPasteboard?我已经阅读了多任务开发文档和 UIPasteboard 文档。如果有人有解决方案,您可以与我分享吗?
谢谢