iphone以编程方式重启 [英] iphone reboot programmatically

查看:126
本文介绍了iphone以编程方式重启的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有代码

system("reboot") 

reboot 命令在终端中有效,但即使我以root身份运行应用程序,操作仍然是否认。有没有人找到任何有效的方法,或者可以解释一下 SBSetting的重启,这让我很好奇?

The reboot command works in the terminal, but even if I run the app as root, the operation is still denied. Has anyone found any way that works, or can explain a bit about SBSetting's reboot, which makes me curious?

推荐答案

我找到了一种方法,虽然它有点令人费解。问题是,即使您将应用设置为 root ,当您进行 system()调用时,您显然仍然受限于用户移动权限。由于移动无法调用重启(成功),因此无效。

I figured out a way to do it, although it's a bit convoluted. The problem is that even if you setup your app to run as root, when you make system() calls, you're apparently still limited to user mobile privileges. Since mobile cannot call reboot (successfully), this doesn't work.

我解决这个问题的方法是利用 SBSettings 支持的新功能。 SBSettings有一个运行的特权守护程序进程。它允许您插入自己的命令,只需编写脚本(或其他可执行文件)并将其转储到适当的目录中( / var / mobile / Library / SBSettings / Commands )。然后,重新启动sbsettingsd进程后,可以通过发布通知来运行脚本。如果您为脚本命名

The way I got around this problem is to take advantage of a new feature that SBSettings supports. SBSettings has a privileged daemon process that runs. It allows you to plug in your own commands, by simply writing a script (or other executable) and dumping it in the appropriate directory (/var/mobile/Library/SBSettings/Commands). Once you then restart the sbsettingsd process, you can get it to run your script by posting a notification. If you name your script

com.mycompany.reboot

然后从您的应用程序中,您可以执行此代码:

then from within your app, you can execute this code:

#import <notify.h>

notify_post("com.mycompany.reboot");

然后,让 com.mycompany.reboot 成为一个简单的shell脚本这个:

Then, you make com.mycompany.reboot a simple shell script like this:

#!/bin/sh
reboot

并确保在com.mycompany.reboot脚本上使用chmod 755。有关此SBSettings命令功能的完整详细信息,请访问:

And make sure to chmod 755 on your com.mycompany.reboot script. The full details of this SBSettings command feature can be found here:

http://thebigboss.org/guides/sbsettings-toggle-spec (参见调用外部函数和脚本 ...)

无论如何,它确实需要你的应用程序依赖于SBSettings,但它是一个免费的应用程序,大多数用户可能想要它仍然拥有它。目前,它通过 notify_post()完成了以编程方式重启(或任何其他需要root访问权限)的目标。

Anyway, it does require your app to depend on SBSettings, but it's a free app, and most users would probably want to have it anyway. For now, it accomplishes the goal of rebooting (or anything else that requires root access) programmatically, via notify_post().

这篇关于iphone以编程方式重启的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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