iphone 以编程方式重新启动
我有代码
system("reboot")
reboot
命令在终端中工作,但即使我以 root 身份运行应用程序,操作仍然被拒绝。有没有人找到任何有效的方法,或者可以解释一下SBSetting重启,这让我很好奇?
I have code
system("reboot")
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
我终于找到了一种无需 root 即可以编程方式重新启动 iOS 设备的方法!!!!
用于重新启动 iOS 设备的命令行工具称为 libimobiledevice:
http://krypted.com/mac-os-x/use-libimobiledevice-to-view-ios-logs/
这确实令人惊叹。我在安装时遇到的一个障碍是尝试安装这一行:
但是我通过运行这一行解决了安装问题:
遇到这个问题后,我按照其余的说明进行操作,瞧!
大多数命令都可以在此页面上找到:
http://krypted.com/uncategorized/command-line-ios-device- management/
重启iOS设备的神奇命令是:
这个工具真正神奇的地方不仅在于重启iOS设备,还可以使用以下命令将iOS设备日志输出到mac的终端应用程序:
I have finally found a way to programmatically restart an iOS device without rooting a device!!!!
The command line tool to restart an iOS device is called libimobiledevice:
http://krypted.com/mac-os-x/use-libimobiledevice-to-view-ios-logs/
It is truly amazing. One snag I ran into while installing was trying to install this line:
However I got around the install problem by running this line:
After that problem, I followed the rest of the instructions and voila!
Most of the commands can be found on this page:
http://krypted.com/uncategorized/command-line-ios-device-management/
The magic command that restarts the iOS device is:
What is truly amazing about this tool is not only restarting an iOS device but also outputting iOS device logs to mac's terminal app using the following command:
我想出了一个办法,虽然有点复杂。问题是,即使您将应用程序设置为以 root 身份运行,当您进行
system()
调用时,您显然仍然仅限于用户移动< /strong> 特权。由于移动无法(成功)调用重新启动,因此这不起作用。我解决这个问题的方法是利用 SBSettings 支持的新功能。 SSBettings 有一个运行的特权守护进程。它允许您插入自己的命令,只需编写脚本(或其他可执行文件)并将其转储到适当的目录(
/var/mobile/Library/SBSettings/Commands
)即可。重新启动 sbsettingsd 进程后,您可以通过发布通知来让它运行您的脚本。 命名脚本如果您在应用程序中
,则可以执行以下代码:然后,将 com.mycompany.reboot 制作为一个简单的 shell 脚本,如下所示:
并确保在 com.mycompany.reboot 上执行 chmod 755。 mycompany.reboot 脚本。可以在此处找到此 SBSettings 命令功能的完整详细信息:
http://thebigboss.org/guides/ sbsettings-toggle-spec(请参阅调用外部函数和脚本 ...)
无论如何,它确实要求您的应用程序依赖于 SSBettings,但是它是一个免费的应用程序,大多数用户可能都想拥有它。目前,它通过
notify_post()
以编程方式实现了重新启动(或任何其他需要 root 访问权限)的目标。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.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 scriptthen from within your app, you can execute this code:
Then, you make com.mycompany.reboot a simple shell script like this:
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 (see Calling External Functions and Scripts ...)
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()
.这个答案可能对某些人来说有点老套,但我还没有找到更好的解决方案来重新启动尚未越狱的 iOS 设备,所以这是我的答案:
为了从命令行重新启动设备,我做了一些准备工作:
此时,您拥有一个将执行上述步骤的应用程序文件。我倾向于让 iTunes 保持打开状态,因为它始终会连接 iOS 设备并准备好进行访问。当 iTunes 关闭并重新启动时,设备需要一些时间才能与 iTunes 完全连接,这往往会破坏 Automator 应用程序的流程。
此时,我可以进入终端,转到应用程序文件的位置并运行以下命令[示例]:
open automator.app
(将 'automator.app' 替换为您的文件名)
如果您像我一样并且在 jenkins 中运行此命令,则需要运行以下命令:
由于某种原因,自动化应用程序需要睡眠时间来完成所有记录的操作。
另外,我确信您也可以编写一个 applescript 来完成所有这些操作,但我讨厌 applescript 并采取了简单的方法!
This answer might feel hacky to some but I have not found a better solution on how to restart an iOS device that has not been jailbroken so here goes my answer:
In order to restart a device from the command line I do some prep work:
At this point you have an app file that will execute the steps mentioned above. I tend to leave iTunes open as it will always have the iOS device hooked up and ready to be accessed. When iTunes is closed and relaunched, the device takes time to fully connect with iTunes and this tends to break the flow of the Automator app.
At this point I can go into a terminal, go to the location of the app file and run the following command [EXAMPLE]:
open automator.app
(replace 'automator.app' with the name of your file)
If you are like me and your are running this command in jenkins, you will need to run the following commands:
For some reason, the automator app needs the sleep time to complete all the recorded actions.
Also, I am sure you can also write an applescript to do all of this but I hate applescript and took the easy way out!
您是否尝试过
NSTask
:执行终端命令来自 Cocoa 应用程序did you try
NSTask
: Execute a terminal command from a Cocoa app如果应用程序在其沙箱中运行,则这是不可能的。在越狱的手机上,您也许能够执行重新启动 shell 命令。
This is not possible if the app is running in its sandbox. on a jailbroken phone you might be able to execute the reboot shell command.