iTunes File Sharing app: realtime monitoring for incoming datas

前端 未结 2 1577
[愿得一人]
[愿得一人] 2020-12-09 06:56

I\'m working on iOS project that supports iTunes file sharing feature. The goal is realtime tracking incoming/changed data\'s.

I\'m

2条回答
  •  借酒劲吻你
    2020-12-09 07:09

    I found two rather reliable (i.e. not 100% reliable but reliable enough for my needs) approaches, which only work in conjunction with polling the contents of the directory:

    1. Check NSURLContentModificationDateKey. While the file is being transferred, this value is set to the current date. After transfer has finished, it is set to the value the original file had: BOOL busy = (-1.0 * [modDate timeintervalSinceNow]) < pollInterval;
    2. Check NSURLThumbnailDictionaryKey. While the file is being transferred, this value is nil, afterwards it cointains a thumbnail, but probably only for file types from which the system can produce a thumbnail. Not a problem for me cause I only care about images and videos, but maybe for you. While this is more reliable than solution 1, it hammers the CPU quite a bit and may even cause your app to get killed if you have a lot of files in the import directory.

    Dispatch sources and polling can be combined, i.e. when a dispatch source detects a change, start polling until no busy files are left.

提交回复
热议问题