iOS - save data so that it is easily accessible outside of the app - ios

Is there any way to save a file (to be exact, a .csv) somewhere outside the application sandbox? From what I've read it seems like it is only possible to save files inside the sandbox.
Maybe I'm thinking about it the wrong way, maybe I don't really need to save it outside the sandbox. What I actually need to do is:
Allow the user to save the file, so that he can use it in other applications (for example email client), and it would be best if the file would stay on his device after he deleted the app. The location of the saved file doesn't really matter, it could be chosen by user with some file picker or hard-coded. Is there any way to achieve this?
I'm using xamarin.forms so solution easy to implement in xamarin.forms would be much appreciated.

From what I've read it seems like it is only possible to save files inside the sandbox.
That is the general idea. You don't just have access to the filesystem on iOS. You could work around this by maybe saving it to iCloud or Dropbox, etc. depending on your use-case but basically you can't just save it somewhere common. Normally, you would then implement the 'share' functionality. What happens then is that iOS copies the file into the other apps' sandbox so it can work with it.

Related

Where to save my iOS app's save files

I am learning iOS file system to store my game data like saving the amount of money earned and things like this in a xml file.
The question is where should I store them?
I read this: File System Basics
And I don't know that I should save data in Documents directory or Application Support directory.
Because the data I want to save is something that is not associated with user's documents and user will never see it so it should be in Application Support, but on the other hand it's something that is affected by user interactions so it should be in Documents.
I think it is the Application Support/MyGame as per the Apple Developer guide link shared by you. You are confused by the fact that it should not be something affected by user interaction. Actually it means user should not directly interact with these. See this from the link: File System Basics
Using something like Parse may slow down your app as it needs to interact with their server, but you do get a backup.
For something of this size, I'd use a mobile backend solutions provider like Parse or Firebase. Personally I use Parse in my projects and is very easy to implement advanced functionality into your apps like user registration/save data to users.
Hope this helps.

Where to store user settings in Electron (Atom Shell) Application?

I can't seem to locate a built in mechanism to store user settings. I was hoping that electron provided a standard method for storing user settings across all desktop platforms. If there isn't a precedent for this I can implement it myself, I just didn't want to jump to a custom solution immediately. Research online is pretty sparse in this area. Thanks!
Each platform has different default locations for different kinds of data. So, if you want to store data in default locations based on platform, check out app.getPath(name)
It retrieves a path to a special directory or file associated with name.
You can also use it to differentiate between data the user wants to save, and data your application saves that you don't want to clutter up users directories.
Or if you just want to store files reletive to a specific path you can use the
app.setPath(name,path)
I've faced this particular problem with my Electron app and this post inspired me to write an NPM module called electron-json-storage.
This module allows to easily write/read JSON to/from app.getPath('userData'):
const storage = require('electron-json-storage');
// Write
storage.set('foobar', { foo: 'bar' }).then(function() {
// Read
storage.get('foobar').then(function(object) {
console.log(object.foo);
// will print "bar"
});
});
Electron doesn't give you anything out of the box for this. However, Electron does give you a method for getting the idiomatic location of storing user data in a cross platform way via the app.getPath API.
I'd say the 3 most common ways to do this are:
localStorage (or any HTML5 storage API)
flat JSON file (this is what I do, and I use electron-store for it)
embedded database like IndexedDB, neDB, or sqlite
Which one you choose will depend on your app's needs. If you only need to access this data in the renderer process, then I'd just use localStorage. Most of the time it seems you need to access the data in both the main and renderer, so a JSON file makes sense. If you're dealing with lots of data or complex querying, then maybe a database makes sense. I wrote about this more in detail here.
How about LocalStorage? If you need to access these settings from the browser process, you probably need to write your own (or just use a node.js library that implements this)
The best way that I have found is to store it in a simple file as JSON. The problem is that if you store that JSON in the app dir, then when you update the app, it will get wiped out. So you want to put it in the default directory for user settings for the current operating system. LUCKILY!!!!! There is a library for node developers that will help you find the userdata directory. The module is called appdirectory, and I have used it several times. It is extremely easy to use.
See APPDIRECTORY HERE
One could store data in cookies; Electron has a mechanism for it (https://electronjs.org/docs/api/cookies) and the cookies can be retrieved in the browser (Angular: https://docs.angularjs.org/api/ngCookies/service/$cookies, React/Other: https://github.com/reactivestack/cookies)
I was able to get it working with Angularjs.

Saving files with iOS. Where do they go?

I have saved a text file from my app and I can open it again, but is there any way the user can gain access to this file to just do whatever they want with it? I tried printing the path which looks like this : /var/mobile/Applications/2DD5A15B-9BC8-4981-A1F6-E22F66C71CA4/Documents/ I'm assuming that huge number is some type of app identifier, which leads me to believe that this file isn't going to be accessible unless you're in the app. Which makes me wonder, why would writing a file be any better than just saving a big string to NSUserDefaults?
I am building an app where the user should be able to do some data logging. If the user can sync their phone with their computer and download the file that would be awesome. Can you do that? Or do I have to build in functionality so that they have to email themselves the file or something?
I'm assuming that huge number is some type of app identifier
It is. It's an UUID.
which leads me to believe that this file isn't going to be accessible unless your in the app
...unless you are in the app (or, unless the device is jailbroken, in which case it's plaintext for anyone interested).
why would writing a file be any better than just saving a big string to NSUserDefaults
Conceptually, it's not a setting. If you have some data, an entity, then write it to a file. NSUserDefaults is not appropriate for storing large amounts of data. It's for storing user preferences (which are volatile!), nothing else.
made of the concept of iOS this is also called sandboxing.
if this would not exist, it could be possible to change or getting data of other apps.
If the user can sync their phone with their computer and download the file that would be awesome. Can you do that? Or do I have to build in functionality so that they have to email themselves the file or something?
you can use the awesome iCloud.
check here:https://developer.apple.com/icloud/index.php

How to save file from web application to user's disk?

I'm working on web application which, among other things, needs to save small file to particular folder on user's hard drive whenever user clicks a button. That file will serve as input for another desktop application so it must be saved in predefined folder and predefined format. "Save as..." and save dialog would be very inconvenient. Also setting that all downloads go to that folder would be troublesome.
Also, changing desktop application is not an option.
In current stage of web browsers and web standards what would be the best approach?
Is it development of custom plug in for browser? Or flash/silverlight? Something else?
First of all this is not doable via http and html.
If this is a controlled environment maybe you could get away with simply providing a customized portable firefox to your users. Of course, all other downloads would go to that folder as well.
Anything thats loaded from a website isn't allowed to access the computers HD, and with good reason.
That aside; Could you give it a new extension and associate a program with it that saves it in the correct place, all the user then needs to do is check 'always do this action' or something to open the file with the program when the button is clicked.
Perhaps a different approach would be to have the desktop application retrieve the file from your web-application when it needs it - is this feasible?
This approach means you need not concern yourself with the sandboxing protection of web browsers that prevent web-applications knowing too much about the clients file-system.

Accessing Word documents in a Rails app

I have a number of documents (mainly Word and Excel) that I'd like to make available to users of my Rails app. However, I've never tried something like this before and was wondering what the best way to do this was? Seeing as there will only be a small number of Word documents, and all will be uploaded by me, do I just store them somewhere in my Rails app (i.e. public/docs or similar) or should I set up a separate FTP and link to that? Perhaps there's an even better way of doing this?
If they're to be publically accessable, you definitely just want to stick them in public somewhere. Write a little helper to generate the URL for you based on however you want to refer to them in your app, for cleanliness (and so if you do change the URL later, for example to bucket your files to keep your directory sizes under control, you don't have to change links all over your app, just in one place.
If, on the other hand, your files are only for logged-in users, you'll need to use something like send_file to do the job, or one of the webserver-specific methods like the X-Sendfile header to check the user is authorised to view the file before sending it back to them.
I would do as you suggested and put them in public/docs. If you are planning on making an overview/index page for the files and link directly to them it would be easier if they were stored locally instead of a remote FTP server. However, since you are the one who will be uploading and maintaining these files, I think you should go with the option that's easiest for you.

Resources