Folderitem iOS

I know I can save files with for example
Dim myFile As FolderItem = SpecialFolder.Documents.Child(“file.txt”)

But are there some good guidelines which special folders are iOS only?
Can I use any file extension?
Are there any restrictions if file format? File size?

All the methods listed on SpecialFolder are iOS only, but I see little reason to use anything other than Documents.

Any files you save can only be accessed by your app, so it doesn’t matter what the extensions or types are. There are no file size restrictions, beyond what is available on the device. But remember Apple still sells iOS devices with as little as 8GB of storage.

[quote=151590:@Paul Lefebvre]All the methods listed on SpecialFolder are iOS only, but I see little reason to use anything other than Documents.

Any files you save can only be accessed by your app, so it doesn’t matter what the extensions or types are. There are no file size restrictions, beyond what is available on the device. But remember Apple still sells iOS devices with as little as 8GB of storage.[/quote]

Each folder has a distinct purpose and the documents folder should only be used for the user’s documents.

[quote=151532:@Christoph De Vocht]I know I can save files with for example
Dim myFile As FolderItem = SpecialFolder.Documents.Child(“file.txt”)

But are there some good guidelines which special folders are iOS only?
Can I use any file extension?
Are there any restrictions if file format? File size?[/quote]

As far as I experimented, the use of SpecialFolder is identical to Mac OS X. Documents is a bit special since you can set your app to use sharing so the user can manage files in there through iTunes.

As far as extensions are concerned, it is just like OS X. Basically, as once said here, iOS is Mac OS X with a funny hat :wink:

So basically if you want to save some preferences, you choose ApplicationSupport.
Is it obligated to use .plist files for this folder? And does iOS saves his own plist file here?

And if you want to write some database stuff, use documents.

[quote=151678:@Christoph De Vocht]So basically if you want to save some preferences, you choose ApplicationSupport.
Is it obligated to use .plist files for this folder? And does iOS saves his own plist file here?

And if you want to write some database stuff, use documents.[/quote]

Use the same rules as OX S and you will be fine. I use a subfolder inside ApplicationSupport where I put all I need. I never use XML ; I was invented before it existed. Whatever is in the subfolder that belongs to my app is my business.

OK, seems logical.
But I just wondered if Apple can reject your iOS app because you wrongly use saving files. :slight_smile:

[quote=151707:@Christoph De Vocht]OK, seems logical.
But I just wondered if Apple can reject your iOS app because you wrongly use saving files. :)[/quote]

Reviewers can be strange, but I would be surprised they would be that psycho. Yet :wink:

It appears that writing a file to ApplicationSupport is not yet supported on iOS. It throws an exception when I try. I’m enabling File Sharing and do not want the user to have access to the preferences file (currently being saved to the Documents folder; only choice apparently). Will writing to the ApplicationSupport folder be possible eventually?

You are right. Trying to create folder in ApplicationSupport crashes.

That said, placing that in documents should not be such an issue if you do not use file sharing. The documents folder will only be accessible to your app sandbox container. You could also try, if you use file sharing, to add a dot before the name of the folder, which should make it invisible. I just tried, it writes and reads fine inside.

Excellent idea! That should solve the problem. I’ll give it a try.

Thank you!

Apples recommended method for storing “user prefs” is NSUserDefaults.standardUserDefaults()

func LoadOptions() {
    if let test = NSUserDefaults.standardUserDefaults() as NSUserDefaults? {
        option_SOUND    = getOption("Sound",option_SOUND).boolValue
// add more variables here as required
    } else {
        SaveOptions()
    }
    set_mode_bits(mode_bits)
}


func SaveOptions() {
    putOption("Sound",option_SOUND)
}


// this is NOT Private so App can save One option at a time is required
func putOption(key:String, optionValue:AnyObject) {
    userDefaults.setObject(optionValue, forKey: key)
// Apple suggests each option be stored at the time it is modified, since there is no real "close" event
}

private func getOption(key:String, defaultValue:AnyObject) -> AnyObject {
    if let retValue:AnyObject = userDefaults.objectForKey(key) {
        return retValue
    } else {
        putOption(key,defaultValue) // insure the option exists in pList
        return defaultValue
    }
}

[quote=156687:@Dave S]Apples recommended method for storing “user prefs” is NSUserDefaults.standardUserDefaults()
[/quote]

Yes, I know. I use this method in my ObjC iOS apps. I’m waiting for someone to make NSUserDefaults available to Xojo. A declare wizard I am not.

I used Jason King’s wonderful DeclareMaker app to create the class. Maybe this will be easier for you who are familiar with it :

NSUserDefaults.xojo_binary_project.zip

And if it works, you could give an example of how to add custom variables the way Dave showed it in Swift ?

Ah! I’ll play with it and see if I can make it work. If so, I’ll post some code. Thanks again, Michel.

It should work. Please file a bug report for whatever you’re seeing not work.

Please file a bug report.

[quote=156698:@Joe Ranieri]@Michel Bujardet You are right. Trying to create folder in ApplicationSupport crashes.
Please file a bug report.[/quote]

<https://xojo.com/issue/37590>

I’d like to raise this from the dead… I am writing a logfile to the Documents specialFolder on iOS, but can’t locate it using Apple Configurator 2. Any idea on how to make this accessible?

You can access it with itunes. But you have to have UIFileSharing entry in your info.plist file in your application

So I’ve added

UIFileSharingEnabled

to my Info.plist; run the app (which generates the logfile fin in Simulator) on the iPad, but neither the app or a Documents folder/logfil shows up in either Configurator 2 or iTunes - just the usual suspects - Numbers, Kindle, etc.