ios – NSURLSession vs后台获取

好的,我正在查看SimpleBackgroundFetch示例项目,它在App Delegate中使用以下内容
[[UIApplication sharedApplication] setMinimumBackgroundFetchInterval:someTimeInSeconds];
//^this code is in didFinishLaunchingWithOptions


-(void)application:(UIApplication *)application performFetchWithCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler
{
  //do something + call completionHandler depending on new data / no data / fail
}

所以,基本上我假设,我在这里调用我的应用程序服务器,以获取一些数据.

但后来我看到了NSURLSession docs,它有这样的方法

– downloadTaskWithURL:

并说它如下:

This API provides a rich set of delegate methods for supporting
authentication and gives your app the ability to perform background
downloads when your app is not running or,in iOS,while your app is
suspended.

那么这两个API之间的区别是什么?如果我想不时地从我的应用程序的服务器下载一些数据,我应该使用什么?

我只是不确定两者之间的区别,所以我只是觉得我应该在这里澄清我的怀疑.去StackOverflow!

解决方法

这些是完全不同的东西.

>后台获取:系统会在某个时间启动您的应用程序(启发式),您的工作就是开始为用户下载新内容.> NSURLSession:NSURLConnection的替换,允许在应用程序暂停后继续下载.

相关文章

UITabBarController 是 iOS 中用于管理和显示选项卡界面的一...
UITableView的重用机制避免了频繁创建和销毁单元格的开销,使...
Objective-C中,类的实例变量(instance variables)和属性(...
从内存管理的角度来看,block可以作为方法的传入参数是因为b...
WKWebView 是 iOS 开发中用于显示网页内容的组件,它是在 iO...
OC中常用的多线程编程技术: 1. NSThread NSThread是Objecti...