Absolute path for the internal storage on iOS device - ios

I am using PCLStorage to interact with local files on both Android and iOS platforms.
I am using the following code snippet.
IFolder rootFolder = await FileSystem.Current.GetFolderFromPathAsync(path);
IFolder folder = await rootFolder.CreateFolderAsync("HandSAppPdf", CreationCollisionOption.OpenIfExists);
IFile file = await folder.CreateFileAsync("Hello.pdf", CreationCollisionOption.GenerateUniqueName);
in the case of Android, I have the
path ="/storage/emulated/0/"
But I am not sure what would be the path in the case of iOS. if anyone can help me out, I would much appreciate that.

Your application’s access to the file system (and other resources such as the network and hardware features) is limited for security reasons. This restriction is known as the Application Sandbox.
Since iOS11, Files App in your phone has been used for users to access the document which an iOS application created. I recommend you to follow this File system access in Xamarin.iOS and its demo. You could generate a new text file in your Application's Documents Folder like this:
public static string WriteFile()
{
var documents = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
var filename = Path.Combine(documents, "Write.txt");
File.WriteAllText(filename, "Write this text into a file!");
return "Text was written to a file." + Environment.NewLine
+ "-----------------" + Environment.NewLine
+ File.ReadAllText(filename);
}
And this file could be accessed through Files App.
Also to allow the user to directly access files in your app, remember to create a new boolean key in the Info.plist file LSSupportsOpeningDocumentsInPlace and set it to true.

Related

Dot Net Core 2 Code to serve a .plist file to an ios device for installation of an iOS application

I am creating a dot net core mvc app to allow my internal team to download the enterprise ios app on their phones. So I created a plist to put (serve) it in that app and allow users to download and install the mobile app through this dot net app.
Below is the Downloadapp action that takes a string with a file name and returns the plist file.
public async Task<IActionResult> Downloadapp(string filename)
{
string file_name = getFileName(filename);
string file_path = getFilePath(filename);
if (filename == null)
return Content("filename not present");
var path = Path.Combine(
Directory.GetCurrentDirectory(),
file_path, file_name);
var memory = new MemoryStream();
using (var stream = new FileStream(path, FileMode.Open))
{
await stream.CopyToAsync(memory);
}
memory.Position = 0;
return File(memory, GetContentType(path), Path.GetFileName(path));
}
I call this: https://localhost:44384/Home/Downloadapp?filename=CCI_Zoom_iOS_Mobile_plist to download the plist successfully and have https://localhost:44384/Home/Downloadapp?filename=CCI_Zoom_iOS_Mobile_ipa in the plist string to call and serve the ipa file.
However, When I call
itms-services://?action=download-manifest&url=https://localhost:44384/Home/Downloadapp?filename=CCI Zoom_iOS_Mobile_plist
using a URL.Action call/also append itms-services.... in the beginning of the URL, it says "Open this page in itunes" and then nothing happens.
On an ios device, normally it should give an option to install the application but in my case nothing is happening.
What dot net core (2.1) code shall I write to generate a link that serves a plist file to download an ios application?
p.s. I am new to .net core so I need your help on this. It would be much appreciated.
Thanks

Application private directory on iOS with access to creation of files from Qt APIs

I am using Qt app on iOS & want to save files into Application's private directory so that other apps cannot access my files. Reading through the documentation here, /Documents directory under data container looks to be the path to save my files which are private to app.
Firstly I chose to use QStandardPaths::writableLocation(QStandardPaths::AppDataLocation) which returned
/var/mobile/Containers/Data/Application/123XX-XXXX-XXXX-XXXX/Library/Application Support/MyApp. But then I found that I could not create any files in there. Tried /Documents inside the App folder as well. But in vain.
Secondly I tried QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation) which returned /var/mobile/Containers/Data/Application/123XX-XXXX-XXXX-XXXX/Documents. I am able to create & save my files here.
On iOS, which is the correct path to create files which are meant to be private to the application ?
How can I get the path using Qt?
The directory named with some ID as 123XX-XXXX-XXXX-XXXX, Is this the application directory or is it Library/Application Support/MyApp inside the same directory ?
I had same problem, for example I created a sqlite file. But the file that you will create can be every file you wants. In my example I need to create a sqlite file.
I solved like this:
QString dbName = "mydb.sql";
QString dbLocation;
#ifdef Q_OS_ANDROID
dbLocation = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation);
#endif
#ifdef Q_OS_IOS
dbLocation = QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation);
#endif
db = QSqlDatabase::addDatabase("QSQLITE");
db.setDatabaseName(dbLocation + "/" + dbName);
qDebug() << db.database(dbLocation + "/" + dbName);
qDebug() << db.databaseName();
Now you can save the file, I used DocumentsLocation to get a path, always works on iOS, but not work on Android, to be ready to Android you use another path: AppDataLocation.
In the documents location you can write/read/put and create files on iOS.
In the AppDataLocation location you can write/read/put and create files on Android.
Permission not denied in DocumentsLocation.

React-native-sqlite-storage how to open database in documents directory for iOS

I am using react-native-sqlite-storage and I can not find a way to get it to open a database that is already in documents directory (downloaded from internet). The file name specified seems to point to a file in the app bundle, which when running on iOS is copied by the library from the bundle to the app's Library folder (since you cant modify files in the iOS app bundle). How can I force it to make use of a file already in the documents folder (or library folder if i move it there)?
React-Native-Sqlite-Storage uses a subdirectory within the apps library folder. The directory is called localDatabase. Copy, or download, or move your database to that location (localDatabase), and then open the database using React-Native-Sqlite-Storage's openDatabase() function while giving it the database name.
var RNFS = require('react-native-fs');
var SQLite = require('react-native-sqlite-storage');
/*copy file from app bundle to library/localDatabase*/
var sourcePath = RNFS.MainBundlePath + '/' + 'myDatabase.sqlite';
var destinPath = RNFS.RNFS.LibraryDirectoryPath + '/LocalDatabase/' + 'myDatabase.sqlite';
RNFS.copyFile(sourcePath, destinPath)
.then(() =>{
var db = SQLite.openDatabase("myDatabase.sqlite", "1.0", "", 200000, me._openCB, me._errorCB);
})

Where to save files from Firefox add-on?

I am working on a Firefox add-on which among other stuff generates thumbnails of websites for use by the add-on. So far I've been storing them by their image data URL using simple-storage. Two problems with this: the storage space is limited and sending very long strings around doesn't seem optimal(I assume the browser has optimized ways of loading image files, but maybe not data URLs). I think it shouldn't be a problem to save the files to disk, the question is where though. I googled quite a bit and could not find anything. Is there a natural place for this? Are there any restrictions?
As of Firefox 32, the place to store data for your add-on is supposed to be: [profile]/extension-data/[add-on ID]. This was established by the resolution of "Bug 915838 - Provide add-ons a standard directory to store data, settings". There is a follow-on bug, "Bug 952304 - (JSONStore) JSON storage API for addons to use in storing data and settings" which is supposed to provide an API for easy access.
For the Addon-SDK, you can obtain the addon ID (which you define in package.json) with:
let self = require("sdk/self");
let addonID = self.id;
For XUL and restartless extensions, you should be able to get the ID of your addon (which you define in the install.rdf file) with:
Components.utils.import("resource://gre/modules/Services.jsm");
let addonID = Services.appInfo.ID
You can then do the following to generate a URI for a file in that directory:
userProfileDirectoryPath = Components.classes["#mozilla.org/file/directory_service;1"]
.getService( Components.interfaces.nsIProperties)
.get("ProfD", Components.interfaces.nsIFile).path,
/**
* Generate URI for a filename in the extension's data directory under the preferences
* directory.
*/
function generateURIForFileInPrefExtensionDataDirectory (fileName) {
//Account for the path separator being OS dependent
let toReturn = "file://" + userProfileDirectoryPath.replace(/\\/g,"/");
return toReturn +"/extension-data/" + addonID + "/" + fileName;
}
}
The object myExtension.addonData is a copy that I store of the Bootstrap data provided to entry points in bootstrap.js.

Air iOS Flash, what is the included folder path?

This is kinda silly but I can't seem to find the directory path for the included folder.
In Flash Cs6 publish setting, I included a folder which is located at c:\abc\def\ghi/xxx.
In this case, the path in iOS will be app://xxx?
To access a flle in the folder, what string do I exactly need to pass to the URLRequest?
I think you are trying to access applicationDirectory. In iOS standard directories native path like
app:/ means applicationDirectory
applicationDirectory - /var/mobile/Applications/uid/filename.app
applicationStorageDirectory - /var/mobile/Applications/uid/Library/Application Support/applicationID/Local Store
However you can access application directory file like
var applicationXMLFile:File = File.applicationDirectory.resolvePath("application_data.xml");
var applicationXMLUpdateFile:File = new File(applicationXMLFile.nativePath);
if we are trying access directly like
var applicationXMLFile:File = File.applicationDirectory.resolvePath("application_data.xml");
Sometimes it throws SecurityError/IOError.
http://help.adobe.com/en_US/as3/dev/WS5b3ccc516d4fbf351e63e3d118666ade46-7fe4.html#WS5b3ccc516d4fbf351e63e3d118666ade46-7d9e
Using a File.
If you want pass to URLRequest iOS Documents folder path.
try this:
var urlRequest:URLRequest = new URLRequest(File.documentsDirectory.resolvePath("myFile.txt").nativePath);

Resources