0

我正在为越狱的 iPhone 开发。我需要将文件写入(复制)到只有 ROOT 具有写入权限的 iPhone 系统文件夹(/Library/LaunchDaemons)。如何通过我的代码将文件写入此类文件夹。我知道我可以使用 NSFileManager 的 copyItemAtPath:toPath 方法来复制文件,但我不能写,因为我没有权限在这些文件夹上写。

有什么建议么??

4

3 回答 3

1

我想我已经找到了这个问题的答案。为了写入系统文件夹,您需要拥有对该文件夹的写入权限。我的应用程序附加了一个守护程序,因此我必须将该守护程序复制到 /System/Library/LaunchDaemons 以使该守护程序工作。因此,当我正在为 JB iphone 开发并且人们将使用 Cydia 安装我的应用程序时,为什么不让 Cydia 将我的应用程序的文件安装到适当的位置。我让 Cydia 将 Daemon 文件复制到 /System/Library/LaunchDaemon 文件夹中。现在的问题是 Cydia 如何知道将文件粘贴到哪里。答案很简单,只需在 .deb 文件中创建正确的文件夹,cydia 就会粘贴位于 .deb 文件中的文件夹中的文件。

例如,如果您有一个守护进程,并且希望 Cydia 将其粘贴到 /System/Library/LaunchDaemons ,请在制作 .deb 之前制作这样的文件结构

+- MyApp
   +- Applications
      +Myapp.app
   +-DEBIAN
    -control
   +-System
     +-Library
       +-LaunchDaemons
         +- com.myLaunchDaemon.plist

Cydia 在安装您的应用程序时会将 com.myLaunchDaemon.plist 文件粘贴到 System/Library/LaunchDaemons 中,重启即可。

于 2010-02-10T03:41:02.027 回答
0

Instead of running your whole app as root it is much better design to have a small helper tool that will install the files. Then only that helper tool has to run as root.

For more info about SUID binaries check http://en.wikipedia.org/wiki/Setuid as a good start.

于 2010-01-26T13:37:48.000 回答
0

您的应用程序可以作为 root 或 setuid root 运行。

于 2010-01-26T13:20:03.090 回答