Save file to public directory in iOS using cordova - ios

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");
}
});

Related

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/

Do you need a backend to store JSON files used by an iOS app?

I have created an Xcode project which reads data from a JSON file. My app is working fine in the view preview and when simulated. My question is, does the JSON file automatically get stored with my app when I publish to the App Store? Or do I have to host the JSON file elsewhere (cloudKit, Firebase, etc)?
In other words, is my JSON file a part of the app, in the same way that the app Icon and app assets are part of the app?
In the image below, I have stored my JSON files in a folder called "resources". Will this "resources" be part of the app when it is uploaded to the App Store?
FYI ... I am very, VERY new to Swift and Xcode! Sorry for the stupid question.
Where my JSON file is located in Xcode
As long as the file is bound to the app target then it will be part of the application bundle. You do this by opening the file in Xcode and then in the property inspector ticking the app target in the Target Membership section.
Be aware when you do this you will need to access the file as part of the bundle and not via its file system location.
if let filepath = Bundle.main.path(forResource: "myFile", ofType: "ext") {
// load file

how can a file written into the MyDocuments directory by a Visual Studio Xamarin.IOS app be read by an Xcode Objective-C app?

The Xamarin app writes a file to its 'sandbox' in the MyDocuments directory.
How do I configure the Xamarin app's project to allow another app to read this file; to expose the MyDocuments directory to another app?
How do I configure get the path for the Obj-C app to read the file?
Xamarin app is a .NET Standard 2.0 class lib project in Visual Studio.
BACKGROUND...
The Xamarin app receives BLE data and writes it to files in its MyDocuments directory.
The Obj-C app must read these files and process.
The new IOS 11 File App was suggested as an answer, however I don't think the File App has anything to do with my question because I want my Xcode Obj-C app to programmatically read the file that was written by my Xamarin.IOS app.
Xamarin app's code for writing the file..........................
Sub append_text_file( pathname as string , text_to_file as string)
dim documents as string = Environment.GetFolderPath (Environment.SpecialFolder.MyDocuments)
dim platform_agnostic_pathname as string = Path.Combine (documents, pathname )
System.IO.File.AppendAllText( platform_agnostic_pathname, text_to_file)
End Sub
Another great resource:
App Group Capabilities in Xamarin.iOS at:
https://learn.microsoft.com/en-us/xamarin/ios/deploy-test/provisioning/capabilities/app-groups-capabilities
...I USED SAFARI ON MACBOOK. IT DOESN'T WORK WITH CHROME ON WINDOWS.

How to prevent files inside my app folder in Files app to open my application

Both Application supports iTunes file sharing and Supports opening documents in place are set to YES on my Info.plist and I'm successfully able to download pdf files and store it on my app folder in Files application but the issue is when I'm trying to explore this PDF file it's directly open my app .. is there any way to avoid this and open normal preview ?
Here is how I'm creating the file :
FileManager.default.createFile(atPath: filePath, contents: pdfData, attributes: nil)
Don't use the Files app use document directory instead of Files, If you are using files app then the files in your application folder will be visible to all those apps that are using Files app.

Document sharing to other apps

my app is document based,user can preview any type of file and can edit with other apps using open in option.if file is modified by other apps, how can get that modified file to my app? Is ios 4.2 later version having any public shared directory for get updated document.Please help...

Resources