I require simple for system monitoring for a new (undisclosed) iphone project. It doesn’t appear that there is any equivilant to ionotify for the iphone, so I whipped up this polling file system monitor which meets my basic requirements. If you find this code useful feel free to use / distribute etc.
#include "FileSystemMonitor.h"
//Setup the monitor
FileSystemMonitor * monitor = [[FileSystemMonitor alloc] init];
monitor.delegate = self;
[monitor monitorPath:@"/"];
//...In your delegate class
-(void)nodeWasCreatedAt:(NSString*)path
{
printf("Created %s\n", [path UTF8String]);
}
-(void)nodeWasDeletedAt:(NSString*)path
{
printf("Deleted %s\n", [path UTF8String]);
}
-(void)fileSizeDidchange:(NSString*)path bytes:(size_t)difference
{
printf("file Added %ul bytes\n", difference);
}
Notes:
- Can monitor for Deleted files, Created Files and File Size Changes
- On an iPhone 3GS it is able to monitor the entire SVN 1.6 source tree and the iVersion source tree (total 11,050 File/Directories) in an execution time of 12s. Due to the low thread priority and the fact that the majority of execution time is IO it does not cause much/any slow down to the UI. However there is still room for improvement.
Download: