- 浏览: 67153 次
- 性别:
- 来自: 北京
最新评论
-
xiaogezq0:
楼主好厉害!求demo。。。。。
那些年我们一起纠结的崩溃——iOS -
yushuaiyun0322:
学姐V5
配置开发者证书 -
be_as_me:
已下载,谢谢分享!
配置开发者证书 -
2012北漂:
饿饱了就吃,最近忙什么呢? 怎么又想起来玩按钮了?
IOS按钮拖动和点击 -
北京-Henry:
苹果手势简单用法
大家都知道我们的程序在后台运行的时间是10分钟,10分钟后便会停止。但是像实时定位,播放音频,以及网络电话这些功能我们需要在后台持续运行。那么我们就要进行相应的设置。
下面具体的例子以定位为例
#import <UIKit/UIKit.h>
#import <CoreLocation/CoreLocation.h>
@interface BackgroundTrackerViewController : UIViewController<CLLocationManagerDelegate>
@property(nonatomic, retain) CLLocationManager *locationManager;
@property(nonatomic, retain) UIButton *startTrackingButton;
@property(nonatomic, retain) UILabel *alertLabel;
- (void)startTracking:(id)sender;
#import "BackgroundTrackerViewController.h"
@interface BackgroundTrackerViewController ()
@end
@implementation BackgroundTrackerViewController
@synthesize locationManager,startTrackingButton,alertLabel;
//开始跟踪
- (void)startTracking:(id)sender
{
[locationManager startUpdatingLocation];
}
-(void)start:(id)sender
{
// [locationManager startUpdatingLocation];
}
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
self.view.backgroundColor=[UIColor grayColor];
self.startTrackingButton=[UIButton buttonWithType:UIButtonTypeRoundedRect];
startTrackingButton.frame=CGRectMake(0, 200, 100, 50);
[startTrackingButton addTarget:self action:@selector(startTracking:) forControlEvents:UIControlEventTouchUpInside];
[startTrackingButton setTitle:@"startTracking" forState:UIControlStateNormal];
[self.view addSubview:startTrackingButton];
self.alertLabel=[[UILabel alloc]initWithFrame:CGRectMake(0, 100, 320, 50)];
self.alertLabel.backgroundColor=[UIColor orangeColor];
self.alertLabel.hidden=YES;
self.alertLabel.text=@"无法找到位置";
[self.view addSubview:alertLabel];
locationManager = [[CLLocationManager alloc] init];
[locationManager setDelegate:self];
//Only applies when in foreground otherwise it is very significant changes
[locationManager setDesiredAccuracy:kCLLocationAccuracyBest];//要求的精确度
}
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation {
CLLocationCoordinate2D currentCoordinates = newLocation.coordinate;
[alertLabel setText:@"Location Has been found"];
[alertLabel setHidden:NO];
NSLog(@"Entered new Location with the coordinates Latitude: %f Longitude: %f", currentCoordinates.latitude, currentCoordinates.longitude);
}
- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error {
NSLog(@"Unable to start location manager. Error:%@", [error description]);
[alertLabel setHidden:NO];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (void)applicationDidEnterBackground:(UIApplication *)application
{
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
if ([[UIDevice currentDevice] respondsToSelector:@selector(isMultitaskingSupported)])
{ //Check if our iOS version supports multitasking I.E iOS 4
if ([[UIDevice currentDevice] isMultitaskingSupported])
{ //Check if device supports mulitasking
UIApplication *application = [UIApplication sharedApplication]; //Get the shared application instance
__block UIBackgroundTaskIdentifier background_task; //Create a task object
background_task = [application beginBackgroundTaskWithExpirationHandler: ^{
/*
当应用程序后台停留的时间为0时,会执行下面的操作(应用程序后台停留的时间为600s,可以通过backgroundTimeRemaining查看)
*/
[application endBackgroundTask: background_task]; //Tell the system that we are done with the tasks
background_task = UIBackgroundTaskInvalid; //Set the task to be invalid
//System will be shutting down the app at any point in time now
}];
// Background tasks require you to use asyncrous tasks
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
//Perform your tasks that your application requires
NSLog(@"time remain:%f", application.backgroundTimeRemaining);
[application endBackgroundTask: background_task]; //End the task so the system knows that you are done with what you need to perform
background_task = UIBackgroundTaskInvalid; //Invalidate the background_task
});
}
}
}
修改应用的Info.plist 文件,你需要在Info.plist文件中添加UIBackgroundModes字段,该字段的值是应用支持的所有后台模式,是一个数值类型。目前此数 组可以包含“audio”、“location”和“voip”这三个字符串常量.
发表评论
-
苹果消息推送问题总结
2015-08-03 17:46 847问题1、消息注册代码 ... -
WebReuestManager使用说明
2014-07-18 17:27 699WebReuestManager是网上流传多年的一个请求类, ... -
WebViewJavascriptBridge使用说明(IOS)
2014-06-11 14:40 9305因为最近项目需要跨平台,在网上找到这个demo拿来用。 ... -
那些年我们一起纠结的崩溃——iOS
2013-12-17 10:46 18431.2013-12-17 10:38:47.205 一类调 ... -
IOS 下架已上传的应用
2013-12-03 11:25 1064在itunesconnect里的app详情里面找到right ... -
ios方法延时的类目
2013-10-10 00:33 110701 @implementation NSObjec ... -
配置开发者证书
2013-09-11 11:24 1135自己总结的,截图绝对够全,并且是最新的还有问题可以QQ联系 ... -
GCD---传说中的多线程
2013-07-09 17:52 0多线程好神秘得东西 ... -
IOS cookies 和session 的含义和使用
2013-06-26 13:55 0cookies -
IOS按钮拖动和点击
2013-06-09 09:49 2559按钮初始化 - (void)viewDidLoad { ... -
手机号码后N位改为“*”(类目)
2013-06-08 13:53 1116@interface NSString (mima) ... -
iOS自动匹配名称、代码、开头字母的UIFextField
2013-05-15 15:16 1155这段时间要实现自动匹配名称、代码、开头字母,自己写出一个d ... -
ios判断程序第一次进入
2013-05-14 11:16 1770if (![[NSUserDefaultsstan ... -
IOS验证码
2013-05-08 15:56 1643项目需要验证码的验证,我自己写了一个的验证码大家随便看一下 ... -
IOS自动登录Demo
2013-04-25 17:12 2229自己写的自动登录简单实现,没有排版,样子丑了点,但是模拟了 ... -
IOS正弦Sin,余弦Cos,正切Tan的计算
2013-04-24 17:33 7557在ios中可以完全兼容c的函数,所以第一步要导入 #inc ... -
IOS键盘监听
2013-04-18 15:01 1760键盘消失 [[NSNotificationCen ... -
常用的宏积累
2013-04-16 12:34 711http://www.cocoachina.com/apple ... -
苹果手势简单用法
2013-03-28 16:55 940//单指单击 2: UITapGestureRecog ... -
获取屏幕上当前相应者
2013-03-27 19:11 930UIWindow *keyWindow = [[UI ...
相关推荐
本软件需要的权限包括:打开网络接口、读取用户的联系人数据、监督、限定或终止呼出的电话、访问网络上的信息、访问范围(如WIFI)性的定位、记录音频信息、读取电话的状态、访问震动器、写用户的外部存储器;...
后台可设置信息发布是否需在通过审核、信息发布间隔时间、同一会员允许当天发布信息数量、电话过滤、非法字过滤、会员注册邮箱激活,多重过滤保障了信息的真实性、实用性。上海分类信息网站,地方分类信息网站,天津...
后台可设置信息发布是否需在通过审核、信息发布间隔时间、同一会员允许当天发布信息数量、电话过滤、非法字过滤、会员注册邮箱激活,多重过滤保障了信息的真实性、实用性。上海分类信息网站,地方分类信息网站,天津...
后台可设置信息发布是否需在通过审核、信息发布间隔时间、同一会员允许当天发布信息数量、电话过滤、非法字过滤、会员注册邮箱激活,多重过滤保障了信息的真实性、实用性。上海分类信息网站,地方分类信息网站,天津...
视频音频解码部分。 MFC_MultiSender_OVER 文件传送,多文件(超大文件)传送功能的实现,含文档。 MFC+DLL的编写和调用示例 如题。 MFC换肤完全贴图实现 如题。 Smile简体版 很简单,只能播放mp3格式的音乐。 ...
视频音频解码部分。 MFC_MultiSender_OVER 文件传送,多文件(超大文件)传送功能的实现,含文档。 MFC+DLL的编写和调用示例 MFC换肤完全贴图实现 Smile简体版 Linux内核完全注释附 MFC+消息循环贴图---金山...
视频音频解码部分。 MFC_MultiSender_OVER 文件传送,多文件(超大文件)传送功能的实现,含文档。 MFC+DLL的编写和调用示例 MFC换肤完全贴图实现 Smile简体版 Linux内核完全注释附 MFC+消息循环贴图---金山...
视频音频解码部分。 MFC_MultiSender_OVER 文件传送,多文件(超大文件)传送功能的实现,含文档。 MFC+DLL的编写和调用示例 MFC换肤完全贴图实现 Smile简体版 Linux内核完全注释附 MFC+消息循环贴图---金山...
视频音频解码部分。 MFC_MultiSender_OVER 文件传送,多文件(超大文件)传送功能的实现,含文档。 MFC+DLL的编写和调用示例 MFC换肤完全贴图实现 Smile简体版 Linux内核完全注释附 MFC+消息循环贴图---金山...
视频音频解码部分。 MFC_MultiSender_OVER 文件传送,多文件(超大文件)传送功能的实现,含文档。 MFC+DLL的编写和调用示例 MFC换肤完全贴图实现 Smile简体版 Linux内核完全注释附 MFC+消息循环贴图---金山...
Handset Handset Handset Handset Manufacturers Manufacturers Manufacturers Manufacturers 电话制造商 ASUSTeK Computer Inc. 华硕 Garmin International, Inc. HTC Corporation ( 多普达的母公司 ) 宏达电子 ...
Webview WebView(网络视图)能加载显示网页,可以将其视为一个浏览器。它使用了WebKit渲染引擎加载显示网页 Activity Activity是一个应用程序组件,提供一个屏幕,用户可以用来交互为了完成某项任务,是一个负责与...