- 1、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。。
- 2、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 3、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
iOS8后台运行方案总结概要1
iOS 8.0后台任务长期运行方案
后台运行方案实现方式为:BackgroundRunner+NSURLSession
配置
在AppDelegate中
@property (assign, nonatomic) BOOL isBackground; //判读是否是后台运行
-(void)applicationDidEnterBackground:(UIApplication *)application
{
[[BackgroundRunner shared] run];
self.isBackground = yes;
}
//在回到界面后关闭后台运行
-(void)applicationWillEnterForeground:(UIApplication *)application {
[[BackgroundRunner shared] stop];
self.isBackground = NO;
}
手机密码锁开启后的文件保护问题设置
//设置常量
#define UrlsessionDownload @/com.apple.nsurlsessiond/Downloads/
#define BundleIdentifier [[NSBundle mainBundle] bundleIdentifier]
//打开uisesion目录的文件保护设置为无
//创建可使用的urlseseion路径
-(void)createUrlSession
{
NSString *theFMCachePath=nil;
NSArray *pathes = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
theFMCachePath = [pathes objectAtIndex:0];
theFMCachePath = [theFMCachePath stringByAppendingString:UrlsessionDownload];
theFMCachePath = [theFMCachePath stringByAppendingString:[NSString stringWithFormat:@%@/,BundleIdentifier]];
NSFileManager *fileManager = [NSFileManager defaultManager];
if(![fileManager isExecutableFileAtPath:theFMCachePath])
{
//设置文件为无权限保护
NSDictionary *attributes = [NSDictionary dictionaryWithObject:NSFileProtectionNone
forKey:NSFileProtectionKey];
[fileManager createDirectoryAtPath:theFMCachePath
withIntermediateDirectories:YES
attributes:attributes
error:nil];
}
}
4.上传sessioin的代码,(UploadSessionBackgound.h, UploadSessionBackgound.m)
//UploadSessionBackgound.h
#import Foundation/Foundation.h
@protocol UploadSessionBackgoundDelegate NSObject
-(void)requestUploadFinishDictionary:(NSDictionary *)dictionary;
@end
@interface UploadSessionBackgound : NSObjectNSURLSessionDataDelegate
@property(nonatomic, strong) NSURLSession *urlSession;
@prope
文档评论(0)