iOS - Allow user to download file from documents directory but not to upload file using iTunes - iphone

Here is a situation I have a data file in document directory which is being updated in the application every now and then. So I want to save it to my desktop using iTunes. But I don't want that the file should be uploaded back to my application. i.e. I want that user can download the file but can not upload any.
I was thinking to have the data file on some other location like Library and put a button on application settings saying "Prepare backup" that will copy that data file in Document directory, from where user can download it. If user uploads any thing it won't make any difference as my current file is in Library directory.
This is just a thought,
can anyone suggest me other way or the above way is good to go?
Edit: I just need that after the successful export user can view the data file (may be later) without support of the application.

You can't.
But what you can do is check (using an timer every 10 seconds) if a new file is added to the documents directory and then delete it programmatically.
But this ofcourse doesn't disable the replacement of files.

Related

Write a File into the App Bundle

I have a Webservice to download some News and write them into a plist-file somewhere in NSLibraryDirectory, thats fine. But if the user has no Internet connection or the webservice is offline or whatever, I load a Default-Newsfile from within the AppBundle.
At the moment I have to replace the Default-File manually before every AppStoreUpdate to keep it up to date.
My Question: Is there an easy way to write into the App Bundle while debugging via Simulator, so the Default-File will everytime be up to date.
I tought about something like:
#ifdef SIMULATOR
//Write to AppBundle
#endif
Note:
It's all about the time while I use the Mac and the Simulator, I don't want to do that in the Published App!
Yes, I already replace the Ressource in my Bundle, but by hand and I want it to realize automatically.
I want to keep my Projectfolder up to date, before I compile it for any Device or the AppStore.
AppBundle is Read-only you cannot write anything to it programmatically, however if you update the resources in your Project through Xcode, you get the updated file automatically in the AppBundle..
Ok, based on your comment, here's what you need (I think - still not completely clear on the question, but let me know if this works for you).
Create an empty file (say news.plist) in your project folder (SRCROOT). Add this to your repo.
Add this file in your project's resources and add it in Copy Bundle Resources step in Build Phases
When you download content from internet, save it to project's temporary folder, then copy it to SRCROOT/news.plist overwriting existing file (optionally add a check on file checksum to avoid unnecessary change). This step is required ONLY when running on simulator.
Whenever developers check-in, the updated news.plist should be checked in to the repo.
To make SRCROOT available in code, add SRCROOT=\"${SRCROOT}\" to GCC_PREPROCESSOR_DEFINITIONS.
Other developer won't need to do anything except the last step - check in the updated file every time it changes.
Does this help?
No, you might be possible to get the simulator to write to you App Bundle, but this does not mean that the file your project (the one that gets compiled when you build for the app store) will be updated.
Why not just save the new to the documents directory, then always load this file. After the app is started, start a background thread and try to update the plist file. Of you are successful in retrieving the news over the write the plist file in the document directory.
This way the user will have an file that was retrieved the last time the device was able to get the file.
You could add an file in the app bundle which you copy to the documents directory on first start of the application, just to make sure that the user has data in the app.

iOS Documents with UIFileSharingEnabled

My iPhone app uses a sqlite3 database for storing the data that it generates. This data needs to persist, and I need to make sure the user cannot damage it. I also want to allow the user to export data as text/csv files, these would be shared through iTunes. I plan to put the database in the Library folder, write the CSV files to the Doucments folder, and turn on UIFileSharingEnabled.
Is there anyway I can stop the user from adding files to my apps Documents directory through iTunes?
If not, it is acceptable practice to have my app delete any files that it did not create?
Is there anyway I can stop the user from adding files to my apps Documents directory through iTunes?
No
If not, it is acceptable practice to have my app delete any files that it did not create?
Of course not. Why do you want to do this anyway? If you use the documents directory for exporting only, simply ignore anything that's inside.

iTunes file sharing - how to upload different folders?

i want to use the "file sharing" feature in my app. I want to create a photo-app which has no content when the user starts it. Therefore the user can select an image-folder on his mac or pc. After that and starting the app on his iphone or ipad, all the content of his image-folder will be viewable.
I think its only possible to add simple files to my app - not content folders, right?
Any ideas how i could do this?
Thanks for your time and help.
On your mac, rename the folder to folder.pkg.
You can now add folder.pkg to the documents for your app using iTunes File Sharing.
Once folder.pkg has been added, rename it to its original name.
Not sure how to do this with iTunes on a PC.
You cannot upload folder to the app.
one way to do so
create .zip file of that folder and upload.
extract that zip file from app.
checkout this project, It has a code to extract zip file.
https://github.com/ZipArchive/ZipArchive
I found that using iTunes 12, and iOS8, I can now ADD folders to an apps Documents folder using iTunes File Sharing. Previously it was only possible to add single files.
It is indeed possible to add a folder to and App's File Sharing space using iTunes version 12+. However, the iTunes upload button will not work for this, because its file selection interface insists on plain file selection only, excluding folders. The way which works is to drag-and-drop a folder from your PC to the iTunes File Sharing window.
Since the iTunes interface for handling file sharing is very poorly designed, is is worth recalling the tricks that you can use to perform operations on the File Sharing space, that iTunes does not provide a button for:
Rename a file or folder: click it once, wait for a couple of seconds, and click it again. This will replace the name with the renaming edit box
Delete a file or folder: select it, then hit the "Del" key on your keyboard
Upload a folder: drag-and-drop it from your computer copy
It remains impossible to directly see or alter the contents of a File Sharing folder in iTunes. My workaround for doing this is the following:
Download the folder to the computer
Make any desired change to the folder tree on the computer copy
Delete the File Sharing copy of the folder (or, optionally, rename it to something like folder.old for safety)
Upload the modified folder from the computer, using drag-and-drop
(optionally) Delete the safety copy in File Sharing, after verifying that the App works fine with the newly uploaded version of the folder
I hope this helps
I was not able to drag-and-drop a folder from my PC (Windows 10). But I found a free application called iFunbox that allowed me to copy a folder to an application's documents.

Shipping Documents Items with an iPhone App

My iPhone app uses a small database to store its settings and saved files. How can I ensure that the default database, with its default settings, gets distributed to anyone who downloads it along with the application files?
EDIT Sorry, I was in a rush when I posted this. I forgot to mention that the database needs to end up in the 'Documents' folder of the application so that it can be backed up at a later date by the user.
-Ash
Put it in "Resources". Then on your first launch, you'll need to load that file out of your mainBundle and save it to the Documents directory. The file will "come with" the app, but it won't live in the right place to get caught by backup.
A side-effect is that restoring the app to factory settings is as easy as deleting that file. Next launch, you can see you don't have your file, and copy a fresh one out of your bundle.
You include it as a file in the Resources folder of your application.

Replace existing XML file within iPhone app

I have an .xml file that is going to be shipped within my app.
This file contains values that are read from it and saved as an array when the app launches.
Each time the app is run, I want to check with the server if there is an internet connection. If so, I want to get the newest version of the .xml file from the server and replace the one that I currently have saved in my app (this way, the next time the user logs in and doesn't have internet access, he/she will be able to use the old (yet most up to date) data).
What is the best way to do this?
Thanks,
The best way to probably do this is to copy the XML file from the app bundle to a location in the app's sandbox, e.g. the Documents folder. Thereafter you can update the XML content as necessary with newer data from the server. The copy is necessary to allow you to write to the file, since you cannot change the content of your app's bundle because it is signed.
Alternatively, if the data is simple enough, you can just save it to user defaults on first launch and change the defaults on subsequent updates
I might skip the XML altogether, unless it contains a baseline of default settings, and just sync user defaults over the Internet. You can't modify files in the bundle, so your only option would be to copy over a "default-settings" XML file to the application's Documents folder to make it editable.