Database Reference
In-Depth Information
} else {
if(!_awaitingCopyiCloudToLocal){
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Turning iCloud Off"
message:@"What would you like to do with the documents currently on iCloud?" delegate:self
cancelButtonTitle:@"Keep Using iCloud" otherButtonTitles:@"Keep a local copy",@"Keep only on
iCloud", nil];
[alert setTag:3];
[alert show];
}
}
}
The start of this method is very similar to the previous one. We first check to see if we are
awaitingCopyiCloudToLocal
and
iCloudIsReady
. If it is, then we start the copy process, however
if it isn't, we check to see whether
_awaitingCopyiCloudToLocal
is set to
NO
. If it is, then we create
an
alertView
and ask the user if they would like to keep using iCloud, Keep a local copy, or Keep
a copy only on iCloud. We set the tag of this alert to 3 so we can handle it correctly and then call
show.
If we are going to copy the iCloud files to our local directory, we first set our
_awaitingCopyiCloudToLocal BOOl
value to
NO
. Then we enumerate through our
iCloudURLs
array.
We then use the same method we used in the previous method to get our
destinationURL
except
this time we pass
YES
for the last parameter.
We then create a block that will run on the background thread by calling
dispatch_async
.
We create an
NSFileCoordinator
and call the method
coordinateReadingItemAtURL:op
tions:error:byAccessor:
method. We pass in the iCloud URL and pass it an option of
NSFileCoordinatorReadingWithoutChanges
. In our
byAccessor:
block we create an
NSFileManager
object and then call
copyItemAtURL:toURL:error:
. Finally, we call the
loadDocumentAtFileURL
method passing our destinationURL.
Now let's go modify our
alertView
to handle this new alert dialog.
} else if(alertView.tag == 3){
if(buttonIndex == alertView.cancelButtonIndex){
[self setiCloudOn:YES];
[self reload];
} else if(buttonIndex == alertView.firstOtherButtonIndex){
_awaitingCopyiCloudToLocal = YES;
if(_iCloudIsReady){
[self copyiCloudToLocal];
}
}
}
Here we check to see if the user selected “Keep using iCloud.” If they did, we set iCloudOn
and then call
reload
. Next we see if they selected “Keep a local copy.” If they did we set our
_awaitingCopyiCloudToLocal
to YES. If iCloud is ready then we call
copyiCloudToLocal
. The final
selection “Keep only on iCloud” is an action we don't need to worry about because there data is
already on iCloud.
Search WWH ::
Custom Search