Database Reference
In-Depth Information
[[NSNotificationCenter defaultCenter] removeObserver:self
name:NSMetadataQueryDidUpdateNotification object:nil];
[_query stopQuery];
_query = nil;
}
}
The
queryiCloud
method starts out by calling our
stopiCloudQuery
method which does exactly that.
We will go into more detail on how it does that shortly. Then we call our
documentQuery
method that
we just created and assign the return value to our private
_query
property. But, we haven't created
that so let's do that now. In the private interface add this line:
@property (strong) NSMetadataQuery *query;
Now that we have our query property created and assigned let's move on. In the next two lines we
add our self as an observer for two messages that will be fired by our
NSMetadataQuery
. They are
NSMetadataQueryDidDidFinishGatheringNotification
and
NSMetadataQueryDidUpdateNotification
.
We tell notification center that when these messages or notifications are fired we want to call our
processiCloudFiles:
method. We will write that shortly. We end our method call by calling the
startQuery
method on our
NSMetadataQuery
object.
Our
stopiCloudQuery
method is similar. We first check to see if query is not nil. If it is, then we
remove ourselves as the observer for both of the messages we subscribed to earlier. Then we call
stopQuery
on our
NSMetadataQuey
object and finally set our object to nil.
Before we can write our
processiCloudFiles:
method we need to add a few more private properties.
In the private interface add the following:
@property (strong) NSMutableArray *iCloudURLs;
@property BOOL iCloudIsReady;
@property BOOL awaitingMoveLocalToiCloud;
@property BOOL awaitingCopyiCloudToLocal;
Let's also not forget to initialize the
iCloudURLs
array. In your
viewDidLoad:
add an initialization for
iCloudURLs
just above the line where you initialize your entries array.
_iCloudURLs = [NSMutableArray array];
Now we can write our
processiCloudFiles
: method.
-(void)processiCloudFiles:(NSNotification *)notification {
[_query disableUpdates];
[_iCloudURLs removeAllObjects];
[[_query results] enumerateObjectsUsingBlock:^(NSMetadataItem *item,
NSUInteger idx, BOOL *stop) {
NSURL *fileURL = [item valueForAttribute:NSMetadataItemURLKey];
NSNumber *aBool = nil;
Search WWH ::
Custom Search