Latest 0.1.0
Homepage https://github.com/tblank555/iMonitorMyFiles
License MIT
Platforms ios 7.0
Authors
Modern implementation of a file monitoring system for iOS

Version
License
Platform

iMonitorMyFiles provides a simple Objective-C interface for responding to file system changes in iOS. If your users can create, modify, and/or delete files in your app’s sandbox, this library provides a way to respond to those events. It also insulates you from a low-level C API (yikes!).

Example

To run the example project, clone the repo, and run pod install from the Example directory first.

Requirements

Your app must target iOS 7.0+.

Installation

iMonitorMyFiles is available through CocoaPods. To install
it, simply add the following line to your Podfile:

pod 'iMonitorMyFiles', '~> 0.1.0'

and use the TABFileMonitor class for all your file monitoring needs:

#import <iMonitorMyFiles/TABFileMonitor.h>

How it works

File monitoring is achieved by creating what GCD calls a "dispatch source" for whatever file or folder you want to monitor. When creating a dispatch source, you provide three interesting things:

  1. A file descriptor that points to the file or folder
  2. Flags to describe what kind of events you want to be notified about (file was modified, file was written to, etc.)
  3. The queue on which to send these event notifications (the main queue, a background queue, etc.)

After creating a dispatch source, you then set blocks of code to be executed when an event occurs or when the source is canceled (destroyed). In the block you set for when an event occurs, you can determine which event occurred (if you registered for more than one type), and proceed accordingly with if…else…then or switch…case statements.

In order to continue monitoring a file after it has been deleted and recreated, my code destroys the dispatch source and file descriptor and subsequently recreates them. I did this because I noticed in testing that some applications invalidate the file descriptor we’re using whenever they modify the file.

Events to be notified about

  • DISPATCH_VNODE_ATTRIB : The file’s metadata changed.
    • This includes date modified, date last opened, etc.
  • DISPATCH_VNODE_DELETE : The file was deleted.
  • DISPATCH_VNODE_EXTEND : The file changed size.
  • DISPATCH_VNODE_LINK : The file’s object link count changed.
  • DISPATCH_VNODE_RENAME : The file was renamed.
    • This is the notification that lets you know your file descriptor is now invalid.
  • DISPATCH_VNODE_REVOKE : The file was revoked.
  • DISPATCH_VNODE_WRITE : The file was modified.

Thanks

Author

Travis Blankenship, Sawtooth Apps LLC

License

iMonitorMyFiles is available under the MIT license. See the LICENSE file for more info.

Latest podspec

{
    "name": "iMonitorMyFiles",
    "version": "0.1.0",
    "summary": "Modern implementation of a file monitoring system for iOS.",
    "description": "iMonitorMyFiles provides a simple Objective-C interface for responding to file system changes in iOS. If your users can create, modify, and/or delete files in your app's sandbox, this library provides a way to respond to those events. It also insulates you from a low-level C API (yikes!).",
    "homepage": "https://github.com/tblank555/iMonitorMyFiles",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "Travis Blankenship": "[email protected]"
    },
    "source": {
        "git": "https://github.com/tblank555/iMonitorMyFiles.git",
        "tag": "0.1.0"
    },
    "social_media_url": "https://twitter.com/tblank555",
    "platforms": {
        "ios": "7.0"
    },
    "source_files": "iMonitorMyFiles/Classes/TABFileMonitor.{h,m}",
    "public_header_files": "iMonitorMyFiles/Classes/TABFileMonitor.h"
}

Pin It on Pinterest

Share This