1、网络的请求以及下载
NSURLSessionConfiguration *sessionConfig;
if ([[[UIDevice currentDevice] systemVersion] floatValue] >=8.0f)
{
sessionConfig =[NSURLSessionConfiguration backgroundSessionConfigurationWithIdentifier:@"downloads"];
}
else
{
sessionConfig = [NSURLSessionConfiguration backgroundSessionConfiguration:@"downloads"];
}
//ios中每一次与网络的请求都是和session有关系的。
when downloading the resource from server,we can use NSUrlSession.
(使应用在后台下载)
+backgroundSessionConfiguration: is deprecated. Please use
+backgroundSessionConfigurationWithIdentifier: instead.
使用的实例:可以查看一下自己的项目中下载资源的部分。
- (instancetype)init
{
self = [super init];
if (self) {
NSURLSessionConfiguration *backgroundConfiguration;
if ([Helper isGreaterOrEqualToIOS8]) {
backgroundConfiguration = [NSURLSessionConfiguration backgroundSessionConfigurationWithIdentifier:@"configIdentifier"];
}else{
backgroundConfiguration = [NSURLSessionConfiguration backgroundSessionConfiguration:@"configIdentifier"];
}
self.backgroundSession = [NSURLSession sessionWithConfiguration:backgroundConfiguration delegate:self delegateQueue:[NSOperationQueue mainQueue]];
}
return self;
}
有关session的讲解:
http://hw1287789687.iteye.com/blog/1968385
2、字符串中处理的方法,在Ios 8 前后的不同的处理方法:
由于:
- (BOOL)containsString:(NSString *)str NS_AVAILABLE(10_10, 8_0);
这个方法是只可以在ios 8 使用,所以在ios 7 中很可能会出现崩溃的可能。
(干脆写一个分类俩实现他们的判断是否存在字符串:string)
#import "NSString+Contains.h"
@implementation NSString (Contains)
- (BOOL)myContainsString:(NSString*)string{
NSRange range = [self rangeOfString:string];
if (range.location !=NSNotFound) {
return YES;
}
return NO;
}
@end
参考链接:
http://stackoverflow.com/questions/25325130/ios8-backgroundsessionconfiguration-is-deprecated
有关网络的请求,在AFNetworking中使用的是最多的。