How can I download files from 'react-native' or 'Expo' to 'icloud drive'? - ios

I am trying to create a file and download it to the device directory.
I use react-native-fetch-blob Also I was usedreact-native-fs
It is easy to download from Android and can check and read files directly from the actual device.
The file I'm talking about is a string file made of json, not a picture or video.
The directory path I use in Android:
const dirs = RNFetchBlob.fs.dirs
dirs.DownloadDir
...
RNFetchBlob.fs
.writeFile(path, data, "utf8")
.then(success => {
console.log("FILE WRITTEN!");
})
.catch(err => {
console.log(err.message);
});
But the problem is the iPhone. I have already checked the cloud documents and CloudKit through the developer account in Xcode.
Although it succeeded in using dirs.DocumentDir to execute the download, it ran the file app from the actual device and tried to go inside by clicking on icloud drive but the file was not visible, just empty.
How can I download to Icloud Drive?
Also How do I create a file from 'react-native' to 'On my iPhone' as shown in the picture below?

Related

How do I access files in the iPhone Simulators "Files app"?

I saved a file on the iOS simulator to the Files App. Specifically, I chose to save into "On My iPhone" > Downloads.
Where can I find this file in Finder on macOS?
I found ~/Library/Developer/CoreSimulator/Devices/UUID/data/Downloads but that folder is empty even though when I launch the Files app in my simulator, I clearly see files in the Downloads directory.
I was able to find it by doing a search within the /UUID folder. Apparently files saved to the Downloads folder in the Files app are saved to:
~/Library/Developer/CoreSimulator/Devices/UUID/data/Containers/Shared/AppGroup/UUID/File Provider Storage/Downloads/

how to save file from an iOS react native app to Files folder

I created a pdf file in my react native app for iOS devices, and also I can open the file in my application because it saved in Documents directory of internal storage of my application, but I want to save the file to Files folder in iOS and open it with other applications, how can I do it?
thank for your attention.
For IOS you should open share options and save the file to the Files folder. For this you can use 'react-native-share' library. If you are using Expo, use 'expo-share'. Please check below documentation.
https://www.npmjs.com/package/react-native-sharing
https://docs.expo.dev/versions/latest/sdk/sharing/

How to save a text file in external storage in ios using flutter?

I have created an app in which user can create and save a text file in the local storage of Android. I have used path_provider package which gives getExternalStorageDirectory() to save the data in the external storage. But I can not find the same for ios. getExternalStorageDirectory() is not supported for ios.
I want to save the file so that user can later on access the file from Files app in ios.
Future<String> get _localPath async{
var dir = await getExternalStorageDirectory();
return dir.path;
}
Future<File> get _localFile async{
final path = await _localPath;
return File('$path/test.txt');
}
Future<File> writeData(String msg) async{
final file = await _localFile;
return file.writeAsString(msg);
}
The above code works for Android(if storage permissions are provided). Can anyone help me for achieving the same in ios.
You can save the file in the NSDocumentsDirectory (getApplicationDocumentsDirectory()) and then make it available to the user.
From: https://developer.apple.com/library/archive/documentation/FileManagement/Conceptual/FileSystemProgrammingGuide/FileSystemOverview/FileSystemOverview.html
Use this directory to store user-generated content. The contents of this directory can be made available to the user through file sharing; therefore, his directory should only contain files that you may wish to expose to the user.
To make the directory available to the user you need to open the Xcode project under 'your_app/ios/Runner.xcworkspace'. Then open the Info.plist file in the Runner directory and add two rows with the key UIFileSharingEnabled and LSSupportsOpeningDocumentsInPlace. Set the value of both keys to YES.
If you now open the Files app and click on 'On My iPhone' you should see a folder with the name of your application.
As a compliment do #ni. answer, you must enable both keys. This is what it should look on:
Xcode (info.plist):
Info.plist on Xcode
Editor (info.plist):
<key>LSSupportsOpeningDocumentsInPlace</key>
<true/>
<key>UIFileSharingEnabled</key>
<true/>
Info in source:
In iOS 11 and later, if both this keys LSSupportsOpeningDocumentsInPlace and the UIFileSharingEnabled key are YES, the local file provider grants access to all the documents in the app’s Documents directory. These documents appear in the Files app, and in a document browser. Users can open and edit these document in place.
Source: Apple developer - iOS keys
I have used below code to fix this.
Directory directory = Platform.isAndroid
? await getExternalStorageDirectory() //FOR ANDROID
: await getApplicationSupportDirectory(); //FOR iOS
also add those files as mentioned by #Gabrielhn

how to Display Files From Files Sharing in Swift 3

A added File Sharing in Plist in My app So I can Easily Copy Files when The iPhone has connect with iTunes to my mac But the problem is that when I copy some files with iTunes in my App and Run the app I have 2 Problems :
1- when I stop the app and open that again I can't see any files in iTunes in the file sharing part
2- This code Below here should print file Exists if there is file and print some thing else if there isn't file But Just Print File Exists
here is my codes
if filemgr.fileExists(atPath: "/Applications") {
print("File exists")
} else {
print("File not found")
}
when I click the button to check files I just See File Exists even when I delete the app and install it again
please help me
When you enable file sharing for an iOS app, it allows your users to copy, delete, and rename files that to, from, and in your app's Documents folder.
Your code needs to first get a reference to its own Documents folder (which can change each time your app runs).
Then it can use the various methods of FileManager to get a list of files from that folder.

Save file to public directory in iOS using cordova

I have a cordova application that downloads pdf file from internet and save it to local filesystem using cordova-plugin-file and cordova-plugin-file-transfer. In next step I would like to open the file using default application for specified mimetype. I am using cordova-plugin-file-opener2 plugin for that. Directory where the file is saved needs to be readable for chosen 3rd party application to open the file. On android there are several publicly accessible filesystem directories and I have it working correctly. But I am unable to find the right directory where I need to save the file in case of iOS, to make it available for chosen default 3rd party app.
cordova-plugin-file says in its docs that all directories available in RW mode to cordova application are private: https://github.com/apache/cordova-plugin-file#file-system-layouts
But how does it come? Concept of opening file by default 3rd party application based on mimetype is standard in every OS. Any help would be appreciated.
iOS hasn't publicly accessible filesystem directories.
One way - use sharing via UIActivityViewController.
I am using cordova-plugin-file-opener2 plugin with IOS. I save my file in cordova.file.cacheDirectory and this works fine for me when I save a zip file into that location. I first had to install a zip file manager so to handle the mimeType = application/zip. The zip file manager I used was a free version of "Zip Viewer" which seems ok but has a few ads.
To get it to work on Android I had to save my file in
cordova.file.externalRootDirectory it failed silently when I used cordova.file.cacheDirectory for Android. You can't use cordova.file.externalRootDirectory for IOS because it is not defined for IOS according to the Cordova File Plugin docs.
Here is a code snippet that is called when the file is saved:
var fileName = "myfile.zip";
//for IOS
var filePath = cordova.file.cacheDirectory+"/Download/"+fileName;
//for Android
//var filePath = cordova.file.externalRootDirectory+"/Download/"+fileName;
var mimeType = "application/zip";
cordova.plugins.fileOpener2.open(
filePath,
mimeType,
{error : function(){
my.alert("ERROR opening with cordova.plugins.fileOpener2");
},
success : function(){
my.log("SUCCESS opening zip file");
}
});

Resources