NSCache的使用,SDWebImage的使用,Reachability联网状态检测框架的使用
来源:互联网 发布:php九九乘法表 编辑:程序博客网 时间:2024/05/01 23:04
NSCache 是苹果官方提供的缓存类,用法与 NSMutableDictionary 的用法很相似,在 AFNetworking 和 SDWebImage 中,使用它来管理缓存
NSCache 是线程安全的,在多线程操作中,不需要对 Cache 加锁
NSCache 的 Key 只是做强引用,不需要实现 NSCopying 协议
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
SDWebImage框架的使用:(做图片缓存就一句话搞定)
<span style="font-size:18px;">[cell.imageView sd_setImageWithURL:[NSURL URLWithString:app.icon] placeholderImage:[UIImage imageNamed:@"user_default"]];</span>
还可以显示下载进度:
<span style="font-size:18px;">[cell.imageView sd_setImageWithURL:[NSURL URLWithString:app.icon] placeholderImage:[UIImage imageNamed:@"user_default"] options:0 progress:^(NSInteger receivedSize, NSInteger expectedSize) { // receivedSize 已经接受到的大小 // expectedSize 期望的大小,总大小 float progress = (float)receivedSize/expectedSize; NSLog(@"下载进度 %f", progress); } completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) { NSLog(@"%@", [NSThread currentThread]); }];</span>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Reachability(联网状态的检测)框架的使用:
typedef enum : NSInteger {NotReachable = 0, // 没有连接ReachableViaWiFi, // wifiReachableViaWWAN // 2G/3G/4G} NetworkStatus;
#import "ViewController.h"#import "Reachability.h"@interface ViewController ()@property(nonatomic,strong)Reachability *reach;@end@implementation ViewController- (void)viewDidLoad { [super viewDidLoad]; // 判断能否连接到某一个主机 // http://www.baidu.com self.reach = [Reachability reachabilityWithHostName:@"baidu.com"]; // 添加通知 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(reachabilityChanged) name:kReachabilityChangedNotification object:nil]; // 开始监听 [self.reach startNotifier];}- (void)dealloc{ // 停止监听 [self.reach stopNotifier]; // 移除监听 // 移除整个控制器里所有的监听// [[NSNotificationCenter defaultCenter] removeObserver:self]; // 移除控制器里的kReachabilityChangedNotification监听 [[NSNotificationCenter defaultCenter] removeObserver:self name:kReachabilityChangedNotification object:nil];}- (void)reachabilityChanged{ // 状态 switch (self.reach.currentReachabilityStatus) { case NotReachable: NSLog(@"没有连接"); break; case ReachableViaWiFi: NSLog(@"不用花钱"); break; case ReachableViaWWAN: NSLog(@"要流量"); break; default: NSLog(@"。。。。。。"); break; }}
0 0
- NSCache的使用,SDWebImage的使用,Reachability联网状态检测框架的使用
- Reachability框架(联网状态的检测)
- NSCache 原理 (著名开源框架SDWebImage 就是使用的NSCache实现的缓存)
- 网络状态检测------苹果官方示例Reachability的使用
- NSCache的简单使用
- 关于NSCache的使用
- NSCache的基本使用
- Reachability 网络状态的使用和封装
- 网络状态监测之 Reachability的使用
- 网络状态监测Reachability的使用
- Reachability的使用
- tonymillion/Reachability的使用
- iOS---NSCache的简单使用
- NSCache的简单使用介绍
- ios之NSCache的使用
- iOS 使用Reachability检测网络状态
- iOS网络状态监测之Reachability的使用
- 使用苹果自带的Reachability监听网络状态
- 表达式和运算符学习笔记
- 前序创建二叉树+ 前序/中序/后序遍历二叉树
- 09-网站标题图片设置
- Nginx负载均衡配置实例详解
- get和post
- NSCache的使用,SDWebImage的使用,Reachability联网状态检测框架的使用
- 《leetCode》:Rotate Image
- 大话AlarmManage
- swift 重载 泛式 inout的使用
- android视图的一些总结
- 丹田练习小总结
- jsp乱码问题
- 当刘小立访问Google时,刘小立如何能访问? ---《计算机网络-自顶向下方法》
- android studio 如何设置代码区域的背景色