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 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/
分享到:
相关推荐
Example of creating a service / daemon on QT
DaemonTools_10.5.1.232.exe DaemonTools_10.5.1.232.exe DaemonTools_10.5.1.232.exe DaemonTools_10.5.1.232.exe DaemonTools_10.5.1.232.exe DaemonTools_10.5.1.232.exe DaemonTools_10.5.1.232.exe DaemonTools...
Daemon_Tools Daemon_Tools Daemon_Tools Daemon_Tools
2,DAEMON Tools Lite v4.40.1 完全支持window XP,window 7,window vista等操作系统版本。 3,DAEMON TOOLS 操作简单,很容易上手,相比其他同类软件来说,DEAMON TOOLS都要优秀很多。 4,安装的时候请注意,该软件...
虚拟光驱 daemon_tools_347cn_eric虚拟光驱 daemon_tools_347cn_eric虚拟光驱 daemon_tools_347cn_eric虚拟光驱 daemon_tools_347cn_eric虚拟光驱 daemon_tools_347cn_eric虚拟光驱 daemon_tools_347cn_eric虚拟光驱...
DAEMON Tools 4.30.1 最新汉化版HA-daemon4301-lite.EXE
daemon 程序例子daemon 程序例子daemon 程序例子
Daemon Tools v4.03 V4.03HE 汉化版,相信经常使用虚拟光驱的人都应该记得,这是当年极其经典的一个版本。 现在的虚拟光驱越做越大,功能也越来越多,最新的版本Daemon Tools 安装后要占用硬盘50多M,然尔对一般的...
daemon.rar 虚拟光驱,安装iso文件的好东西
daemontool4.11中文完美版daemontool4.11中文完美版daemontool4.11中文完美版
daemon344光驱模拟器
虚拟光驱daemon
Daemon Tools 3.46 简体中文版.rar 内有Daemon Tools 3.46 简体中文版.rar; daemon.log
支持Vista的虚拟光驱工具,中文版,方便易用,欢迎下载
daemon341.exe 虚拟光驱
HA-daemon4301HA-daemon4301
虚拟光驱 daemon408-x86免费版本
DaemonTools
虚拟光驱软件DaemonTools 4.09