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.

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 thehackint0sh 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.

转自 http://chrisalvares.com/blog/page/6/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值