- 浏览: 1334110 次
- 性别:
- 来自: 成都
文章分类
- 全部博客 (471)
- 原创文章 (4)
- Database (84)
- J2SE (63)
- Web (26)
- Javascript (30)
- Lucene (11)
- os (13)
- 算法 (8)
- Webservice (1)
- Open projects (18)
- Hibernate (18)
- Spring (15)
- Css (2)
- J2ee (2)
- 综合技术 (18)
- 安全管理 (13)
- PatternsInJava (27)
- NIO (5)
- Ibatis (2)
- 书籍收藏 (1)
- quartz (7)
- 并发编程 (15)
- oracle问题 (2)
- ios (60)
- coco2d-iphone (3)
- C++ (6)
- Zookeeper (2)
- golang (4)
- animation (2)
- android (1)
最新评论
-
dandingge123:
【引用】限制UITextField输入长度的方法 -
qja:
...
对List顺序,逆序,随机排列实例代码 -
安静听歌:
现在在搞这个,,,,,哎~头都大了,,,又freemarker ...
通用大型网站页面静态化解决方案(一) -
springdata-jpa:
java quartz定时任务demo教程源代码下载,地址:h ...
Quartz 配置参考 -
马清天:
[b][/b][list][*]引用[u][/u][/list ...
通用大型网站页面静态化解决方案(一)
This is part three of the blog series “Creating an iPhone Daemon”, for part one please click this link
In the last part of the series, we created the header file for our DLocationDelegate class, now lets create the implementation file (DLocationDelegate.h)
// // DLocationDelegate.m // // // Created by Chris Alvares on 3/25/09. // Copyright 2009 Chris Alvares. All rights reserved. // #import "DLocationDelegate.h" #define NSURLRequestReloadIgnoringLocalCacheData 1 @implementation DLocationDelegate @synthesize locationManager; -(id) init { if (self = [super init]) { trackingGPS = false; NSLog(@"starting the location Manager"); self.locationManager = [[CLLocationManager alloc] init]; self.locationManager.delegate = self; } return self; } //this function is to only be called once. -(void) startIt:(NSTimer *) timer { if(timer != nil) [timer invalidate]; trackingGPS = true; [self.locationManager startUpdatingLocation]; } //the difference in this function is that it invalidates the timer function, and can run more than one time -(void) startItAgain:(NSTimer *)timer { if(!trackingGPS) { trackingGPS = true; [self.locationManager startUpdatingLocation]; } } - (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation { srandom(time(0)); //do this to make sure that it does not use a cached page NSLog(@"Location found"); //if the horizontalAccuracy is negative, CoreLocation failed, and we want a good reading, so we want at least 100 meter accuracy if([newLocation horizontalAccuracy] < 100 && [newLocation horizontalAccuracy] > 0) { [self.locationManager stopUpdatingLocation]; NSNumber *num = [NSNumber numberWithInt:(random())]; NSLog(@"Latitude %lf Longitude %lf", newLocation.coordinate.latitude, newLocation.coordinate.longitude); NSNumber *latitude = [[NSNumber alloc] initWithDouble:newLocation.coordinate.latitude]; NSNumber *longitude = [[NSNumber alloc] initWithDouble:newLocation.coordinate.longitude]; NSNumber *altitude = [[NSNumber alloc] initWithDouble:newLocation.altitude]; NSMutableString *str = [[NSMutableString alloc] initWithString:@"http://chrisalvares.com/iPhoneLocationService.php?ID=2&LATITUDE="]; [str appendString:[latitude stringValue]]; [str appendString:@"&LONGITUDE="]; [str appendString:[longitude stringValue]]; [str appendString:@"&ALTITUDE="]; [str appendString:[altitude stringValue]]; [str appendString:@"&RANDOM="]; [str appendString:[num stringValue]]; NSURL *theURL = [[NSURL alloc] initWithString:str]; NSURLRequest *theRequest = [NSURLRequest requestWithURL:theURL cachePolicy:NSURLRequestReloadIgnoringLocalCacheData timeoutInterval:120]; NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self startImmediately:YES]; if(connection == nil) { trackingGPS = NO; } NSLog(@"setting timer for 30 minutes"); NSTimer *timer = [[NSTimer timerWithTimeInterval:1800.0 target:self selector:@selector(startItAgain:) userInfo:nil repeats:NO ] retain]; [[NSRunLoop currentRunLoop] addTimer:timer forMode:NSDefaultRunLoopMode]; [timer release]; [latitude release]; [longitude release]; [altitude release]; [theURL release]; } else { NSLog(@"Accuracy not good enough %lf", [newLocation horizontalAccuracy]); } } - (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error { trackingGPS = false; NSLog(@"trackingGPS failed"); } - (void)connectionDidFinishLoading:(NSURLConnection *)connection { NSLog(@"GPS information Sent"); trackingGPS = false; } -(void) dealloc { [locationManager release]; [super dealloc]; } @end
Yes, it is a pretty big file, so I won’t explain it all (it has comments to help you).
self.locationManager = [[CLLocationManager alloc] init]; self.locationManager.delegate = self;
These two lines are important, after we init the locationManager we must make sure that the delegate is set to our DLocationDelegate class.
if([newLocation horizontalAccuracy] < 100 && [newLocation horizontalAccuracy] > 0)
Inside this function, you will notice the CLLocation *newlocation’s horizontalAccuracy property. If the horizontal accuracy is less than 0, than there was an error, if it is greater than 100, the accuracy is very poor, so the DLocationDelegate class will wait for a better reading.
[self.locationManager stopUpdatingLocation];
This line is VERY important, we have to stop the GPS from updating, otherwise the iPhone’s batter will die super quickly.
NSMutableString *str = [[NSMutableString alloc] initWithString:@"http://youriphonelocationserver.com/locationService.php?ID=2&LATITUDE="]; [str appendString:[latitude stringValue]]; [str appendString:@"&LONGITUDE="]; [str appendString:[longitude stringValue]]; [str appendString:@"&ALTITUDE="]; [str appendString:[altitude stringValue]]; [str appendString:@"&RANDOM="]; [str appendString:[num stringValue]];
When you put everything together, you should get a link like:
http://youriphonelocationserver.com/locationService.php?ID=iphoneid&LATITUDE=laditudeNumber&LONGITUDE=longitudeNumber&ALTITUDE=number&RANDOM=12312
We will create this PHP file in an upcoming tutorial.
NSTimer *timer = [[NSTimer timerWithTimeInterval:1800.0 target:self selector:@selector(startItAgain:) userInfo:nil repeats:NO ] retain]; [[NSRunLoop currentRunLoop] addTimer:timer forMode:NSDefaultRunLoopMode];
The DLocationDelegate timer is set for 1800.0 seconds, which is 30 minutes. I found that 30 minutes does not drain the battery too much, but still has a good amount of readings just incase your iPhone is lost.
While this will get your DLocationDelegate class setup, we still have one more issue, and that is that the iPhone will go into a hard sleep after a minute of no use. We will fix this in an upcoming tutorial.
发表评论
-
ios 声音合成
2013-08-18 13:20 1290http://stackoverflow.com/ques ... -
__bridge,__bridge_retained和__bridge_transfer的意思,区别与使用 20 三
2012-12-24 01:41 1717使用ARC能帮我们减轻不少内存管理方面的负担,尤其是对用 ... -
CAAnimation
2012-12-23 01:09 2350CAAnimation采用了CAMediaTi ... -
UIViewAnimation动画与Core Animation的CATransition类动画
2012-12-23 01:06 2750使用UIView类函数实现://U ... -
GCD实战2:资源竞争
2012-12-23 01:04 1596转自http://www.dreamingwish.co ... -
GCD实战一:使用串行队列实现简单的预加载
2012-12-22 17:10 2909转自 http://www.dreamingwish.c ... -
GCD介绍(四): 完结
2012-12-22 17:08 1405转自 http://www.dreamingwish.c ... -
GCD介绍(三): Dispatch Sources
2012-12-22 17:07 1657转自 http://www.dreamingwish.com/ ... -
GCD介绍(二): 多核心的性能
2012-12-22 17:05 1208转自http://www.dreamingwish.co ... -
基本概念和Dispatch Queue
2012-12-22 17:03 1385转自 http://www.dreamingwish.c ... -
Best Audio Format for iPhone Audio Programming
2012-12-19 16:26 2563I had never done audio p ... -
LAME 是一个开源的MP3解码编码工具
2012-12-19 13:09 8611MP3 Encoding * 编码MP3文件必须按如下 ... -
sqlite3中的数据类型
2012-12-10 21:37 1339(转)http://www.cnblogs.com/kfqco ... -
ios随机数,and()、random()、arc4random()
2012-11-15 11:06 4729原文:http://bj007.blog.51cto.c ... -
IPHONE GIF 播放的方式
2012-10-11 18:30 1457转 http://blog.csdn.net/zltia ... -
在新线程中使用NSTimer
2012-10-11 18:21 1589转自 http://blog.csdn.net/sjzs ... -
Creating an iPhone Daemon – Part 5
2012-09-02 15:29 1540Creating an iPhone Daemon – ... -
Creating an iPhone Daemon – Part 4
2012-09-02 15:28 1408Creating an iPhone Daemon – ... -
Creating an iPhone Daemon – Part 2
2012-09-02 15:24 1260Here is part two of the blog ... -
Creating an iPhone Daemon – Part 1
2012-09-02 15:23 1167So I thought I would start t ...
相关推荐
Daemon Tools Lite 4.30.3是一款广受好评的虚拟光驱软件,尤其对于中文用户来说,其简体中文版本极大地便利了操作和理解。该版本为4.05版,表明它已经过多次更新和优化,以适应用户的需求和系统兼容性。 虚拟光驱是...
3. **快速加载**:Daemon Tools能够快速加载和卸载镜像,提供无缝的用户体验,无需等待物理光驱的读取时间。 4. **集成到资源管理器**:用户可以直接在Windows资源管理器中右键点击镜像文件,选择“装载”或“卸载...
"daemon.rar" 是一个包含"daemon.exe"的压缩包,该文件通常指的是Daemon Tools,这是一个非常流行的虚拟光驱软件,尤其适用于Windows操作系统。 Daemon Tools允许用户加载ISO、BIN等光盘映像文件,模拟出一个或多个...
虚拟光驱 daemon_tools_347cn_eric虚拟光驱 daemon_tools_347cn_eric虚拟光驱 daemon_tools_347cn_eric虚拟光驱 daemon_tools_347cn_eric虚拟光驱 daemon_tools_347cn_eric虚拟光驱 daemon_tools_347cn_eric虚拟光驱...
3. **光盘保护**: Daemon Tools支持多种光盘保护机制,如SafeDisc、SecuROM、ARMed等,使得用户可以在受保护的游戏中使用虚拟光驱。 4. **快速访问**: 虚拟光驱的读取速度远超物理光驱,尤其对于大容量的游戏或应用...
Daemon Tools是一款广受欢迎的虚拟光驱软件,尤其在游戏爱好者和系统管理员中有着广泛的使用。它的3.47版本是一个经典的老版本,以其小巧的体积(不到500KB)和出色的性能赢得了用户的好评。这个版本可能在很多地方...
Daemon Tools是一款广受欢迎的虚拟光驱软件,尤其在3.46版本时,它已经拥有相当成熟的稳定性和功能。这个版本特别为中国用户提供了简体中文界面,使得国内用户能够更加方便地操作和理解软件的各项功能。 Daemon ...
Daemon Tools是一款著名的虚拟光驱软件,它在IT领域中被广泛使用,特别是在游戏爱好者和系统管理员之间。Daemon Tools v4.0.9是该软件的一个版本,它允许用户创建虚拟CD和DVD驱动器,以便无需物理光盘即可运行软件、...
3. 检查“启动”文件夹(C:\Users\用户名\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup)和“系统启动”文件夹(C:\Windows\System32\config\systemprofile\Desktop),看是否有Daemon Tools的...
《虚拟光驱技术详解与DAEMON Tools V3.46简体中文版介绍》 在数字化时代,虚拟光驱作为一种高效、便捷的工具,已经逐渐成为计算机用户的重要辅助软件。虚拟光驱允许用户在没有物理光驱的情况下,通过创建虚拟光盘...
DaemonTools4.09是一款经典的虚拟光驱软件,它允许用户在计算机上模拟CD/DVD驱动器,无需物理光盘即可运行光盘映像文件。这个版本被特别提及为适用于Windows Server 2008操作系统,表明它兼容该服务器平台,但可能不...
标题中的"daemon3.47版"指的是Daemon Tools这一知名虚拟光驱软件的特定版本,即3.47版。Daemon Tools是历史悠久且广受好评的虚拟光驱软件之一,它提供多种操作系统平台的支持,包括Windows系统。 Daemon Tools的...
3. **多平台支持**:除了Windows操作系统,DAEMON Tools还可能对其他平台有所支持,尽管这里未明确提及,但通常这样的专业软件会考虑跨平台兼容性。 4. **易用界面**:DAEMON Tools以用户友好著称,它的界面设计...
Daemontools是一款功能强大的系统工具,主要用于管理和监控持续运行的服务。版本4.11是其一个重要的更新,特别地,这里的"中文完美版"意味着它已经进行了汉化处理,适合中国用户使用,无需担心语言障碍。这个版本的...
- `daemon-tools-3-17.exe`:这是Daemon Tools 3.17的安装程序文件。 6. **使用方法**:下载并解压压缩包后,用户需要找到对应版本的安装程序(通常是.exe文件),双击运行进行安装。安装过程中按照提示步骤操作,...
3. **支持多种格式**:除了常见的ISO和MDX格式,DAEMON Tools V4.08还兼容其他多种光盘映像格式,如BIN、CUE、NRG等,满足用户处理不同来源的光盘映像需求。 4. **安装和卸载简便**:DAEMON Tools的安装过程简单...
"daemon-0.8.tar.gz" 是一个在IT领域常见的压缩文件格式,它包含了名为 "daemon-0.8" 的项目或软件的源代码或资源。这个文件的命名方式表明它是一个版本号为0.8的守护进程(daemon)相关的程序。在Linux和Unix系统中...
DAEMON Tools Lite 可以制作简单光盘映像文件和模拟 CD/DVD 光驱的最流行软件产品 功能 加载 *.mdx, *.mds/*.mdf, *.iso, *.b5t, *.b6t, *.bwt, *.ccd, *.cdi, *.bin/*.cue, *.ape/*.cue, *.flac/*.cue, *.nrg, ...
Daemon Tools v4.03 V4.03HE 汉化版,相信经常使用虚拟光驱的人都应该记得,这是当年极其经典的一个版本。 现在的虚拟光驱越做越大,功能也越来越多,最新的版本Daemon Tools 安装后要占用硬盘50多M,然尔对一般的...
linux系统命令start-stop-daemon的源码及二进制,其中也提供了一个服务启动脚本模板。 此程序能帮助你实现将命令行程序变成服务运行,比如将"java -jar xxx.jar" 放在后台执行。 ./start-stop-daemon --help start-...