简体   繁体   English

iPhone文件共享:如何识别何时添加文件?

[英]iPhone File Sharing: How to recognize when files have been added?

I have file sharing via iTunes working in my application (reference What's New in iOS 3.2 ) by enabling the UIFileSharingEnabled key, but according to the documentation: 通过启用UIFileSharingEnabled键,我在我的应用程序中通过iTunes进行文件共享(参考iOS 3.2中的新功能 ),但根据文档:

"Applications that support file sharing should be able to recognize when files have been added to the Documents directory and respond appropriately." “支持文件共享的应用程序应该能够识别何时将文件添加到Documents目录并进行适当的响应。”

My question is, if my application is running, and then the user decides to add a file, how do I respond to this event? 我的问题是,如果我的应用程序正在运行,然后用户决定添加文件,我该如何回应此事件? And what event is it that I would respond? 我会回应什么事件?

In other words, I know what my iPhone application needs to do when a file is added but not sure where to put this "responding" code. 换句话说,我知道我的iPhone应用程序在添加文件时需要做什么,但不知道在哪里放置这个“响应”代码。 Currently, if my application is running (could be running in the background as well) and a file is added, the only way to see the effects of this added file is by force-quitting the application and then re-launching the app. 目前,如果我的应用程序正在运行(也可能在后台运行)并且添加了文件,则查看此添加文件的效果的唯一方法是强制退出应用程序,然后重新启动应用程序。

You need to remember that your app isn't really running in the background, or at all for that matter when files are added to the device. 您需要记住,您的应用程序实际上并未在后台运行,或者在将文件添加到设备时完全无法运行。 In order for the user to add files to device he needs to sync it in iTunes. 为了让用户将文件添加到设备,他需要在iTunes中同步它。 So after the sync is done, your app will either be relaunched, or resumed, in both these cases you have methods in your app delegate which you can use to check if new files were added to to the application. 因此,在同步完成后,您的应用程序将重新启动或恢复,在这两种情况下,您在应用程序委托中都有方法可用于检查是否将新文件添加到应用程序中。

- (void)applicationDidBecomeActive:(UIApplication *)application
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM