Creating an iPhone Daemon – Part 1
So I thought I would start this blog of with a BANG!, and show people how to create an iPhone Daemon.
A daemon is a program or application that runs in the background on the device. This differs from a regular program as it is started on boot of the device, and can run at certain intervals without the users permission. I am going to show you how to create a very simple one that polls the GPS on the iPhone, and stores the information on a database.
You will need to do the following things before we can get started.
1) Make sure your iPhone is jail broken
2) Install openSSH on your iPhone via Cyndia
3) xcode has the tool chain installed, if it does not there are very easy instructions over at the hackint0sh forums
4) Install Cyberduck/or another SFTP program on your mac
So now that we have done this, lets get coding!
Open up xcode and start a new xcode project with the open tool chain template.
The first thing to note is that it is not good to use the UIApplication class to start your daemon (it takes more memory than we need), so we are going to write our own main method.
#import #import "CALocationDelegate.h" int main(int argc, char *argv[]) { //start a pool NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; //initialize our LocationManager delegate so we can pick up GPS information DLocationDelegate *obj = [[DLocationDelegate alloc] init]; //start a timer so that the process does not exit, this will GPS time to fetch and come back. NSDate *now = [[NSDate alloc] init]; NSTimer *timer = [[NSTimer alloc] initWithFireDate:now interval:.01 target:obj selector:@selector(startIt:) userInfo:nil repeats:YES]; NSRunLoop *runLoop = [NSRunLoop currentRunLoop]; [runLoop addTimer:timer forMode:NSDefaultRunLoopMode]; [runLoop run]; [pool release]; NSLog(@"Finished Everything, now closing"); return 0; }
You might notice that we started a timer and used the NSRunloop-run method. The run method blocks the thread, but still lets delegates (like the CoreLocationDelegate) receive delegate methods.
On the next segment, we will create the DLocationDelegate class to receive GPS coordinates, and send them to a server.
Tags: daemon, demon, GPS, iPhone, iPhone daemon, iPhone GPS
16 Comments
I am very interested in this
is that first line supposed to be
#import {CoreLocation/CoreLocation.h}
where the { } are HTML carot brackets? Maybe they got censored in the blog post?
Thank you for a great blog, I will be sure to bookmark your site and check later… Usually I don’t leave a comment but I wanted to let you know that I really like your site
Usually I don’t leave a comment but I wanted to let you know that I really like your site.
Hi!
any one can helpmeout..while i am using this application ..when i placed calocation daemon app build in coreservices..to run as background daemon..
iphone gives me a pop-up alert…calocationdaemon app uses your current location..i want to hide this pop-up alert ..dont want to show this pop-up alert to user..how it can be possible through code .
thanks
Hi there, thanks for that nice tutorial.
I have one question, do i need to add this whole code in a Navigation Based App Template?
Thanks for the info! I have a question though: can I create a daemon to open an app right after the boot process completes?
Please help me someone just still my I-Phone (nov 11, 2010)
I have the serial number and I like to register my i-phone because there is many personal information in it.
How can I register my i-phone, please help me?
Nice one. “iPhone is jail broken” I’ve got a few codes.
Willingly I accept. In my opinion, it is actual, I will take part in discussion. I know, that together we can come to a right answer.
[url=http://rozwiazywaniezadan.com]Rozwiazywanie zadan [/url]
thanks i’ve searching for this
you very first ought to call TN to see if they even will accept your license. i know where im at you’ve to do some far more points if you are moving from out of state to mine. like take one more test etc…. so call and ask them what you need to do. http://weifjdsflkdjs.com
Does anyone know how to do that by now? There don’t seem to be templates out for XCode 4.2
What about xcode 4.3.2???
Does anyone know how to do that by now? There donβt seem to be templates out for XCode 4.2
Hi thanks for this article!
but how can i check if the deamon is running?
and are those runned as root?
2 Trackbacks
[...] a file, search it for a string, replace the string with another, and close it). I found this site: Chris Alvares blog Β» Creating an iPhone Daemon – Part 1, but he didn’t post any other [...]
[...] Here is part two of the blog series “Creating an iPhone Daemon”, for part one please click this link [...]