将TiniFile从应用程序保存到iOS

opc*_*0de 6 delphi ios firemonkey delphi-xe5

我是iOS平台的新手.我正在尝试为我的应用程序保存一个INI文件.问题是我无法获得具有写入权限的路径.

这是我的代码:

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

我得到一个例外,即无法创建该文件.如何使用Firemonkey获取可写路径?

Ken*_*ite 12

使用TPath.GetDocumentsPath(并使用TPath.Combine而不是连接,删除硬编码/):

uses
  Systen,IOUtils;


ini := TIniFile.Create(TPath.Combine(TPath.GetDocumentsPath, 'user.dat'));
Run Code Online (Sandbox Code Playgroud)

使用TPath.GetDocumentsPath透明地在所有支持的平台(Win32,Win64,OSX,iOS和Android)上工作,并且使用TPath.Combine将自动添加TPath.DirectorySeparatorChar,因此您不必手动连接它们.

如果你喜欢自己做,但是:

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