ios后台运行程序
来源:互联网 发布:桌面工作计划软件 编辑:程序博客网 时间:2024/05/16 07:24
http://blog.csdn.net/csharpjasp/article/details/6833343
1.运行逻辑代码:
-(void)execBackrgoundMethod
{
/*
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.
*/
UIApplication* app = [UIApplication sharedApplication];
bgTask = [app beginBackgroundTaskWithExpirationHandler:^{
[app endBackgroundTask:bgTask];
bgTask = UIBackgroundTaskInvalid;
}];
// Start the long-running task and return immediately.
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT,
0), ^{
/*
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.
*/
UIApplication* app = [UIApplication sharedApplication];
bgTask = [app beginBackgroundTaskWithExpirationHandler:^{
[app endBackgroundTask:bgTask];
bgTask = UIBackgroundTaskInvalid;
}];
// Start the long-running task and return immediately.
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT,
0), ^{
//在这里写你要在后运行行的代码
[app endBackgroundTask:bgTask];
bgTask = UIBackgroundTaskInvalid;
});
}
2.后台弹出UILocalNotification:
- (void)scheduleAlarmForDate:(NSDate*)theDate
{
//theDate延迟多长时间弹出
UIApplication* app = [UIApplication sharedApplication];
NSArray* oldNotifications = [app scheduledLocalNotifications];
// Clear out the old notification before scheduling a new one.
if ([oldNotifications count] > 0)
[app cancelAllLocalNotifications];
// Create a new notification.
UILocalNotification* alarm = [[[UILocalNotification alloc] init] autorelease];
if (alarm)
{
alarm.fireDate = theDate;
alarm.timeZone = [NSTimeZone defaultTimeZone];
alarm.repeatInterval = 0;
alarm.soundName = @"alarmsound.caf";
alarm.alertBody = @"Time to wake up!";
[app scheduleLocalNotification:alarm];
}
}
{
//theDate延迟多长时间弹出
UIApplication* app = [UIApplication sharedApplication];
NSArray* oldNotifications = [app scheduledLocalNotifications];
// Clear out the old notification before scheduling a new one.
if ([oldNotifications count] > 0)
[app cancelAllLocalNotifications];
// Create a new notification.
UILocalNotification* alarm = [[[UILocalNotification alloc] init] autorelease];
if (alarm)
{
alarm.fireDate = theDate;
alarm.timeZone = [NSTimeZone defaultTimeZone];
alarm.repeatInterval = 0;
alarm.soundName = @"alarmsound.caf";
alarm.alertBody = @"Time to wake up!";
[app scheduleLocalNotification:alarm];
}
}
- ios后台运行程序
- ios后台运行程序
- iOS后台运行程序
- ios 程序后台运行
- iOS 后台运行程序
- iOS后台运行程序
- iOS中程序后台运行
- 关于iOS程序后台运行
- iOS 保持程序后台运行
- iOS 程序后台运行保持程序后台长时间运行
- IOS程序后台运行及多任务
- 关于ios程序的后台运行
- ios后台运行程序 的一些总结
- 关于ios程序的后台运行
- 关于ios程序的后台运行
- iOS 程序退到后台长期运行
- iOS 运行程序和进入后台通知
- iOS程序后台运行继续完成操作
- 博客开张首帖!!!撒花~~
- adt导入老版本eclipse项目时不能运行原因
- 使用Spread Studio for .NET自定义行和列的数量
- 字符串替换
- C细节:内存方面
- ios后台运行程序
- 使用libnet与libpcap构造TCP/IP协议软件
- 机器学习中的算法(1)-决策树模型组合之随机森林与GBDT
- 各浏览器下使用 OBJECT 元素和 EMBED 元素嵌入 Flash 存在差异
- webView 总结
- shell 跳转目录
- JS自动判断浏览器分辨率
- servlet线程安全解析
- 线性代数--向量--行列式