Skip to content
Sam Spencer edited this page Jan 26, 2021 · 4 revisions

iCloud Document Sync delegate methods notify you of the status of iCloud and your documents stored in iCloud. There are no required delegate method for iOS, however it is recommended that you utilize all available delegate methods.

iCloud Availability Changed

Called (automatically by iOS) when the availability of iCloud changes. The first parameter, cloudIsAvailable, is a boolean value that is YES if iCloud is available and NO if iCloud is not available. The second parameter, ubiquityToken, is an iCloud ubiquity token that represents the current iCloud identity. Can be used to determine if iCloud is available and if the iCloud account has been changed (ex. if the user logged out and then logged in with a different iCloud account). This object may be nil if iCloud is not available for any reason. The third parameter, ubiquityContainer, is the root URL path to the current application's ubiquity container. This URL may be nil until the ubiquity container is initialized.

- (void)iCloudAvailabilityDidChangeToState:(BOOL)cloudIsAvailable withUbiquityToken:(id)ubiquityToken withUbiquityContainer:(NSURL *)ubiquityContainer

iCloud Files Changed

When the files stored in your app's iCloud Document's directory change, this delegate method is called. The first parameter, files, contains an array of NSMetadataItems which can be used to gather information about a file (ex. URL, Name, Dates, etc). The second parameter, fileNames, contains an array of the name of each file as NSStrings.

- (void)iCloudFilesDidChange:(NSMutableArray *)files withNewFileNames:(NSMutableArray *)fileNames

iCloud File Conflict

When uploading multiple files to iCloud there is a possibility that files may exist both locally and in iCloud - causing a conflict. iCloud Document Sync can handle most conflict cases and will report the action taken in the log. When iCloud Document Sync can't figure out how to resolve the file conflict (this happens when both the modified date and contents are the same), it will pass the files and relevant information to you using this delegate method. The delegate method contains two NSDictionaries, one which contains information about the iCloud file, and the other about the local file. Both dictionaries contain the same keys with the same types of objects stored at each key:

  • fileContent contains the NSData of the file.
  • fileURL contains the NSURL pointing to the file. This could possibly be used to gather more information about the file.
  • modifiedDate contains the NSDate representing the last modified date of the file.

Below is the delegate method to be used

- (void)iCloudFileConflictBetweenCloudFile:(NSDictionary *)cloudFile andLocalFile:(NSDictionary *)localFile;

iCloud Query Parameter

Called before creating an iCloud Query filter. Specify the type of file to be queried. If this delegate method is not implemented or returns nil, all files stored in the documents directory will be queried. Should return a single file extension formatted (as an NSString) like this: @"txt"

- (NSString *)iCloudQueryLimitedToFileExtension