Can I download and rename a file from .abc to .json in my app? - iphone

I would like to take a json file (.json) and rename it to my app's file type (.abc) and then attach it to an email and then open this file up in another instance of my app and then read this .json file.
Would this be possible? i.e. can I take this file save it and rename it back to .json and then read it using a json parser all within my running iOS app?

Short answer is yes, but why bother with extensions? Anyways, take a look at these NSFileManager methods :
– replaceItemAtURL:withItemAtURL:backupItemName:options:resultingItemURL:error:
– moveItemAtURL:toURL:error:
– moveItemAtPath:toPath:error:

Related

Imported packaged files ".key .numbers .pages" from iCloud using UIDocumentMenuViewController are not opening in UIWebView

Hi I am trying to display a packaged file say .key/.pages/.numbers file to user in a UIWebView but I cant. The keynote file was created using a Keynote app from my iPad recently. I imported that file to my app using UIDocumentMenuViewController from iCloud. I tried to look into the file attributes and it turn out that the file imported is actually a "directory" not single file. Inside, it has some contents. Can anybody tell me how to go from here?
I had the same problem. iWork files are zipped bundles but for some reason importing from iCloud unzips the contents first, whearas copying from the app directly via Open in ... from Number (or Pages or Keynote) works perfectly.
So what you need to do is test if the result of import is a directory, and if so zip the directory into a single file and keep the correct file extension (.number pages or .key).
This seems like a hack but it works and is best workaround I've been able to find
In Swift you can use SSZipArchive as an easy way to zip a directory

Reading/writing data to encrypted custom file type

I'd like to create a custom file type, say, .cstm, and be able to create .cstm files on the mac, and read them on the iPhone.
I want the .cstm file to contain XML data. Currently I've got the mac app to successfully make .xml files and the iPhone app to successfully read .xml files, but I'd like to create a proprietary custom file type.
How would I go about doing this? I know how to allow the iPhone app to open a custom file type, but that's as far as I know.
Thanks!
You don't need anything special per se. You can just save and load to the URL with the ctsm extension. To support your app automatically launching as an editor of that extension in OSX, you will want to add an entry to your Info.plist file CFBundleDocumentTypes array entry declaring your app as an editor of that extension
https://developer.apple.com/library/mac/#documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html#//apple_ref/doc/uid/TP40009249-101685-TPXREF107

File Name form NSFileHandle

I am using an third party SDK for file handling, they have given some handles for file open, file read, file write. When i create the object of wrapper of that SDK using file path its calls those handle methods (File open, file read etc.).
I want to change the data of file at the time of reading it. But the SDK open multiple supporting files so i am not able to find is it my file in read state or some other file.
They have provided the object of NSFileHandle in there read method is there is any way i can find out is it my file or supporting file using file handle object or is there is any other way around.
Please suggest me the solutions.
Regards:

Naming a file downloaded from url in iPhone

I would like to save a file downloaded from the internet in iPhone.
Can I use the url as the file name? If not, what transformation should I apply to the url to obtain a valid file name?
I need to find the local copy of the file later using its url.
Edit: Not asking where or how to write a file to disk. The question is limited to getting a valid file name from an url.
Can I use the url as the file name?
You can use just about anything you want for a file name. As long as it's a valid file name for the underlying file system.
If
not, what transformation should I
apply to the url to obtain a valid
file name?
This is unanswerable because there's no way to specify what "valid" means here.
I need to find the local copy of the
file later using its url.
You probably want to save it to your application's Documents directory. There already are plenty of questions relating to saving files on iPhone here on Stack Overflow, and I urge you to read some of them.
For lack of a better method, I'm using a persistent dictionary to map the urls to unique names.

how to creating localizable.strings file by code in iPhone

I am working on one multilanguage project which will download string from server depend on language selected by user. I would like to save this downloaded string into localizable.string file. So how could I do that? I know how genstrings works but I would like to generated *.strings file by code and save it. My code will read this *.strings file for localizable. Anybody know which api i have to use?
thanks in advance
Manu
Typically, localization depends on strings files that are within the app bundle. Since you can not modify the app bundle at run time, you will have to put the strings files you downlaod elsewhere and you will have to modify the usual localization methods to find and use those strings files.
Look at Apple's iPhone samples to see how they do localization and fetching of the strings, and see if you can replace all the local accesses of the localization resources with resources in another directory.