iOS5 文件共享:识别文件何时添加到目录?
正如标题所说,我想知道如何识别新文件已添加到我的应用程序中,例如通过 iTunes 同步。在 iOS4 中,我使用了方法
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
或
- (void)application:(UIApplication *)application didBecomeActive
但从 iOS 5 开始,这就没用了,因为应用程序不会进入后台并在同步后变为活动状态。它保持活跃。那么有没有办法解决这个问题呢?
问候
拉尔夫
as the title says i wanna know how i can recognize that new file have been added to my App for example over an iTunes Sync. In iOS4 i used the methods
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
or
- (void)application:(UIApplication *)application didBecomeActive
But since iOS 5, this is useless because the app will not enter the Background and become active after a sync. It stays active. So is there a way to solve this?
regards
Ralf
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果 iTunes 文件共享使用新的文件协调机制(尚未检查,但我假设它确实如此),您可以实现 NSFilePresenter 协议来获取文档目录中的更改通知。
通过实现
presentedSubitemDidAppearAtURL:
和相关方法,应该可以对整个目录使用单个文件呈现器(请参阅NSFilePresenter
文档)。If iTunes file sharing uses the new file coordination mechanism (haven't checked but I would assume that it does), you could implement the
NSFilePresenter
protocol to get notified of changes in the Documents directory.It should be possible to use a single file presenter for the entire directory by implementing
presentedSubitemDidAppearAtURL:
and related methods (see "Handling Changes to a Presented Directory" in theNSFilePresenter
documentation).通常我会创建一个计时器并定期检查与 iTunes 共享的目录中是否有新文件。我认为对于 iOS5 这是最好的方法。
iOS5 可以通过 WiFi 同步,因此您无法控制何时将文件添加到目录中
Usually I create a Timer and periodically check for new files in the Directory shared with ITunes. I think with iOS5 it's the best approach.
iOS5 can sync through WiFi so you don't have control about when a file will be added to the directory