-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathatom.xml
More file actions
316 lines (290 loc) · 58.3 KB
/
Copy pathatom.xml
File metadata and controls
316 lines (290 loc) · 58.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
<title><![CDATA[CarryRee's blog]]></title>
<subtitle><![CDATA[Welcome]]></subtitle>
<link href="/atom.xml" rel="self"/>
<link href="http://yoursite.com/"/>
<updated>2018-05-09T02:42:05.872Z</updated>
<id>http://yoursite.com/</id>
<author>
<name><![CDATA[CarryRee]]></name>
</author>
<generator uri="http://hexo.io/">Hexo</generator>
<entry>
<title><![CDATA[Interruption]]></title>
<link href="http://yoursite.com/2018/05/09/Interruption/"/>
<id>http://yoursite.com/2018/05/09/Interruption/</id>
<published>2018-05-09T02:19:20.000Z</published>
<updated>2018-05-09T02:42:05.872Z</updated>
<content type="html"><![CDATA[<h1 id="iOS监听中断方法"><a href="#iOS监听中断方法" class="headerlink" title="iOS监听中断方法"></a>iOS监听中断方法</h1><p>有时候播放音乐的时候会被电话或打开其他播放器,这个时候声音会被抢占,这个时候则需要监听中断</p>
<h2 id="注册通知"><a href="#注册通知" class="headerlink" title="注册通知"></a>注册通知</h2><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div></pre></td><td class="code"><pre><div class="line">[[NSNotificationCenter defaultCenter] addObserver:self</div><div class="line"> selector:@selector(audioSessionInterruptionNotification:)</div><div class="line"> name:AVAudioSessionInterruptionNotification</div><div class="line"> object:nil];</div></pre></td></tr></table></figure>
<h2 id="通知方法"><a href="#通知方法" class="headerlink" title="通知方法"></a>通知方法</h2><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div></pre></td><td class="code"><pre><div class="line">// 监听中断通知调用的方法</div><div class="line">- (void)audioSessionInterruptionNotification:(NSNotification *)notification {</div><div class="line"> int type = [notification.userInfo[AVAudioSessionInterruptionOptionKey] intValue];</div><div class="line"></div><div class="line"> switch (type) {</div><div class="line"> case AVAudioSessionInterruptionTypeBegan: // 被打断</div><div class="line"> break;</div><div class="line"> case AVAudioSessionInterruptionTypeEnded: // 中断结束</div><div class="line"> break;</div><div class="line"> default:</div><div class="line"> break;</div><div class="line"> }</div><div class="line">}</div></pre></td></tr></table></figure>
]]></content>
<summary type="html">
<![CDATA[<h1 id="iOS监听中断方法"><a href="#iOS监听中断方法" class="headerlink" title="iOS监听中断方法"></a>iOS监听中断方法</h1><p>有时候播放音乐的时候会被电话或打开其他播放器,这个时候声音会被抢占,这个时候则需要监]]>
</summary>
</entry>
<entry>
<title><![CDATA[将Framework提交Cocoapods]]></title>
<link href="http://yoursite.com/2018/02/09/uploadPod/"/>
<id>http://yoursite.com/2018/02/09/uploadPod/</id>
<published>2018-02-09T06:13:43.000Z</published>
<updated>2018-02-09T06:22:35.225Z</updated>
<content type="html"><![CDATA[<h2 id="一-上传framework到Github"><a href="#一-上传framework到Github" class="headerlink" title="一.上传framework到Github"></a>一.上传framework到Github</h2><p>参考<a href="http://carryree.com/2018/02/08/uploadGithub/" target="_blank" rel="external">打包framework上传到github</a></p>
<h2 id="二-安装cocoapods的打包插件"><a href="#二-安装cocoapods的打包插件" class="headerlink" title="二.安装cocoapods的打包插件"></a>二.安装cocoapods的打包插件</h2><p>1.安装</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">sudo gem install cocoapods-packager</div></pre></td></tr></table></figure>
<p>2.注册</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">pod trunk register xxxx@xx.com xxxx --verbose</div></pre></td></tr></table></figure>
<p>xxxx@xx.com 为注册邮箱<br>xxxx 为用户名</p>
<p>注册后收到一封邮件,复制邮件打开链接完成注册<br><img src="/img/2018:02:09_110201.jpg" width="400"></p>
<p>3.查看注册信息</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">pod trunk me</div></pre></td></tr></table></figure>
<h2 id="三-上传cocoa-pods"><a href="#三-上传cocoa-pods" class="headerlink" title="三.上传cocoa pods"></a>三.上传cocoa pods</h2><p>1.cd 到你的git本地目录</p>
<p>2.在工程根目录初始化一个Podspec文件 最好与你项目同名</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">pod spec create EMTest</div></pre></td></tr></table></figure>
<p><img src="/img/2018:02:09_110302.jpg" width="500"></p>
<p>3.配置自己的podspec文件(仅供参考)</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div><div class="line">32</div><div class="line">33</div><div class="line">34</div><div class="line">35</div><div class="line">36</div><div class="line">37</div><div class="line">38</div><div class="line">39</div><div class="line">40</div><div class="line">41</div><div class="line">42</div><div class="line">43</div><div class="line">44</div><div class="line">45</div><div class="line">46</div><div class="line">47</div><div class="line">48</div><div class="line">49</div><div class="line">50</div><div class="line">51</div><div class="line">52</div><div class="line">53</div><div class="line">54</div><div class="line">55</div><div class="line">56</div><div class="line">57</div><div class="line">58</div><div class="line">59</div><div class="line">60</div><div class="line">61</div><div class="line">62</div><div class="line">63</div><div class="line">64</div><div class="line">65</div><div class="line">66</div><div class="line">67</div><div class="line">68</div><div class="line">69</div><div class="line">70</div><div class="line">71</div><div class="line">72</div><div class="line">73</div><div class="line">74</div><div class="line">75</div><div class="line">76</div><div class="line">77</div><div class="line">78</div><div class="line">79</div><div class="line">80</div><div class="line">81</div><div class="line">82</div><div class="line">83</div><div class="line">84</div><div class="line">85</div><div class="line">86</div><div class="line">87</div><div class="line">88</div><div class="line">89</div><div class="line">90</div><div class="line">91</div><div class="line">92</div><div class="line">93</div><div class="line">94</div><div class="line">95</div><div class="line">96</div><div class="line">97</div><div class="line">98</div><div class="line">99</div><div class="line">100</div><div class="line">101</div><div class="line">102</div><div class="line">103</div><div class="line">104</div><div class="line">105</div><div class="line">106</div><div class="line">107</div><div class="line">108</div><div class="line">109</div><div class="line">110</div><div class="line">111</div><div class="line">112</div><div class="line">113</div><div class="line">114</div><div class="line">115</div><div class="line">116</div><div class="line">117</div><div class="line">118</div><div class="line">119</div><div class="line">120</div><div class="line">121</div><div class="line">122</div><div class="line">123</div><div class="line">124</div><div class="line">125</div><div class="line">126</div><div class="line">127</div><div class="line">128</div><div class="line">129</div><div class="line">130</div><div class="line">131</div><div class="line">132</div><div class="line">133</div><div class="line">134</div><div class="line">135</div><div class="line">136</div></pre></td><td class="code"><pre><div class="line">#</div><div class="line"># Be sure to run `pod spec lint EMTest.podspec' to ensure this is a</div><div class="line"># valid spec and to remove all comments including this before submitting the spec.</div><div class="line">#</div><div class="line"># To learn more about Podspec attributes see http://docs.cocoapods.org/specification.html</div><div class="line"># To see working Podspecs in the CocoaPods repo see https://github.com/CocoaPods/Specs/</div><div class="line">#</div><div class="line"></div><div class="line">Pod::Spec.new do |s|</div><div class="line"></div><div class="line"> # ――― Spec Metadata ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #</div><div class="line"> #</div><div class="line"> # These will help people to find your library, and whilst it</div><div class="line"> # can feel like a chore to fill in it's definitely to your advantage. The</div><div class="line"> # summary should be tweet-length, and the description more in depth.</div><div class="line"> #</div><div class="line"></div><div class="line"> s.name = "EMTest"</div><div class="line"> s.version = "1.0.0"</div><div class="line"> s.summary = "This is just test."</div><div class="line"></div><div class="line"> # This description is used to generate tags and improve search results.</div><div class="line"> # * Think: What does it do? Why did you write it? What is the focus?</div><div class="line"> # * Try to keep it short, snappy and to the point.</div><div class="line"> # * Write the description between the DESC delimiters below.</div><div class="line"> # * Finally, don't worry about the indent, CocoaPods strips it!</div><div class="line"> s.description = 'test for github, CarryRee'</div><div class="line"></div><div class="line"> s.homepage = "http://www.emeet.ai"</div><div class="line"> # s.screenshots = "www.example.com/screenshots_1.gif", "www.example.com/screenshots_2.gif"</div><div class="line"></div><div class="line"></div><div class="line"> # ――― Spec License ――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #</div><div class="line"> #</div><div class="line"> # Licensing your code is important. See http://choosealicense.com for more info.</div><div class="line"> # CocoaPods will detect a license file if there is a named LICENSE*</div><div class="line"> # Popular ones are 'MIT', 'BSD' and 'Apache License, Version 2.0'.</div><div class="line"> #</div><div class="line"></div><div class="line"> s.license = { :type => "MIT", :file => "LICENSE" }</div><div class="line"></div><div class="line"></div><div class="line"> # ――― Author Metadata ――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #</div><div class="line"> #</div><div class="line"> # Specify the authors of the library, with email addresses. Email addresses</div><div class="line"> # of the authors are extracted from the SCM log. E.g. $ git log. CocoaPods also</div><div class="line"> # accepts just a name if you'd rather not provide an email address.</div><div class="line"> #</div><div class="line"> # Specify a social_media_url where others can refer to, for example a twitter</div><div class="line"> # profile URL.</div><div class="line"> #</div><div class="line"></div><div class="line"> s.author = { "CarryRee" => "63755364@qq.com" }</div><div class="line"> # Or just: s.author = "CarryRee"</div><div class="line"> # s.authors = { "CarryRee" => "63755364@qq.com" }</div><div class="line"> # s.social_media_url = "http://twitter.com/CarryRee"</div><div class="line"></div><div class="line"> # ――― Platform Specifics ――――――――――――――――――――――――――――――――――――――――――――――――――――――― #</div><div class="line"> #</div><div class="line"> # If this Pod runs only on iOS or OS X, then specify the platform and</div><div class="line"> # the deployment target. You can optionally include the target after the platform.</div><div class="line"> #</div><div class="line"></div><div class="line"> s.platform = :ios</div><div class="line"> s.platform = :ios, "9.0"</div><div class="line"></div><div class="line"> # When using multiple platforms</div><div class="line"> # s.ios.deployment_target = "5.0"</div><div class="line"> # s.osx.deployment_target = "10.7"</div><div class="line"> # s.watchos.deployment_target = "2.0"</div><div class="line"> # s.tvos.deployment_target = "9.0"</div><div class="line"></div><div class="line"></div><div class="line"> # ――― Source Location ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #</div><div class="line"> #</div><div class="line"> # Specify the location from where the source should be retrieved.</div><div class="line"> # Supports git, hg, bzr, svn and HTTP.</div><div class="line"> #</div><div class="line"></div><div class="line"> s.source = { :git => "https://github.com/CarryRee/EMTest.git", :tag => s.version.to_s }</div><div class="line"></div><div class="line"></div><div class="line"> # ――― Source Code ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #</div><div class="line"> #</div><div class="line"> # CocoaPods is smart about how it includes source code. For source files</div><div class="line"> # giving a folder will include any swift, h, m, mm, c & cpp files.</div><div class="line"> # For header files it will include any header in the folder.</div><div class="line"> # Not including the public_header_files will make all headers public.</div><div class="line"> #</div><div class="line"></div><div class="line"> #s.source_files = "Classes", "Classes/**/*.{h,m}"</div><div class="line"> #s.exclude_files = "Classes/Exclude"</div><div class="line"> s.vendored_frameworks = 'EMTest.framework'</div><div class="line"></div><div class="line"> # s.public_header_files = "Classes/**/*.h"</div><div class="line"></div><div class="line"></div><div class="line"> # ――― Resources ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #</div><div class="line"> #</div><div class="line"> # A list of resources included with the Pod. These are copied into the</div><div class="line"> # target bundle with a build phase script. Anything else will be cleaned.</div><div class="line"> # You can preserve files from being cleaned, please don't preserve</div><div class="line"> # non-essential files like tests, examples and documentation.</div><div class="line"> #</div><div class="line"></div><div class="line"> # s.resource = "icon.png"</div><div class="line"> # s.resources = "Resources/*.png"</div><div class="line"></div><div class="line"> # s.preserve_paths = "FilesToSave", "MoreFilesToSave"</div><div class="line"></div><div class="line"></div><div class="line"> # ――― Project Linking ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #</div><div class="line"> #</div><div class="line"> # Link your library with frameworks, or libraries. Libraries do not include</div><div class="line"> # the lib prefix of their name.</div><div class="line"> #</div><div class="line"></div><div class="line"> # s.framework = "SomeFramework"</div><div class="line"> # s.frameworks = "SomeFramework", "AnotherFramework"</div><div class="line"></div><div class="line"> # s.library = "iconv"</div><div class="line"> # s.libraries = "iconv", "xml2"</div><div class="line"></div><div class="line"></div><div class="line"> # ――― Project Settings ――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #</div><div class="line"> #</div><div class="line"> # If your library depends on compiler flags you can set them in the xcconfig hash</div><div class="line"> # where they will only apply to your library. If you depend on other Podspecs</div><div class="line"> # you can include multiple dependencies to ensure it works.</div><div class="line"></div><div class="line"> s.requires_arc = true</div><div class="line"></div><div class="line"> # s.xcconfig = { "HEADER_SEARCH_PATHS" => "$(SDKROOT)/usr/include/libxml2" }</div><div class="line"> # s.dependency "JSONKit", "~> 1.4"</div><div class="line"></div><div class="line">end</div></pre></td></tr></table></figure>
<p>3.验证</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">pod lib lint</div></pre></td></tr></table></figure>
<p><img src="/img/2018:02:09_112103.jpg" width="300"></p>
<p>4.提交cocoa pods (这个有点耐心, 需要会时间)</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">pod trunk push EMTest.podspec</div></pre></td></tr></table></figure>
<p><img src="/img/2018:02:09_113004.jpg" width="500"></p>
<p>注意记得把.podspec也上传到Github中</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div></pre></td><td class="code"><pre><div class="line">git add EMTest.podspec</div><div class="line">git commit -m "pod"</div><div class="line">git push -u origin master</div></pre></td></tr></table></figure>
<p>5.成功后搜索</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">pod search EMTest</div></pre></td></tr></table></figure>
<p>6.如果搜索不出来 更新下cocoapods</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">pod setup</div></pre></td></tr></table></figure>
<p>7.如果还是没有,一直显示</p>
<blockquote>
<p>[!] Unable to find a pod with name, author, summary, or description matching <code>EMTest</code></p>
</blockquote>
<p>执行</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">rm ~/Library/Caches/CocoaPods/search_index.json</div></pre></td></tr></table></figure>
<p>在执行pod search就会重新搜索<br><img src="/img/2018:02:09_141205.jpg" width="500"></p>
]]></content>
<summary type="html">
<![CDATA[<h2 id="一-上传framework到Github"><a href="#一-上传framework到Github" class="headerlink" title="一.上传framework到Github"></a>一.上传framework到Github</h2><]]>
</summary>
</entry>
<entry>
<title><![CDATA[打包framework上传到github]]></title>
<link href="http://yoursite.com/2018/02/08/uploadGithub/"/>
<id>http://yoursite.com/2018/02/08/uploadGithub/</id>
<published>2018-02-08T11:10:57.000Z</published>
<updated>2018-02-09T02:28:37.676Z</updated>
<content type="html"><![CDATA[<h2 id="一-github创建项目"><a href="#一-github创建项目" class="headerlink" title="一.github创建项目"></a>一.github创建项目</h2><p>1.登陆github</p>
<p>2.创建仓库<br><img src="/img/2018:02:08_145301.jpg" alt="outputScreen"></p>
<h2 id="二-制作SSH-KEY"><a href="#二-制作SSH-KEY" class="headerlink" title="二.制作SSH-KEY"></a>二.制作SSH-KEY</h2><p>1.生成SSH-Key<br>打开终端查看是否已经存在SSH密钥:<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">cd ~/.ssh</div></pre></td></tr></table></figure></p>
<p>如果没有密钥则不会有此文件夹,有则备份删除, 也可以直接删除;</p>
<p>2.生成新的秘钥, 命令如下</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">ssh-keygen -t rsa -C "1441699953@qq.com"</div></pre></td></tr></table></figure>
<p>你需要把邮件地址换成你自己的邮件地址,然后一路回车,使用默认值即可,因为这个Key仅仅用于简单的服务,所以也无需设置密码。</p>
<p>3.自定义生成key的名字(直接回车)<br><img src="/img/2018:02:08_134804.jpg" alt="outputScreen"></p>
<p>4.设置密码(直接回车)<br><img src="/img/2018:02:08_135005.jpg" alt="outputScreen"></p>
<p>5.成功生成SSH-Key<br><img src="/img/2018:02:08_135106.jpg" alt="outputScreen"></p>
<p>6.在~/.ssh/目录下会生成id_rsa和id_rsa.pub私钥和公钥。我们将id_rsa_emeet.pub中的内容粘帖到服务器的SSH-key的配置中。<br>可以用查看命令</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">cat id_rsa.pub</div></pre></td></tr></table></figure>
<p>用复制命令</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">pbcopy < ~.ssh/id_rsa.pub</div></pre></td></tr></table></figure>
<p><img src="/img/2018:02:08_193010.jpg" alt="outputScreen"></p>
<p>7.在GitHub的设置中粘贴公钥,Setting -> SSH and GPG keys -> New SSH key<br><img src="/img/2018:02:08_164208.jpg" alt="outputScreen"></p>
<p>8.测试<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">ssh -T git@github.com</div></pre></td></tr></table></figure></p>
<p>成功的话会有You’ve successfully authenticated的语句提示</p>
<h2 id="三-上传framework"><a href="#三-上传framework" class="headerlink" title="三.上传framework"></a>三.上传framework</h2><p>1.拷贝仓库到git链接,因为配置了SSH,选择复制SSH链接<br><img src="/img/2018:02:08_131102.jpg" width="300"></p>
<p>2.git clone 下载项目</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">git clone git@github.com:EMTest2018/EMTest.git</div></pre></td></tr></table></figure>
<p>3.在克隆下来的文件项目放入framework,<a href="http://carryree.com/2018/01/20/framework/#more" target="_blank" rel="external">上一篇制作好的framework</a>.<br><img src="/img/2018:02:08_131703.jpg" width="500"></p>
<p>4.打开终端,cd到克隆下来的文件夹下面</p>
<p>5.添加framework</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">git add EMTest.framework</div></pre></td></tr></table></figure>
<p>6.添加日志</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">git commit -m "framework"</div></pre></td></tr></table></figure>
<p>7.上传</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">git push -u origin master</div></pre></td></tr></table></figure>
<p><img src="/img/2018:02:08_190309.jpg" width="400"></p>
<p>8.给稳定的代码打上版本tag,一般以版本号作为tag名字</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">git tag 1.0.0</div></pre></td></tr></table></figure>
<p>9.将tag推送到git服务器</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">git push --tags</div></pre></td></tr></table></figure>]]></content>
<summary type="html">
<![CDATA[<h2 id="一-github创建项目"><a href="#一-github创建项目" class="headerlink" title="一.github创建项目"></a>一.github创建项目</h2><p>1.登陆github</p>
<p>2.创建仓库<br><i]]>
</summary>
</entry>
<entry>
<title><![CDATA[iOS Framework 静态库制作]]></title>
<link href="http://yoursite.com/2018/01/20/framework/"/>
<id>http://yoursite.com/2018/01/20/framework/</id>
<published>2018-01-20T08:08:57.000Z</published>
<updated>2018-01-20T08:48:28.022Z</updated>
<content type="html"><![CDATA[<h2 id="工程创建"><a href="#工程创建" class="headerlink" title="工程创建"></a>工程创建</h2><p>1.打开Xcode -> Create a new Xcode project,然后选择如图的Cocoa Touch Framework, 选择语言、填好包名,组织名<br><img src="/img/2018:01:19_164701.jpg" alt="outputScreen"></p>
<p>2.工程的Targets下的配置General -> Deployment Info下的Deplayment Target 设置使用的最低版本,我们就设置成9.0便于说明</p>
<p>3.工程的Targets下的配置Build Settings -> Linking下的Mach-O type 设置为Static Library<br><img src="/img/2018:01:20_101602.png" alt="outputScreen"></p>
<h2 id="代码示例"><a href="#代码示例" class="headerlink" title="代码示例"></a>代码示例</h2><p>1.新建三个类test1、test2、test3<br>代码基本如下:</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div></pre></td><td class="code"><pre><div class="line">@interface Test1 : NSObject</div><div class="line"></div><div class="line">- (void)print;</div><div class="line"></div><div class="line">@end</div></pre></td></tr></table></figure>
<p>test2、test3同理</p>
<p>2.然后设置test1.h和test1.m完全对外公开、Test2.h公开,test2.m隐蔽、test3.h和test3.m不对外公开</p>
<p>3.工程的Targets下的配置Build Phases -> Headers下的文件根据上面所示,如下设置,<br>注意:新建一个类的时候,默认Project会默认对应该类的头文件,如果需要完全公开,.m也要对外的话,点击下面的“+”,添加.m,然后将其拖到Public之中,要对外的都放入Public,不对外的放入Project;<br><img src="/img/2018:01:20_153303.png" alt="outputScreen"></p>
<h2 id="生成真机和模拟器合并framework"><a href="#生成真机和模拟器合并framework" class="headerlink" title="生成真机和模拟器合并framework"></a>生成真机和模拟器合并framework</h2><p>问题:framework如果选择真机运行Products会生成真机framework,只能在真机运行,不能再模拟器运行,同理如果选择模拟器运行Products会生成模拟器framework,只能在模拟器运行,不能在真机运行;</p>
<p>为了解决以上问题,我们可以通过脚本生成生成真机和模拟器合并framework</p>
<p>1.Xcode -> File -> Target -> Cross-platform 下面的 other 点击 Aggregate 然后输入了脚本名EMAggregate<br><img src="/img/2018:01:20_154804.png" alt="outputScreen"></p>
<p>2.工程的Targets下EMAggregate 的 Build Phases 点击左上角“+”,选择New Run Script Phase;<br><img src="/img/2018:01:20_155205.png" alt="outputScreen"></p>
<p>3.添加如下代码:</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div><div class="line">32</div><div class="line">33</div><div class="line">34</div><div class="line">35</div><div class="line">36</div><div class="line">37</div><div class="line">38</div><div class="line">39</div><div class="line">40</div><div class="line">41</div><div class="line">42</div><div class="line">43</div><div class="line">44</div><div class="line">45</div><div class="line">46</div><div class="line">47</div><div class="line">48</div><div class="line">49</div><div class="line">50</div><div class="line">51</div></pre></td><td class="code"><pre><div class="line"># Sets the target folders and the final framework product.</div><div class="line"></div><div class="line"># 如果工程名称和Framework的Target名称不一样的话,要自定义FMKNAME</div><div class="line"></div><div class="line"># 例如: FMK_NAME = "MyFramework"</div><div class="line"></div><div class="line">FMK_NAME=${PROJECT_NAME}</div><div class="line"></div><div class="line"># Install dir will be the final output to the framework.</div><div class="line"></div><div class="line"># The following line create it in the root folder of the current project.</div><div class="line"></div><div class="line">INSTALL_DIR=${SRCROOT}/Products/${FMK_NAME}.framework</div><div class="line"></div><div class="line"># Working dir will be deleted after the framework creation.</div><div class="line"></div><div class="line">WRK_DIR=build</div><div class="line"></div><div class="line">DEVICE_DIR=${WRK_DIR}/Release-iphoneos/${FMK_NAME}.framework</div><div class="line"></div><div class="line">SIMULATOR_DIR=${WRK_DIR}/Release-iphonesimulator/${FMK_NAME}.framework</div><div class="line"></div><div class="line"># -configuration ${CONFIGURATION}</div><div class="line"></div><div class="line"># Clean and Building both architectures.</div><div class="line"></div><div class="line">xcodebuild -configuration "Release" -target "${FMK_NAME}" -sdk iphoneos clean build</div><div class="line"></div><div class="line">xcodebuild -configuration "Release" -target "${FMK_NAME}" -sdk iphonesimulator clean build</div><div class="line"></div><div class="line"># Cleaning the oldest.</div><div class="line"></div><div class="line">if [ -d "${INSTALL_DIR}" ]</div><div class="line"></div><div class="line">then</div><div class="line"></div><div class="line">rm -rf "${INSTALL_DIR}"</div><div class="line"></div><div class="line">fi</div><div class="line"></div><div class="line">mkdir -p "${INSTALL_DIR}"</div><div class="line"></div><div class="line">cp -R "${DEVICE_DIR}/" "${INSTALL_DIR}/"</div><div class="line"></div><div class="line"># Uses the Lipo Tool to merge both binary files (i386 + armv6/armv7) into one Universal final product.</div><div class="line"></div><div class="line">lipo -create "${DEVICE_DIR}/${FMK_NAME}" "${SIMULATOR_DIR}/${FMK_NAME}" -output "${INSTALL_DIR}/${FMK_NAME}"</div><div class="line"></div><div class="line">rm -r "${WRK_DIR}"</div><div class="line"></div><div class="line">open "${INSTALL_DIR}"</div></pre></td></tr></table></figure>
<p>4.运行EMAggregate,然后就会在该工程旁边生成目录Products,里面就是合并的<br><img src="/img/2018:01:20_160506.png" alt="outputScreen"></p>
]]></content>
<summary type="html">
<![CDATA[<h2 id="工程创建"><a href="#工程创建" class="headerlink" title="工程创建"></a>工程创建</h2><p>1.打开Xcode -> Create a new Xcode project,然后选择如图的Cocoa Touch ]]>
</summary>
<category term="静态库" scheme="http://yoursite.com/tags/%E9%9D%99%E6%80%81%E5%BA%93/"/>
</entry>
<entry>
<title><![CDATA[工程的动态库同时支持真机和模拟器]]></title>
<link href="http://yoursite.com/2017/11/22/platform/"/>
<id>http://yoursite.com/2017/11/22/platform/</id>
<published>2017-11-22T02:31:25.000Z</published>
<updated>2018-01-20T08:47:00.460Z</updated>
<content type="html"><![CDATA[<h2 id="问题"><a href="#问题" class="headerlink" title="问题"></a>问题</h2><p>最近在工程使用到了第三方提供的SDK,有的第三方提供的是framework的是动态库,只提供真机和模拟器,如果的想同时支持真机和模拟,一想到就是合并,输出一个通用framework</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">lipo -create 【模拟器打包path】 【真机打包path】 -output 【导出兼容版本path】</div></pre></td></tr></table></figure>
<p>可惜一般得出结果是<br><img src="/img/2017:11:22_094601.jpeg" alt="outputScreen"><br><strong>分析</strong>:这个命令是静态库使用,动态库并不适用</p>
<h2 id="测试Framework"><a href="#测试Framework" class="headerlink" title="测试Framework"></a>测试Framework</h2><p>使用XCode新建一个动态库<br><img src="/img/2017:11:22_094701.jpeg" alt="newFrameWork"></p>
<p>在 Build Settings 的 Linking 下设置 Mach-O type 为 Dynamic Library<br><img src="/img/2017:11:22_094801.jpeg" alt="settingFrame"></p>
<p>代码也简单加一方法,给外部调用</p>
<p><strong>Test.h</strong></p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div></pre></td><td class="code"><pre><div class="line">@interface Test : NSObject</div><div class="line">- (void)helloWorld;</div><div class="line">@end</div></pre></td></tr></table></figure>
<p><strong>Test.m</strong></p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div></pre></td><td class="code"><pre><div class="line">- (void)helloWorld {</div><div class="line">NSLog(@"%@", @"Hello, world!");</div><div class="line">}</div></pre></td></tr></table></figure>
<p>通过xcode编译出真机和模拟器的framework<br>这里我把真机的framework文件夹名字命名为iphoneos、模拟器的framework文件夹名字命名为iphonesimulator,注意:这一步很重要;</p>
<h2 id="测试工程"><a href="#测试工程" class="headerlink" title="测试工程"></a>测试工程</h2><p>随便新建一个工程,把两个framework拖入工程,然后删除<strong>LinkFrame works and Librarues</strong>, 然后<strong>Embedded Binaries</strong>再添加两个动态库<br><img src="/img/2017:11:22_094901.jpeg" width="300"></p>
<p>设置如下图设置<br><img src="/img/2017:11:22_095202.jpeg" alt="settingProject2"></p>
<p>最后导入库<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">#import <TestFrame/Test.h></div></pre></td></tr></table></figure></p>
<p>调用方法</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div></pre></td><td class="code"><pre><div class="line">Test *test = [[Test alloc] init];</div><div class="line">[test helloWorld];</div></pre></td></tr></table></figure>
<p>编译看看,是不是编译不过,没错,两个库冲突了</p>
<h2 id="冲突处理"><a href="#冲突处理" class="headerlink" title="冲突处理"></a>冲突处理</h2><p>1.删掉其中一个(>-<),废话中的废话</p>
<p>2.共存处理(下面重点介绍)</p>
<h2 id="共存处理"><a href="#共存处理" class="headerlink" title="共存处理"></a>共存处理</h2><p>1.在两个framework的文件夹下建立一个新文件夹,命名为$PLATFORM_NAME,随便将一个framework复制进去<br><img src="/img/2017:11:22_101345.jpeg" alt="settingProject7"></p>
<p>2.将两个framework从工程中删除(逻辑删除),随便讲其中一个拖入工程,注意是拖framework,不是文件夹</p>
<p>3.点击拖入的framework,如图所示,配置路径<br><img src="/img/2017:11:22_095701.jpeg" alt="settingProject3"></p>
<p>4.然后配置<strong>Build Settings</strong>下的Framework Search Paths设置为$PLATFORM_NAME文件夹的路径(路径为红色不要紧)<br><img src="/img/2017:11:22_095801.jpeg" alt="settingProject4"></p>
<p>5.更改选择为$PLATFORM_NAME文件夹下的framework,然后找到改文件夹去改删去该文件夹(你没有看错),是物理删除该文件夹<br><img src="/img/2017:11:22_101645.jpeg" alt="settingProject8"></p>
<p>6.<strong>Embedded Binaries</strong>再添加回$PLATFORM_NAME的framework(路径为浅色不要紧)<br><img src="/img/2017:11:22_095845.jpeg" width="300"></p>
<p>7.基本到这里就可以<br><img src="/img/2017:11:22_095901.jpeg" alt="settingProject6"></p>
]]></content>
<summary type="html">
<![CDATA[<h2 id="问题"><a href="#问题" class="headerlink" title="问题"></a>问题</h2><p>最近在工程使用到了第三方提供的SDK,有的第三方提供的是framework的是动态库,只提供真机和模拟器,如果的想同时支持真机和模拟,一想到]]>
</summary>
<category term="Framework" scheme="http://yoursite.com/tags/Framework/"/>
</entry>
<entry>
<title><![CDATA[hexo备份导出]]></title>
<link href="http://yoursite.com/2017/11/09/hexoBackup/"/>
<id>http://yoursite.com/2017/11/09/hexoBackup/</id>
<published>2017-11-09T07:25:01.000Z</published>
<updated>2017-11-09T07:51:32.125Z</updated>
<content type="html"><![CDATA[<h1 id="hexo-备忘录"><a href="#hexo-备忘录" class="headerlink" title="hexo 备忘录"></a>hexo 备忘录</h1><h3 id="备份存储"><a href="#备份存储" class="headerlink" title="备份存储"></a>备份存储</h3><p>在GitHub上的<a href="https://github.com/CarryRee/CarryRee.github.io" target="_blank" rel="external">CarryRee.github.io</a>.仓库就有两个分支,一个hexo分支用来存放网站的原始文件,一个master分支用来存放生成的静态网页。</p>
<p><img src="/img/2017:11:9_152054.jpg" alt="img"></p>
<h3 id="备份导出"><a href="#备份导出" class="headerlink" title="备份导出"></a>备份导出</h3><ol>
<li>从GitHub上的<a href="https://github.com/CarryRee/CarryRee.github.io" target="_blank" rel="external">CarryRee.github.io</a> clone分支hexo</li>
<li>使用终端cd 进入clone的文件夹</li>
<li>本地新拷贝的<a href="https://github.com/CarryRee/CarryRee.github.io" target="_blank" rel="external">CarryRee.github.io</a>.文件夹下通过Git bash依次执行下列指令:npm install hexo、npm install、npm install hexo-deployer-git(记得,不需要hexo init这条指令)。</li>
</ol>
<h3 id="注意"><a href="#注意" class="headerlink" title="注意"></a>注意</h3><ol>
<li><p>问题一:执行“hexo server”出现以下错误</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">npm install hexo --no-optional</div></pre></td></tr></table></figure>
</li>
<li><p>安装Hexo时,执行“npm install -g hexo-cli“出现错误</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">sudo npm install --unsafe-perm --verbose -g hexo</div></pre></td></tr></table></figure>
</li>
</ol>
]]></content>
<summary type="html">
<![CDATA[<h1 id="hexo-备忘录"><a href="#hexo-备忘录" class="headerlink" title="hexo 备忘录"></a>hexo 备忘录</h1><h3 id="备份存储"><a href="#备份存储" class="headerlink" ]]>
</summary>
</entry>
<entry>
<title><![CDATA[浅谈block的循环引用]]></title>
<link href="http://yoursite.com/2017/07/28/memory/"/>
<id>http://yoursite.com/2017/07/28/memory/</id>
<published>2017-07-28T09:18:02.000Z</published>
<updated>2017-07-31T06:10:30.000Z</updated>
<content type="html"><![CDATA[<h1 id="浅谈block的循环引用"><a href="#浅谈block的循环引用" class="headerlink" title="浅谈block的循环引用"></a>浅谈block的循环引用</h1><h5 id="1-前言:最近在项目上经常遇到控制器pop出来却不执行dealloc的,很多时候都是block循环引用导致,所以特意对block进行一番研究,以防自己犯引用错误;"><a href="#1-前言:最近在项目上经常遇到控制器pop出来却不执行dealloc的,很多时候都是block循环引用导致,所以特意对block进行一番研究,以防自己犯引用错误;" class="headerlink" title="1.前言:最近在项目上经常遇到控制器pop出来却不执行dealloc的,很多时候都是block循环引用导致,所以特意对block进行一番研究,以防自己犯引用错误;"></a>1.前言:最近在项目上经常遇到控制器pop出来却不执行dealloc的,很多时候都是block循环引用导致,所以特意对block进行一番研究,以防自己犯引用错误;</h5><h5 id="2-在ARC环境下,比较常见的发生循环引用就是self-gt-block-gt-self-从而形成环,导致不被释放,或者其他类持有block-gt-self,但这个没有释放,或没有主动释放block;"><a href="#2-在ARC环境下,比较常见的发生循环引用就是self-gt-block-gt-self-从而形成环,导致不被释放,或者其他类持有block-gt-self,但这个没有释放,或没有主动释放block;" class="headerlink" title="2.在ARC环境下,比较常见的发生循环引用就是self -> block -> self 从而形成环,导致不被释放,或者其他类持有block -> self,但这个没有释放,或没有主动释放block;"></a>2.在ARC环境下,比较常见的发生循环引用就是self -> block -> self 从而形成环,导致不被释放,或者其他类持有block -> self,但这个没有释放,或没有主动释放block;</h5><h5 id="3-案例分析:"><a href="#3-案例分析:" class="headerlink" title="3.案例分析:"></a>3.案例分析:</h5><p>控制器:</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div></pre></td><td class="code"><pre><div class="line">@interface BlockViewController ()</div><div class="line"></div><div class="line">@property (nonatomic, strong) PropertyTest *propertyTest;</div><div class="line">@property (nonatomic, strong) NSString *name;</div><div class="line">@property (nonatomic, copy) void(^myBlock)();</div><div class="line">@property (nonatomic, strong) NSMutableArray *dataArray;</div><div class="line"></div><div class="line">@end</div></pre></td></tr></table></figure>
<p>控制器属性:</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div></pre></td><td class="code"><pre><div class="line">@interface propertyTest : NSObject</div><div class="line">@property (nonatomic, copy) void(^propertyBlock)();</div><div class="line">@end</div></pre></td></tr></table></figure>
<p>单例:</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div></pre></td><td class="code"><pre><div class="line">typedef void(^TestBlock)(void);</div><div class="line"></div><div class="line">@interface Singleton : NSObject</div><div class="line"></div><div class="line">@property (nonatomic, copy) TestBlock testBlock;</div><div class="line"></div><div class="line">+ (instancetype) sharedSingleton;</div><div class="line">- (void) test;</div></pre></td></tr></table></figure>
<hr>
<p><strong>1)GCD里面的block</strong></p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div></pre></td><td class="code"><pre><div class="line">dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{</div><div class="line">self.name = @"test";</div><div class="line">});</div></pre></td></tr></table></figure>
<p>结果:执行了dealloc <br><br>分析:GCD是一次性派发的任务,当执行完block,会释放block,GCD本身也释放</p>
<p><strong>2) 属性的block</strong></p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div></pre></td><td class="code"><pre><div class="line">self.propertyTest = [[PropertyTest alloc] init];</div><div class="line"></div><div class="line">self.propertyTest.block = ^{</div><div class="line">self.name = @"test";</div><div class="line">};</div></pre></td></tr></table></figure>
<p>结果:不执行了dealloc <br><br>分析:self->self.propertyTest->block->self.name(self),此情况就是最典型的循环引用了,形成保留环无法释放</p>
<p><strong>3) 属性的block, 增加__weak声明</strong></p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div></pre></td><td class="code"><pre><div class="line">self.propertyTest = [[PropertyTest alloc] init];</div><div class="line"></div><div class="line">__weak typeof (self) wealSelf = self;</div><div class="line">self.propertyTest.block = ^{</div><div class="line">typeof(wealSelf) strongSelf = wealSelf;</div><div class="line">strongSelf.name = @"test";</div><div class="line">};</div></pre></td></tr></table></figure>
<p>结果:执行了dealloc <br><br>分析:self->self.propertyTest->block->self.name(self),但是weak打破了循环,后面那个strongSelf和原来的self并没有直接关系,因为strongSelf是通过weakSelf得来的,而weakSelf又没有强引用原来的self</p>
<p><strong>4) 成员的block</strong></p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div></pre></td><td class="code"><pre><div class="line">self.propertyTest = [[PropertyTest alloc] init];</div><div class="line"></div><div class="line">self.propertyTest.block = ^{</div><div class="line">_name = @"test";</div><div class="line">};</div></pre></td></tr></table></figure>
<p>结果:不执行了dealloc <br><br>分析:self->self.propertyTest->block->_name(self),跟2)上述同理</p>
<p><strong>5) 成员的block,增加__weak声明,但还是用成员</strong></p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div></pre></td><td class="code"><pre><div class="line">self.propertyTest = [[PropertyTest alloc] init];</div><div class="line"></div><div class="line">__weak typeof (self) weakSelf = self;</div><div class="line">self.propertyTest.block = ^{</div><div class="line">typeof(weakSelf) strongSelf = weakSelf;</div><div class="line">_name = @"test";</div><div class="line">};</div></pre></td></tr></table></figure>
<p>结果:不执行了dealloc <br><br>分析:self->self.propertyTest->block->_name(self),虽然被weak打破,还是用了self的成员name</p>
<p><strong>6) 属性的block,结束后重置为nil</strong></p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div></pre></td><td class="code"><pre><div class="line">self.propertyTest.block = ^{</div><div class="line">self.name = @"test";</div><div class="line">self.propertyTest.block = nil;</div><div class="line">self.propertyTest = nil;</div><div class="line">NSLog(@"%@", self.propertyTest);</div><div class="line">};</div></pre></td></tr></table></figure>
<p>结果:不执行了dealloc <br><br>分析:self->self.propertyTest->block->self.name(self),self.propertyTest = nil,self.propertyTest.block = nil;虽然强制为空,应该是拷贝到堆上的block还没有释放;</p>
<p><strong>7) 临时生成类</strong></p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div></pre></td><td class="code"><pre><div class="line">PropertyTest *propertyTest = [[PropertyTest alloc] init];</div><div class="line"></div><div class="line">propertyTest.block = ^{</div><div class="line">self.name = @"test";</div><div class="line">};</div></pre></td></tr></table></figure>
<p>结果:执行了dealloc <br><br>分析:propertyTest->block->self.name(self),未形成环,注意:在ARC中,在被拷贝的 block 中无论是直接引用self 还是通过引用self的成员变量间接引用self,该block都会retain self。但是block执行完会释放一次,临时生成的类释放也会在释放一次;</p>
<p><strong>8) 单例持有</strong></p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div></pre></td><td class="code"><pre><div class="line">[Singleton sharedSingleton].testBlock = ^{</div><div class="line">self.name = @"test";</div><div class="line">};</div></pre></td></tr></table></figure>
<p>结果:不执行了dealloc <br><br>分析:Singleton 执行完释放一次block, 但是Singleton是单例, 并没有释放;</p>
<p><strong>9) 单例持有,__weak声明</strong></p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div></pre></td><td class="code"><pre><div class="line">__weak typeof (self) weakSelf = self;</div><div class="line">[Singleton sharedSingleton].testBlock = ^{</div><div class="line">typeof(weakSelf) strongSelf = weakSelf;</div><div class="line">strongSelf.name = @"test";</div><div class="line">};</div></pre></td></tr></table></figure>
<p>结果:执行了dealloc <br><br>分析:__weak声明使该block不retain self,Singleton 执行完释放一次block,self也释放了;</p>
<p><strong>10) 单例持有,手动释放</strong></p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div></pre></td><td class="code"><pre><div class="line">[Singleton sharedSingleton].testBlock = ^{</div><div class="line">self.name = @"test";</div><div class="line">};</div><div class="line">[Singleton sharedSingleton].testBlock = nil;</div></pre></td></tr></table></figure>
<p>结果:执行了dealloc <br><br>分析:在ARC中,在被拷贝的 block 中无论是直接引用self 还是通过引用self的成员变量间接引用self,该block都会retain self。但是block执行完会释放一次,然后被手动释放了一次,self也释放了;</p>
<p><strong>11) 数组包含block</strong></p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div></pre></td><td class="code"><pre><div class="line">PropertyTest *propertyTest = [[PropertyTest alloc] init];</div><div class="line"></div><div class="line">propertyTest.block = ^{</div><div class="line">self.name = @"test";</div><div class="line">};</div><div class="line"></div><div class="line">self.dataArray = [NSMutableArray array];</div><div class="line">[self.dataArray addObject:propertyTest];</div></pre></td></tr></table></figure>
<p>结果:不执行了dealloc <br><br>分析:self.dataArray -> propertyTest -> block -> self.name ,这是间接持有</p>
<p><strong>12) 数组包含block, __weak声明</strong></p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div></pre></td><td class="code"><pre><div class="line">PropertyTest *propertyTest = [[PropertyTest alloc] init];</div><div class="line"></div><div class="line">__weak typeof (self) weakSelf = self;</div><div class="line">propertyTest.block = ^{</div><div class="line">typeof(weakSelf) strongSelf = weakSelf;</div><div class="line">strongSelf.name = @"test";</div><div class="line">};</div><div class="line"></div><div class="line">self.dataArray = [NSMutableArray array];</div><div class="line">[self.dataArray addObject:propertyTest];</div></pre></td></tr></table></figure>
<p>结果:执行了dealloc <br><br>分析:self.dataArray -> propertyTest -> block -> self.name ,这是间接持有, 但被 weak 打破循环</p>
]]></content>
<summary type="html">
<![CDATA[<h1 id="浅谈block的循环引用"><a href="#浅谈block的循环引用" class="headerlink" title="浅谈block的循环引用"></a>浅谈block的循环引用</h1><h5 id="1-前言:最近在项目上经常遇到控制器pop出来却不]]>
</summary>
<category term="内存管理 block" scheme="http://yoursite.com/tags/%E5%86%85%E5%AD%98%E7%AE%A1%E7%90%86-block/"/>
</entry>
<entry>
<title><![CDATA[CABasicAnimation 内存不释放问题]]></title>
<link href="http://yoursite.com/2017/07/21/animation/"/>
<id>http://yoursite.com/2017/07/21/animation/</id>
<published>2017-07-21T09:01:53.000Z</published>
<updated>2017-07-24T01:59:25.000Z</updated>
<content type="html"><![CDATA[<h2 id="CABasicAnimation-内存不释放问题"><a href="#CABasicAnimation-内存不释放问题" class="headerlink" title="CABasicAnimation 内存不释放问题"></a>CABasicAnimation 内存不释放问题</h2><p>最近在项目遇到一个问题就是,在页面dismissViewController后发现该页面没有被释放,仔细查阅后,发现页面用了CABasicAnimation的removedOnCompletion = NO会导致不被释放,应该在dismissViewController之前调用removeAnimationForKey</p>
<hr>
<p><strong>原因</strong>:<br>removedOnCompletion 默认为YES,代表动画执行完毕后就从图层上移除,图形会恢复到动画执行前的状态。如果想让图层保持显示动画执行后的状态,那就设置为NO,也就是说图层一直在从而导致图层未释放。</p>
<p><strong>解决</strong>:<br>在界面结束之前先手动调用removeAnimationForKey</p>
]]></content>
<summary type="html">
<![CDATA[<h2 id="CABasicAnimation-内存不释放问题"><a href="#CABasicAnimation-内存不释放问题" class="headerlink" title="CABasicAnimation 内存不释放问题"></a>CABasicAnimati]]>
</summary>
<category term="动画 内存管理" scheme="http://yoursite.com/tags/%E5%8A%A8%E7%94%BB-%E5%86%85%E5%AD%98%E7%AE%A1%E7%90%86/"/>
</entry>
<entry>
<title><![CDATA[CarryRee-s-blog]]></title>
<link href="http://yoursite.com/2017/07/03/CarryRee-s-blog/"/>
<id>http://yoursite.com/2017/07/03/CarryRee-s-blog/</id>
<published>2017-07-03T02:59:37.000Z</published>
<updated>2017-07-21T09:19:45.000Z</updated>
<content type="html"><![CDATA[<h2 id="博客成功搭建纪念一下"><a href="#博客成功搭建纪念一下" class="headerlink" title="博客成功搭建纪念一下"></a>博客成功搭建纪念一下</h2>]]></content>
<summary type="html">
<![CDATA[<h2 id="博客成功搭建纪念一下"><a href="#博客成功搭建纪念一下" class="headerlink" title="博客成功搭建纪念一下"></a>博客成功搭建纪念一下</h2>]]>
</summary>
</entry>
</feed>