How do I save text to a flutter web app's website subdirectory and then have the app read it later? - flutter

So I have an app on website.com/app
I want the app to save a text variable, and then have the app parse the same text variable to use it later, in a different session, or even on a completely different computer.
It would be even better if website.com/app2 could access the file, but the first case is fine as well.
Would shared preferences work for this, or does every user have one shared preferences? Or does it get wiped when the website is closed?
Thanks!

What you are talking about is cross device sharing. SharedPreferences can only help you in case of a single device.
If you want to persist your value against a user across devices, you need to use some backend storage mechanism. Something like firestore which is beginner friendly.
More on it here.

Related

How to run code during app uninstall in flutter

I would like to run code to delete files created on local storage when my flutter app is uninstalled. How can I do the same? Is there any event to handle this? If not, how can I clean up the images generated?I don't see any reference online for this.
If you are saving images to users gallery, that image is no longer the domain of your app, in any way shape or form. If you create a gallery within your app this would be different, also, a gallery within your app would in fact be deleted along with any other memory your app uses. I highly doubt you could access users gallery & delete images even with users permission.
Possible backend server solution: here
This indicates this is not possible as per below:
All of your app's files are deleted by the OS when the user deletes
the app. If Apple wanted developers to have that capability, we would
have that capability 🙂
You could make a case for needing to know the app is deleted if you
are storing stuff on the server side. Currently from the server's
point of view there's no way to know whether the app was deleted or
the user just stopped using it. But locally stored files are not an
issue.
I am also looking for a solution to this & I think server logic will get it done.
Must be some sort of logic possible to discover server side if user is GONE!

How to save built in app data in swift

I am creating an app that needs to have data to be shown as soon as someone opens the app. It should be offline and not pulled from any online database. I want to add the data in Xcode, like an offline database.
Now my question is, how do I save data manually in Xcode for users without needing an online backend?
If you want something like User's data history, you can use UserDefaults class. See here for more details.
https://developer.apple.com/documentation/foundation/userdefaults
See here for an example:
https://www.hackingwithswift.com/example-code/system/how-to-save-user-settings-using-userdefaults

Is there a path every app can write files in the jailbreak iPhone?

I should hook UIResponder of every app, including SpringBoard and any others. In the hooking, I will write something to the specified file. If I set the path to /var/mobile/Library/MyApp, recommended by Cydia, I found that only the SpringBoard and MyApp could write successfully.
So is there a place every app can write and read?
I admit that I'm not 100% sure on this one, but my guess would be no, there is not a path that every app can writes files to on a jailbroken iPhone.
Certainly, jailbreak apps (installed in /Applications/) on a jailbroken phone can write to locations that can be shared between those jailbreak apps. But, as I understand your question, you would like to inject code into normal, App Store apps, so that those apps can also read and write to the shared location. That part I don't think is possible, because jailbreaking does not completely disable the sandbox for 3rd-party apps installed normally, under /var/mobile/Applications/.
Now, there might be a workaround. There are some shared folders that are accessible to all apps for certain purposes. For example, any app can write images to the saved photos album. What you could try is to take the content of the file you want to write, and encode it as fake image data, in a UIImage (e.g. with [UIImage imageWithData:]). You'd probably need to add a valid image header to the data. Then, you save the file to the photos album, using something like
writeImageToSavedPhotosAlbum:orientation:completionBlock:.
Another app could then find the fake photo by enumerating the saved photos album, and then converting the asset back to image representation to pull the real data back out.
However, this seems quite complicated, and possibly wouldn't work (I haven't tried it). Perhaps you could tell us why you want this shared file. Maybe there's a better way to share the data, without using a globally-accessible file?
Notifications can help you with this. Every app will send interprocess notifications about the events. You could start a daemon that will listen for this notifications and save them in a file. Or you could listen for them in SpringBoard as he can write, for example, to /var/mobile/Media. Depends on what you want to do with this file. Check out my answer here How to create a global environment variable that can be accessed by SpringBoard or other applications in the jailbroken iPhone?

Store and manage files between two applications?

It is possible to store some application files and share it with another application?
Can application A remove files created in such shared space by application B?
In general, no. There are a few things you can consider.
All apps can read/write/share photos via the user's photos library.
Some apps have been known to share data via the address book. That is, they put data in a special address card which can be read by multiple apps.
If the apps have matching App ID bundle seeds, they can access the same keychain entries. I'm not sure how much data can be stored in the keychain, but it is possible to share data this way.
Apps can pass data to each other via a launch URL. That is, one app can ask iOS to open a URL that launches the next app, and that URL can have parameters that pass data.
No, each application has its own sandbox. Only way to communicate is to use custom URLs to call the other application or have a 'middle man' (eg a computer).
As an alternative to RupertP's answer, the only real work-around is to use a globally-accessible server. A lot of iOS devs use MobileMe's iDisk (not free) or DropBox (free for a limited account).

When to persist data in iPhone application?

I'm currently creating an iPhone app where in one part of my app you can view your twitter stream. I'm unsure if I need to ever save the twitter information to a sqlite database or not.
So here is the flow of this part of the app:
press button to see twitter stream
go get twitter stream
display twitter stream in table view
I'm wondering if I should ever save the twitter stream into a database. Any advice?
I would say you should save the twitter stream. You should almost always try to save some application state in an iPhone app. This way, if the user is interrupted (a phone call) they can jump back into your app without missing a beat.
There are a few different ways to persist data in an iPhone app. Instead of bothering with using a SQLite database you will almost certainly want to use Core Data, which is new in iPhone OS 3.0
If you won't ask the user to provide his/her twitter credentials and it will be an anonymous stream, you don't need to store anything.
But the minute you want to store some preferences, actual state (to show the user what he/she was seeing when a phone call came or after application restart) you will need to store persistent data.
I think it's important to cache web data. With a cache, you can present data immediately on app startup - this is important on the iPhone OS because users are constantly opening and closing apps. Having your data immediately available is a big win for the user.
You can make the caching very simple, just have a single table with the URL as one column and the HTTP response as a second. Then you don't have to change any of your code to make the caching happen.
Alternatively, you will need to define a data model and manage that through CoreData or sqlite.