iPhone Reboot Programmatically

iphone reboot programmatically

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 script

com.mycompany.reboot

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

#import 

notify_post("com.mycompany.reboot");

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

#!/bin/sh
reboot

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().

How can I reboot the iPhone programmatically from within my application?

No, there is no legal way. Mostly because of security reasons. What happens if they allow and somebody trying to write some virus. But illegally, yes, it can, Cydia can do that so we can technically do that

Way to Programmatically Reboot iOS Device?

This is not a real answer (just thinking aloud).

Obviously, you can't do this through public API.

I believe, API's like SBReset can't do this either, because they are protected by entitlement.

I believe your simplest option to find some reasonably low level API which crashes and use it to crash a device.

I had exactly the same question some time ago:A way to reboot iOS device or restart Springboard using private API?

P.S. I don't have a way to find these crashes. I would recommnd to talk to jailbreak community (people who come up with jailbreaks for iOS devices). They collect all kinds of crashes. Most of these crashes aren't exploitable. However, you don't need an exploit, you just need a OS crash.

Is there any way to restart my iOS app programmatically?

There are no methods available in iOS to restart your application, BUT you could manually reinstantiate initial root UIViewController when needed.


To reinstantiate root UIViewController you could use following static functions in your AppDelegate class:

static func getWindow() -> UIWindow? {
return UIApplication.shared.keyWindow
}

static func resetViewController() {
let window = getWindow()

let controller = ... /// Instantiate your inital `UIViewController`

window?.rootViewController = controller
window?.makeKeyAndVisible()
}

Note:

"Restarting" app is a very uncommon practice and should be avoided in all cases if possible.

Force iphone app to restart programmatically?

First of all, although it is possible to force kill your app, this is not allowed by Apple and will rejected. Even if it wasn't rejected, there is no way to restart your app once it's killed. You just need to find some way to reset your app through your code, as Jason Coco said. It might be more work, but it's worth it to not get rejected by Apple.

Is there a way to programmatically restore my iPhone to factory settings?

There is a private API SBDataReset in SpringboardServices private framework. It wipes all data.

You can check the following code for example how to use it.

An application which uses this API should have "com.apple.springboard.wipedevice" entitlement to work.

BTW. One more alternative is to use MDM protocol. It has a wipe command. However, it requires way more machinery (MDM server, enroll a user).

Update 1

It looks like sample code in the link is out date. I looked into Preferences and couple of other pieces of iOS software which uses SBDataReset and it looks like new argument was introduced to SBDataReset.

Try following code (sorry, I don't have jailbroken iOS device right now, so I can't try it on my own)

#import 
#import
#include
#include

// Framework Paths
#define SBSERVPATH "/System/Library/PrivateFrameworks/SpringBoardServices.framework/SpringBoardServices"
#define UIKITPATH "/System/Library/Framework/UIKit.framework/UIKit"

#define WIPE_MODE_NORMAL 4

int main(int argc, char **argv)
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];

// Fetch the SpringBoard server port
mach_port_t *p;
void *uikit = dlopen(UIKITPATH, RTLD_LAZY);
int (*SBSSpringBoardServerPort)() =
dlsym(uikit, "SBSSpringBoardServerPort");
p = SBSSpringBoardServerPort();
dlclose(uikit);

// Getting DataReset proc
void *sbserv = dlopen(SBSERVPATH, RTLD_LAZY);
int (*dataReset)(mach_port_t* port, int wipeMode) = dlsym(sbserv, "SBDataReset");
dataReset(p, WIPE_MODE_NORMAL);
dlclose(sbserv);

[pool release];
}

Please notice, that there is second parameter for SBDataReset function.

It looks like 4 is normal wipe mode and 6 is brick wipe mode.

DISCLAIMER This code is provided AS IS. I have no idea what will happen if device will be wiped in brick mode.

How to reboot or reload iPhone app programmatically in iOS

Rebooting the app is a bad idea, I'm pretty sure Apple would reject it. However, You could display a popup telling the user to open a close the app to apply your updated information. But the best way would be just to manually call the methods needed to rebuild your app (I.e. the ones that need to use the updated data).
If you have to do some extensive rebuilding (i.e. things that the user would immediately notice) it might be a good idea to add in a "loading" progress bar of sorts.

How to reboot not jailbroken iOS device programmatically?

If you're looking to do this on a real device, i.e. not the simulator, then I'm almost certain this is impossible. Apple doesn't allow you to do much outside of your sandboxed app, let alone reboot the entire phone.



Related Topics



Leave a reply



Submit