GetTemporaryFolderItem Equivalent

I need a temporary folder item in iOS. I can use SpecialFolder.Temporary to get the location of the temporary folder, but I also need a name for the temporary file. In desktop I would use GetTemporaryFolderItem to return a temporary filename in the temporary folder.

Is there an equivalent or has anybody come up with an alternative for iOS?

You could use the current date (and time) as the file name so that it will be unique.

Since its temporary & unique to your app (see https://developer.apple.com/library/ios/documentation/FileManagement/Conceptual/FileSystemProgrammingGuide/FileSystemOverview/FileSystemOverview.html) the current date time & nanoseconds or something like it should be unique.

Or you can get at NSProcessInfo globallyUniqueString or NSUUID UUIDString.

Thanks guys. I like the idea of the date so I’m doing:

SpecialFolder.Temporary.Child(Date.Now.SecondsFrom1970.ToText + ".jpeg")

Given that it’s very temporary and in my app’s sandbox I think that should be fine.

Does anybody know whether the iOS temporary folder is automatically cleaned up?

I’ve tried cleaning it up myself but if I do:

resavedImage = iOSImage.FromFile(tempFile)
if tempFile.Exists then tempFile.Delete

I am finding that the tempFile is deleted before iOSImage.FromFile has completed loading the binary, so I only get part of an image. Removing the Delete call solves the problem but leaves the temp file behind.

read the link I posted
It specifically says exactly

tmp/
Use this directory to write temporary files that do not need to persist between launches of your app. Your app should remove files from this directory when they are no longer needed; however, the system may purge this directory when your app is not running.
The contents of this directory are not backed up by iTunes.

Sorry Norman :frowning:

NP
I might be a tad grumpy today

The problem is that initializing the IOS Image does not load right away. The system may load the image when needed. If memory is low, it may unload it. So you need the file to continue to exist.