How to: upload user files to iCloud + retrieve files from iCloud? (Nativescript) - nativescript

In my iOS nativescript app, I want users to be able to upload files to iCloud and also retrieve them from iCloud. So it would work like other apps, such as photos, where you can save your photos and retrieve them from iCloud.
The goal is to remove stress on phone storage.
Is this possible?
I earlier asked a question regarding backing up all app data to iCloud (link). It looks like this is possible--users can add the app to an iCloud backup. But this is different than what I am asking here. In that case, a user would have to retrieve all of their phone's data from the backup.
Here, I am looking for a way for users to (1) upload just specific types of files (say, pdf files or media files) to iCloud that they could later (2) download into the app itself.
In other words, they could choose to save and access files using iCloud instead of storing them locally on their phones.
I have seen this question asked earlier on nativescript forums and stackoverflow, but without answers.
So any help is appreciated.

Related

Xamarin Essentials Share does not have load option

My app backs up its data in a zip file that uses Share.RequestAsync to store the file. This works great because it presents all the possible sharing options including email, messaging, and cloud devices like Google Drive, Dropbox, etc.
In order to load that zip file from wherever it was stored I use FilePicker.PickAsync. The problem is that this presents a very limited number of options for selecting the file. It offers either the local device or a single cloud service (iCloud on iOS or Drive on Android). What if I want to restore the zip file from Drive in my app on my iPhone?
Why is there such a difference in the xamarin share options when it comes to saving and loading files? It seems like the Share class should offer a method to load files that presents the same options that it does for sharing. Or at least the FilePicker.PickAsync should present the same interface as Share.RequestAsync for load options. Am I missing something?
Here is what the share dialog looks like compared to the file picker on iOS. It is similar on Android. The share offers access to iCloud, Drive and Dropbox while the picker only offers access to iCloud.

codenameone downloading files/images visible to other apps

I note that other apps (testing on Android) like WhatsApp, etc have folders that contains images the user has used/downloaded. These folders (like WhatsAppImages) are visible in other apps (Gallery/File Explorers, etc) so you can use those files to share, delete, etc like any other file.
In my codenameone app I download image files but they cannot be seen anywhere on the local device. I understand that for security apps run in a sandbox and this may be why.
But how do these other apps make their downloaded files visible to the general file system and other apps ?
Many Thx
Codename One doesn't support that at this time but you can use native interfaces to add this as explained here for Android: How to save image in android gallery
and here for iOS: How can I save an image to the camera roll?
You can also file an RFE to add this either as a cn1lib or API.

When can I use Photos Framework and iCloud Photo Library?

I want to provide my users a photo picker which displays all their images similarly to the Photos app. Currently I can use two frameworks, the old Assets Library and the new Photos Library frameworks. Is there any recommendation how should I choose between these two?
The documentation states:
In iOS 8.0 and later, use the Photos framework instead of the Assets Library framework. The Photos framework provides more features and better performance for working with a user’s photo library.
But as my tests show, there are some cases when the user has not yet been enabled iCloud Photo Library, thus I can retrieve none of their photos via the new framework. How can I detect if iCloud Photo Library is enabled? And if enabled, the old framework more or less still works, but it seems that does not show every photo. Which photos does it show? Shall I continue using it? I can't find any documentation about this.
I've made an app with Assets Library framework and I'm testing another one with Photos framework.
On my iPhone I haven't enabled iCloud Photo Library, but with both frameworks I can retrieve all the photos.
On the other hand, on my iPad I've enabled iCloud Photo Library with "Optimize [device] Storage" option. In this case (https://support.apple.com/en-us/HT204264):
All of your original, full-resolution photos and videos are stored in iCloud while device-size versions are kept on your device. You can download the original photos and videos over Wi-Fi or cellular when you need them.
On iPad, with the Photos framework I can retrieve all photos, while with the old app using Assets Library I find only the downloaded ones (i.e. the images I've requested with the app using Photos framework).
I think that if you select the other option: "Download and Keep Originals" both frameworks can retrieve all photos (but I haven't tried yet).
I hope this can help.

Saving Data on iCloud

I have been able to sync a plist to iCloud with all the user's level high scores.
I still haven't been able to figure out how to make it so people cannot just go into iCloud docs folder and change those values.
I know Jetpack Joyride saves their game information to iCloud, but when I go into the documents folder, there is nothing in there (do they save it to their own servers?)
Another game I have saves with a "Game.sav" file.
Is there a folder you can save to in iCloud that users cannot access? It would ruin the game if they could change their high score or achievement numbers for Game Center.
Thanks in advance!
Instead of the document-saving feature of iCloud, use the key-value feature of iCloud (NSUbiquitousKeyValueStore). Users can't see that.

What non-user directories can sandboxed mac app read/write to?

I have an app which needs to preserve data between times it runs. I had been using NSUserDefaults for this, but I've had a few users point this out to me: this causes different users to end up with different data, which isn't the way the app should work. It needs a single directory that it can read/write from regardless of which user is running it.
So, I need a non-user specific directory that a sandboxed mac app can read and write to.
Thanks!
(Oh, and if this directory is persistent between updates of my app, that'd be helpful, too!)
Quick barely related question: Is there a way to have a user modifiable resource file in a Mac App Store approved app? I don't want it to be modifiable via my app; I just want to make sure that users modifying it won't cause the system to kill the app for not matching a code signature hash or something.
I don't think that you will be able to read and write in a directory outside of the App Sandbox container without prompting the user to select it using Powerbox and saving a security-scoped bookmark (see App Sandbox Container Directory). From what I've gathered about App reviews lately, you won't even be able to specify a default in the open dialog if you elect to have the user choose the directory.
As for the second question, as I understand it any verification of code signatures is left to the developer. So while MAS apps have a _CodeSignature folder containing a plist with all the hashes of the resource, in my experiments changing them had no effect on app launch.

Resources