Folder in iCloud or Documents synched to iCloud

I want to find out 2 things:

  • if a folder is in the iCloud folder. That was some folder “mobile documents” as far as I remember.
  • if the Desktop and the Documents are synched to iCloud. User wanted to archive emails and wondered why everything was so slow.

For both cases I want to show warnings. Of course, the users always know better than us developers and love the synchronised folders.

Good idea to show warnings indeed. iCloud is (compared to Dropbox and others) incredibly slow. For all services where I do rely on a stable and fast synchronisation iCloud is unfortunately still not an option for me. As to your question I don’t find anything in my notes right now, but I remember that iCloud is creating some folders under Library … ~/Library/Application Support/ … cloudDocs? MobileSync? Hope googling around this will help you.

@Christian_Schmitz : is this somewhere in the MBS plugins?

Below is the following code I use to check to see if something is being synced with iCloud. I am sure Christian can provide the MBS equivalents.

if NSUrlGetResourceValue( destination.NSURL, rValue, NSURLIsUbiquitousItemKey, error ) = false then
  errorMessage = "Unable to determine iCloud status: " + NSErrorLocalizedDescription( error )
  
elseif NSObjectIsKindOfClass( rValue, NSNumberClass ) = false then
  errorMessage = "Unable to determine iCloud status: Not a number, but a " + NSObjectClassName( rValue )
  
elseif NSNumberBoolValue( rValue ) then
  errorMessage = "is being synchronized with iCloud"
  
end if

I’m already using the code below to check if a file needs to be downloaded from iCloud:

Dim theURL As New NSURLMBS(theFolderitem)

dim value as Variant 
dim error as NSErrorMBS
Dim result As Boolean = theURL.getResourceValue(value, theURL.NSURLIsUbiquitousItemKey, error)
#Pragma Unused result

'not an iCloud file
if value = Nil then Return False

'iCloud files
if value.IntegerValue = 1 then
  
  'don't care about the trash
  if theFolderitem.Name = ".Trash" then Return False
  
  'normal file
  Return not theFolderitem.Visible
  
elseif value.IntegerValue = 0 then
  
  'invisible files like dsstore
  Return False
  
end if

So I just take out the visible check for “value.IntegerValue = 1” - I think.

It certainly appears to do the right thing, but yeah I would remove the check for “.Trash” and visibility from this function, so that it only tells you if the file is being mangled by iCloud.

May I make some suggestions (that I’m trying to recall to do myself)?

Checking the "result’ to make sure that the getResourceValue call worked. If it is is false, then handle the error. Just in case Apple change the key names next week, so you get some information, rather than your code thinking that this file is not iCloud.

Checking the “value” type as Apple have a habit of changing the return values from API, this way if they do, the error will let you know they have rather than falsely believing the file isn’t in iCloud.

if the getResourceValue call returned true, but “value” is NIL, then Apple are now returning a data type that the MBS doesn’t convert to a variant, so check for that if it is not numeric.