CocoaPods插件安装
上次讲了如何安装CocoaPods,安装完成后,是不是觉得敲着终端命令有点累,而且一个不小心就敲错了,那么就用Xcode里的CocoaPods插件吧!
首先你得安装Alcatraz,(Alcatraz是一个管理插件的插件,方便安装和卸载)直接去github上下载zip然后解压用Xcode运行(用终端命令的话因为GFW所以不行),关闭Xcode重新打开,如果出现Load bundle和Skip Bundle,一定要选左边的Load bundle

接下来如果在Window
里看到了Package Manager
就证明安装成功了,然后点击打开

打开后搜索,然后安装

如果打开一片空白就是需要翻~墙,翻不了墙的直接下载CocoaPods插件然后安装(我不知道github有没有被墙,如果墙了的话请在下方评论,我会把插件上传到网盘),安装成功后Product
下就会有CocoaPods
,$GEM_HOME
路径可以安装下图的方式,也可以根据github的方式。
/usr/bin
/usr/local/bin
$GEM_HOME/bin
${GEM_HOME}/bin
$GEM_PATH/bin
${GEM_PATH}/bin
/SOME_PARENT/$GEM_HOME/bin
/SOME_PARENT/$GEM_PATH/bin

随后新建一个工程来测试了,新建以后创建Podfile文件Product->CocoaPods->Create/Edit Podfile


这里我试了试Cocoapods官网的方法可以正常安装,但是想上图一样的格式没法正常安装所以就舍弃上面的格式(如果你知道上图的格式请在下方评论,谢谢),贴入下面代码(Podfile格式解析)
source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '9.3'
use_frameworks!
target 'Test' do
pod 'SDWebImage', '~>3.7.6'
pod 'Masonry', '~>1.0.0'
end
目前我使用的格式
# source 'https://github.com/CocoaPods/Specs.git'
# platform :ios, '9.3'
# use_frameworks!
# 井号后面的是注释的内容
target 'Test' do
pod 'Masonry'
pod 'SDWebImage'
end
#可以不用写版本号,默认是最新版本
然后安装

安装完成后控制台会输出信息,并且弹出一个窗口,选Yes


此时的目录结构

打开后,你就会发现安装框架的都在Pods工程下的Pods文件夹里

接下来你就可以在ViewController.m里贴入以下代码测试
#import "ViewController.h"
#define MAS_SHORTHAND
#define MAS_SHORTHAND_GLOBALS
//#import "UIImageView+WebCache.h"
#import <SDWebImage/UIImageView+WebCache.h>
//#import <Masonry/Masonry.h>
#import "Masonry.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
UIImageView *v = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"21663230_165034300243_2"]];
v.frame = CGRectMake(0, 49, 240, 128);
[self.view addSubview:v];
[v sd_setImageWithURL:[NSURL URLWithString:@"http://pic75.nipic.com/file/20150825/21663230_165034300243_2.jpg"] placeholderImage:nil];
UIView *blueView = [[UIView alloc] init];
blueView.backgroundColor = [UIColor blueColor];
[self.view addSubview:blueView];
[blueView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.view).offset(0);
make.width.equalTo(100);
make.height.equalTo(50);
make.top.equalTo(v.bottom).offset(150);
}];
}
@end
运行后你会发现本来是用URLWithString引入了一张网络图片但是怎么不显示?
原因是iOS9中新增App Transport Security(简称ATS)特性, 主要使到原来请求的时候用到的HTTP,都转向TLS1.2协议进行传输。这也意味着所有的HTTP协议都强制使用了HTTPS协议进行传输。
所以需要去Info.plist里设置
1 . 选择Information Property List

2 . 点击添加,然后把滑落滑到最上面选择第三个App Transport Security Settings

3 . 接着展开App Transport Security Settings选项(点击左边的箭头,箭头向下),然后点击添加按钮,最后把Value设置为Yes就行了

键盘操作:点击Information Property List后,enter ↑ ↑ ↑ enter enter → enter tab ↑ enter
运行后可能你还是没显示图片,这时command+k然后command+b编译一下,运行就有效果了(还没有效果就多点几下command+k)
