Database Reference
In-Depth Information
Now, let's go to the two spots that we have TODO #1 and change them to read:
[self moveLocalToiCloud];
And change our TODO #2s to read:
[self copyiCloudToLocal];
And let's change our TODO #3 to read:
[self queryiCloud];
Finally let's add the following two lines at the beginning of our reload method.
_iCloudIsReady = NO;
[_iCloudURLs removeAllObjects];
Now we need to modify our
getDocumentFilename:forLocal
method so that we are handling a value
of
NO
for the last parameter. Currently we only check to see whether the value
isLocal
is
YES
. We
need to add an else to that statement so we can check to see whether the name exists in our iCloud
container. The
if
statement should now look like this:
if(isLocal){
nameExists = [self documentNameExistsInObjects:newDocName];
} else {
nameExists = [self documentNameExistsIniCloudURLs:newDocName];
}
We are calling a new method here
documentNameExistsIniCloudURLs:
. Let's write that now.
-(BOOL)documentNameExistsIniCloudURLs:(NSString *)documentName {
__block BOOL nameExists = NO;
[_iCloudURLs enumerateObjectsUsingBlock:^(NSURL *fileURL, NSUInteger idx, BOOL *stop) {
if([[fileURL lastPathComponent] isEqualToString:documentName]){
nameExists = YES;
*stop = YES;
}
}];
return nameExists;
}
This is an identical method to
documentNameExistsInObjects:
except here we are enumerating
through the
iCloudURLs
array.
The last thing we want to do is to add our self as an observer to the
UIApplicationDidBecomeActiveNotification
. We do this in the
viewWillAppear:
method. We add an
enableUpdates
call on our
NSMetadataQuery
object as well.
Search WWH ::
Custom Search