- 浏览: 1315094 次
- 性别:
- 来自: 成都
文章分类
- 全部博客 (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 ...
通用大型网站页面静态化解决方案(一)
Here is part two of the blog series “Creating an iPhone Daemon”, for part one please click this link
As I said in part 1, we will be creating the DLocationDelegate class.
With most daemons, you do a task like read a file, do something with that file, sleep for a certain amount of time, then check for file changes, and repeat the steps over again. Unfortunately, with GPS coordinates, we have to wait for the CoreLocation delegate to give us the coordinates. The thing about Objective-C and Apple’s Cocoa framework is that most of the classes depend heavily on delegates. This is also true when dealing with the CoreLocation APIs. So lets get coding.
So lets write the DLocationDelegate header file first, this will give us a good look at what is ahead
#import <CoreLocation/CoreLocation.h> #import <Foundation/Foundation.h> #import <UIKit/UIKit.h> @interface DLocationDelegate : NSObject <CLLocationManagerDelegate> { BOOL trackingGPS; CLLocationManager *locationManager; } @property (nonatomic, retain) CLLocationManager *locationManager; - (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation; - (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error; -(void) startIt:(NSTimer *) timer; -(void) startItAgain:(NSTimer *)timer; - (void)connectionDidFinishLoading:(NSURLConnection *)connection; @end
So lets go through this line by line starting with our imports
#import <CoreLocation/CoreLocation.h> #import <Foundation/Foundation.h> #import <UIKit/UIKit.h>
The most important import we have here is the CoreLocation framework, this will let us use the CLLocationManager class.
@interface DLocationDelegate : NSObject <CLLocationManagerDelegate>
When you have a class name in <> symbols, Objective-C now knows that you are implementing methods from this class. In this case to receive the GPS coordinates we use the CLLocationManagerDelegate protocol
BOOL trackingGPS; CLLocationManager *locationManager;
The Boolean trackingGPS will tell us if we are currently tracking the GPS, this will be used to tell if the CLLocationManager is currently looking for coordinates. The locationManager is the actual class that will get the GPS coordinates from either the GPS (iPhone 3G) or the cell towers (iPhone 2G).
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation; - (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error;
These are the delegate methods for the CLLocationManagerDelegate. The first one “didUpdateToLocation” will give us the coordinates using a CLLocation class which contains a longitude, latitude, and sometimes even a altitude. The second function will notify our DLocationDelegate of any errors with the GPS, maybe if your iPhone is inside a lead case .
-(void) startIt:(NSTimer *) timer; -(void) startItAgain:(NSTimer *)timer;
We will use these functions to start the GPS after a certain amount of time.
- (void)connectionDidFinishLoading:(NSURLConnection *)connection;
This is for the NSURLConnection object that will send the GPS coordinates to our server.
In part three of this tutorial we will create the DLocationDelegate.m file (the implementation file)
-Chris
转自 :http://chrisalvares.com/blog/30/creating-an-iphone-daemon-part-2/
发表评论
-
ios 声音合成
2013-08-18 13:20 1236http://stackoverflow.com/ques ... -
__bridge,__bridge_retained和__bridge_transfer的意思,区别与使用 20 三
2012-12-24 01:41 1642使用ARC能帮我们减轻不少内存管理方面的负担,尤其是对用 ... -
CAAnimation
2012-12-23 01:09 2303CAAnimation采用了CAMediaTi ... -
UIViewAnimation动画与Core Animation的CATransition类动画
2012-12-23 01:06 2697使用UIView类函数实现://U ... -
GCD实战2:资源竞争
2012-12-23 01:04 1553转自http://www.dreamingwish.co ... -
GCD实战一:使用串行队列实现简单的预加载
2012-12-22 17:10 2820转自 http://www.dreamingwish.c ... -
GCD介绍(四): 完结
2012-12-22 17:08 1327转自 http://www.dreamingwish.c ... -
GCD介绍(三): Dispatch Sources
2012-12-22 17:07 1599转自 http://www.dreamingwish.com/ ... -
GCD介绍(二): 多核心的性能
2012-12-22 17:05 1150转自http://www.dreamingwish.co ... -
基本概念和Dispatch Queue
2012-12-22 17:03 1316转自 http://www.dreamingwish.c ... -
Best Audio Format for iPhone Audio Programming
2012-12-19 16:26 2506I had never done audio p ... -
LAME 是一个开源的MP3解码编码工具
2012-12-19 13:09 8501MP3 Encoding * 编码MP3文件必须按如下 ... -
sqlite3中的数据类型
2012-12-10 21:37 1267(转)http://www.cnblogs.com/kfqco ... -
ios随机数,and()、random()、arc4random()
2012-11-15 11:06 4690原文:http://bj007.blog.51cto.c ... -
IPHONE GIF 播放的方式
2012-10-11 18:30 1415转 http://blog.csdn.net/zltia ... -
在新线程中使用NSTimer
2012-10-11 18:21 1552转自 http://blog.csdn.net/sjzs ... -
Creating an iPhone Daemon – Part 5
2012-09-02 15:29 1508Creating an iPhone Daemon – ... -
Creating an iPhone Daemon – Part 4
2012-09-02 15:28 1379Creating an iPhone Daemon – ... -
Creating an iPhone Daemon – Part 3
2012-09-02 15:25 1477This is part three of the bl ... -
Creating an iPhone Daemon – Part 1
2012-09-02 15:23 1132So I thought I would start t ...
相关推荐
Example of creating a service / daemon on QT
Daemon_Tools Daemon_Tools Daemon_Tools Daemon_Tools
虚拟光驱 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 程序例子daemon 程序例子daemon 程序例子
daemon.rar 虚拟光驱,安装iso文件的好东西
daemontool4.11中文完美版daemontool4.11中文完美版daemontool4.11中文完美版
Daemon Tools v4.03 V4.03HE 汉化版,相信经常使用虚拟光驱的人都应该记得,这是当年极其经典的一个版本。 现在的虚拟光驱越做越大,功能也越来越多,最新的版本Daemon Tools 安装后要占用硬盘50多M,然尔对一般的...
daemon344光驱模拟器
虚拟光驱daemon
Daemon Tools 3.46 简体中文版.rar 内有Daemon Tools 3.46 简体中文版.rar; daemon.log
daemon341.exe 虚拟光驱
HA-daemon4301HA-daemon4301
虚拟光驱 daemon408-x86免费版本
DaemonTools
虚拟光驱软件DaemonTools 4.09
DAEMON Tools 4.30.1 最新汉化版HA-daemon4301-lite.EXE
Daemon Tools现在同时支持32位和64位操作系统。 一个不错的虚拟光驱工具,支持Win9x/win2k,支持ps,支持加密光盘,装完不需启动即可用。是一个先进的模拟备份并且合并保护盘的软件,可以备份SafeDisc保护的软件,...
DAEMONTools4.12.1汉化版DAEMONTools4.12.1汉化版DAEMONTools4.12.1汉化版DAEMONTools4.12.1汉化版
“学会与别人分享自己的快乐”——虚拟光驱软件,DaemonTools4.09 ,经测试 Window Server 2008可用,win7 还是不能用~无任何插件及不良信息,放心使用!