启用应用程序沙箱时,System()命令不工作 [英] System() command not working when enabling app sandboxing

查看:147
本文介绍了启用应用程序沙箱时,System()命令不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Apple现在要求所有未来的应用程序都进行沙盒化,因此我按照说明操作了沙箱应用程序。生成成功,但我的系统(rm -rf〜/ .Trash / *)命令停止工作。什么都没发生。我觉得混乱这里是为什么这个系统命令不工作与应用程序沙盒/权利。这是我的权利设置:

Apple now require all future apps to be sandboxed and so I followed the instructions to sandbox an app. The build succeeded but then my system(rm -rf ~/.Trash/*) command stopped working. Nothing happened. What I find confusing here is why this system command does not work with App Sandboxing/Entitlements on. Here is are my entitlement settings:

授权:已检查

应用沙盒:已选中

这是我当前的代码:

- (void)viewDidLoad {
[self emptyTrash];
}

- (void)emptyTrash {
system(rm -rf ~/.Trash/*);
}

感谢您的帮助!

推荐答案

查看文档


Mac OS X路径查找API位于POSIX图层上方,相对于容器返回路径
,而不是相对于用户的家
目录。如果你的应用程序,在你沙箱之前,访问
的用户的实际主目录(〜)的位置,并且您使用Cocoa或Core
Foundation API,然后,在启用沙盒后,您的路径查找$

Mac OS X path-finding APIs, above the POSIX layer, return paths relative to the container instead of relative to the user’s home directory. If your app, before you sandbox it, accesses locations in the user’s actual home directory (~) and you are using Cocoa or Core Foundation APIs, then, after you enable sandboxing, your path-finding code automatically uses your app’s container instead.

您可以使用

struct passwd *getpwuid(uid_t uid);
struct passwd {
char    *pw_name;       /* user name */
char    *pw_passwd;     /* encrypted password */
uid_t   pw_uid;         /* user uid */
gid_t   pw_gid;         /* user gid */
__darwin_time_t pw_change;      /* password change time */
char    *pw_class;      /* user access class */
char    *pw_gecos;      /* Honeywell login info */
char    *pw_dir;        /* home directory */
char    *pw_shell;      /* default shell */
__darwin_time_t pw_expire;      /* account expiration */
}

 #include <pwd.h>
 #include <sys/types.h>
 char *HomeDirectory = getpwuid(getuid())->pw_dir;
 NSLog(@"%s", HomeDirectory);
 system([[NSString stringWithFormat:@"rm -rf %s/.Trash/",HomeDirectory] UTF8String]);

这篇关于启用应用程序沙箱时,System()命令不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆