Save TiniFile from application in iOS

I am very new to the iOS platform. I am trying to save an INI file for my application. The problem is that I cannot get the path with write permission.

Here is my code:

ini := TIniFile.Create(GetHomePath + '/user.dat'); try ini.WriteString('data','user',edtuser.Text); ini.WriteString('data','descr',edt1.Text); finally ini.Free; end; 

I get an exception that the file cannot be created. How can I access recording using Firemonkey?

+6
source share
2 answers

Use TPath.GetDocumentsPath (and use TPath.Combine instead of concatenation to remove hard-coded / ):

 uses Systen,IOUtils; ini := TIniFile.Create(TPath.Combine(TPath.GetDocumentsPath, 'user.dat')); 

Using TPath.GetDocumentsPath transparently works on all supported platforms (Win32, Win64, OSX, iOS and Android), and using TPath.Combine will be automatically added, so you do not need to manually concatenate them.

If you prefer to do it yourself, though:

 var IniName: string; begin IniName := TPath.GetDocumentsPath + TPath.DirectorySeparatorChar + 'user.dat'; Ini := TIniFile.Create(IniName); try // Rest of code finally Ini.Free; end; end; 
+12
source

Maybe this or it can help you

 uses INIFiles; function TForm6.MyINIFilePath: string; begin // Result := GetHomePath + PathDelim + 'Library' + PathDelim+'My.ini'; Result := GetHomePath + PathDelim + 'Documents' + PathDelim+'MyD.ini'; end; 
+2
source

Source: https://habr.com/ru/post/956476/