When a file is changed in iCloud (whether added, deleted, or the content changed), I would like to call a method I created ([self methodName]
) so that I can update my table view with the names of the new files. How am I notified of the file change? Do I need to listen for a NSNotification (if so, what is it?) or do I have to check manually? Thanks.
Asked
Active
Viewed 2,543 times
5

Jack Humphries
- 13,056
- 14
- 84
- 125
2 Answers
6
The name of the NSNotification I have to listen for is NSMetadataQueryDidUpdateNotification
. This is how I did it:
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(queryDidUpdate:) name:NSMetadataQueryDidUpdateNotification object:query];
...
-(void)queryDidUpdate:(NSNotification *)notification {
//something changed, reload (NSMetadataQuery, create NSPredicate, rerun the query, etc.)
}

Jack Humphries
- 13,056
- 14
- 84
- 125
2
This section of the Apple developer website contains a great tutorial for setting up document-based iCloud apps.
To answer your questions, though: as long as your document is a UIDocument
you can register for a notification. Just search that page for "Monitoring Document-State Changes and Handling Errors" - there is tons of source code to help you out.

Aaron Brager
- 65,323
- 19
- 161
- 287
-
Ok, there's my problem. I'm using NSFileManager to manually move things to and from my iCloud container, not UIDocument. I'll have to look into that. Thanks. – Jack Humphries Jul 02 '12 at 14:42