下面是内存溢出 jb51.cc 通过网络收集整理的代码片段。
内存溢出小编现在分享给大家,也给大家做个参考。
- (BOol)application:(UIApplication *)application dIDFinishLaunchingWithOptions:(NSDictionary *)launchOptions { [application setMinimumBackgroundFetchInterval:UIApplicationBackgroundFetchIntervalMinimum]; NSLog(@"Launched in background %d",UIApplicationStateBackground == application.applicationState); return YES;}// 1.利用Background Fetch- (voID)application:(UIApplication *)application performFetchWithCompletionHandler:(voID (^)(UIBackgroundFetchResult))completionHandler { NSURLSessionConfiguration *sessionConfiguration = [NSURLSessionConfiguration defaultSessionConfiguration]; NSURLSession *session = [NSURLSession sessionWithConfiguration:sessionConfiguration]; NSURL *url = [[NSURL alloc] initWithString:@"http://127.0.0.1/data.Json"]; NSURLSessionDataTask *task = [session dataTaskWithURL:url completionHandler:^(NSData *data,NSURLResponse *response,NSError *error) { if (error) { completionHandler(UIBackgroundFetchResultFailed); return; } completionHandler(UIBackgroundFetchResultNewData); }]; [task resume];}// 2.利用Remote Notification/* 推送的内容 { "aps" : { "content-available" : 1 },"content-ID" : 42 } */- (voID)application:(UIApplication *)applicationdIDReceiveRemoteNotification:(NSDictionary *)userInfofetchCompletionHandler:(voID (^)(UIBackgroundFetchResult))completionHandler{ NSLog(@"Received remote notification with userInfo %@",userInfo); NSNumber *contentID = userInfo[@"content-ID"]; Nsstring *downloadURLString = [Nsstring stringWithFormat:@"http://yourserver.com/downloads/%d.mp3",[contentID intValue]]; NSURL* downloadURL = [NSURL URLWithString:downloadURLString]; NSURLRequest *request = [NSURLRequest requestWithURL:downloadURL]; NSURLSessionDownloadTask *task = [[self backgroundURLSession] downloadTaskWithRequest:request]; task.taskDescription = [Nsstring stringWithFormat:@"podcast Episode %d",[contentID intValue]]; [task resume]; completionHandler(UIBackgroundFetchResultNewData);}- (NSURLSession *)backgroundURLSession{ static NSURLSession *session = nil; static dispatch_once_t oncetoken; dispatch_once(&oncetoken,^{ Nsstring *IDentifIEr = @"io.objc.backgroundTransferExample"; NSURLSessionConfiguration* sessionConfig = [NSURLSessionConfiguration backgroundSessionConfiguration:IDentifIEr]; session = [NSURLSession sessionWithConfiguration:sessionConfig delegate:self delegateQueue:[NSOperationQueue mainQueue]]; }); return session;}
以上是内存溢出(jb51.cc)为你收集整理的全部代码内容,希望文章能够帮你解决所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
总结以上是内存溢出为你收集整理的ios后台更新和下载全部内容,希望文章能够帮你解决ios后台更新和下载所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)