Database Reference
In-Depth Information
if([self iCloudWasOn]){
[[[UIAlertView alloc] initWithTitle:@"iCloud Not Available" message:@"You are currently
unable to connect to iCloud so updates to your documents will not take place until you are connected
to iCloud again." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil] show];
}
[self setiCloudOn:NO];
[self setiCloudWasOn:NO];
}
if(![self iCloudOn])
[self loadLocal];
}
The first two lines of this method are identical to what we had before. Next we disable the add
button because we don't want the user to have the ability to add while we are pulling our data.
In the next line we check to see whether iCloud is available. If iCloud is available, we then check to
see if it is not on and we have not prompted the user. If we pass that test, then we start by calling
our setPromptForiCloud: method with a value of YES . We follow this by creating an alert view that
will prompt the user to determine whether they want to use iCloud. We set the tag to our alert to 2 so
that we can handle it correctly in our alertView:clickedButtonAtIndex: method.
We then check to see if iCloud is on and if iCloud was not on previously, which lets us know that the
user just turned iCloud on for the first time. If that state is true, we have a TODO item that we will
write later that will move the local data to the iCloud container. We follow that with an else if to check
whether iCloud is not on and iCloud was on previously signaling that the user has just turned iCloud
off. If this state is true, we have a TODO item that we will write later that will handle copying data
from the iCloud container to our local directory. We follow up all this by calling our setiCloudWasOn:
method with the current value return from iCloudOn.
If the iCloud is not available, we first call our method setPromptedForiCloud: and passing NO . We do
this because we want to make sure that if the user hasn't had a chance to turn iCloud on they will be
prompted once iCloud is available.
Next we check to see if iCloudWasOn so that we can alert the user and let them know that iCloud
is currently not available. We set the delegate to nil on this alertView because we are just
notifying the user and not expecting any decision to made by them. We then call setiCloudOn and
setiCloudWasOn to NO because it isn't available. Setting these values is what allows the user to work
locally, but then when iCloud connectivity is regained any local data will be pushed to iCloud.
In the last piece of code we check to see whether iCloud is on. If it isn't, then we call our loadLocal
method to load our local data. Now let's move on to our alertView delegate method and handle the
alertView whose tag we set to 2. We will add an else if statement like this:
} else if(alertView.tag == 2){
if(buttonIndex == alertView.firstOtherButtonIndex){
[self setiCloudOn:YES];
[self reload];
}
}
 
Search WWH ::




Custom Search