ios 中的session使用以及nsstring中方法的使用

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中使用的是最多的。




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值