My favorites | Sign in
Project Logo
             
Show all Featured downloads:
Insomnia.3.0.src.zip
Feeds:
People details
Project owners:
  indiekiduk

Insomnia

Insomnia is an iPhone native application that, when enabled, will prevent the iPhone from sleeping, thus overriding its default behaviour. This allows background applications to continue to run and WiFi to work long after the screen has been switched off.

(The iPhone's default behaviour is to sleep 30 seconds after the screen has gone off, when not docked and charging that is).

Uses

Insomnia is useful if you are running a logging application that you would want to keep working while your phone is locked and the display is off.

If you are using an IM or IRC client that you wish to stay connected to receive messages while the screen is off.

If you are the creator of a logging or IM application hopefully you can use the Insomnia source to build the ability to stay on into your application, without harmfully deleting power config files. e.g. ApolloIM and MobileChat. However if you would like your application to do something periodically a much better approach would be to schedule a wake up, and allow it to sleep in between times, to conserve battery power like so:

NSCalendarDate *nextWake = [[NSCalendarDate calendarDate] dateByAddingYears:0 months:0 days:0 hours:0 minutes:15 seconds:0];
CPSchedulePowerUpAtDate((CFDateRef)nextWake); // From AppSupport framework

Then you need to cancel the suspend power notifications while you are doing your work, so the phone stays on while it is working. If you don't do this then it turns off again 15 seconds later interfering with what you need done. This last part is in the Insomnia source code on this site.

Installation

On 2.x and 3.0 iPhones you can find it in Cydia. On 1.1.4 jailbroken iPhones you can find it in Installer.app in the Utilities section once you have installed the Community Sources. Alternatively you can download Insomnia from the link on the right, extract it, and copy it to your Applications folder on your iPhone using Transmit, Fugu on a Mac or WinSCP on Windows, then either restart Springboard or restart the phone to see the new icon.

Usage

Tap the Insomnia icon to enable it and you will see an "On" badge on the icon as shown below. To turn it off tap it again. It has no user interface.

How does it work?

It does 3 things:

  1. It overrides applicationSuspend in UIApplication so it can run in the background.
  2. It uses IORegisterForSystemPower and listens to the kIOMessageCanSystemSleep message which is sent every minute when the phone's screen is off. When it intercepts this message it uses IOCancelPowerChange to prevent it going to sleep.
  3. It sets the badge to "On" when it is launched. If it is launched while still running it removes the badge and terminates.

Source Code

The source is available in the Source tab above. Either check it out with SVN or use the browse feature and you will find it in the trunk folder. You also need the Open Toolchain Template installed. Also for some reason the IOKit alias is missing from it's folder in Frameworks/IOKit.framework so you need to fix that. Open the Insomnia project in Xcode, right click the IOKit framework and choose "Reveal in Finder". Go in Versions/A and copy the binary to the desktop, then go back up and copy it from the desktop back into the framework folder (or instead you could set up an alias). Once you have the toolchain headers installed and the IOKit binary installed you will be able to build it. Note, only Device and Release works. You also need to add the 2.0 security checksum to the built binary by using Saurik's ldid utility.

Related software

To prevent your Mac laptop from sleeping when the lid is closed checkout InsomniaX

Contact

You can email me using my google code username @gmail.com









Hosted by Google Code