iOS开发-开发总结(四)

一:send和awk解释
 
  • sed -n p filenamesed ----------------------------是一个流编辑器(stream editor)
  • awk ‘BEGIN {print “Hellow"}'awk --------是一种用于处理文本的编程语言工具。
 
二:传值方式总结
  • KVO底层会动态长生新的类,只能坚挺属性(一个对象的属性能背多个兑现监听,一个对象能监听多个对象的其他属性)
    • kvc/kvo底层是基于runtime
  • 代理,规范,代码多:一对一
  • 通知,发送和接收:一对多(一个通知能被多个对象接受,一个对象能接受多个通知)
 
 
三:block简单小结
 
bloack时基于指针和函数指针的,指向结构体的指针!外面使用__block之后里面能修改值,是因为block将地址传进去了

默认在栈里面,对block做一次copy操作就能将它放到堆里面并且一致使用它,还有一种方法是Block_copy(blockname)非Arc里面

 

 
四:swift代码更新:转2.0
 
Xcode 7中将代码转换成Swift 2的工具。该工具位于在Xcode的Edit菜单下--Convert > To Latest Swift Syntax。
 
 
 

五:使用GTMBase64编码解码字符串

  • GTMDefines.h GTMBase64.h GTMBase64.m
你可以在这里找到这三个文件(GTMDefines.h在第二页,点击右上角的next按钮即可跳转到第二页)
 

六:编解码函数(可以编解码字符串、图片、视频:filePath换成相应的即可):

从模拟器和真机的Documents路径下读取文件,编码后写入文件;读出来解码

// 加密函数

复制代码
 1 -(void)func_encodeFile
 2 
 3 {
 4 
 5     //NSString *path = [NSHomeDirectory() stringByAppendingFormat:@"/Documents/test.png"];
 6 
 7     NSString *filePath = [NSHomeDirectory() stringByAppendingFormat:@"/Documents/iphone4.mov"];
 8 
 9     
10 
11     //文件路径转换为NSData
12 
13     NSData *imageDataOrigin = [NSData dataWithContentsOfFile:filePath];
14 
15     
16 
17     // 对前1000位进行异或处理
18 
19     unsigned char * cByte = (unsigned char*)[imageDataOrigin bytes];
20 
21     for (int index = 0; (index < [imageDataOrigin length]) && (index < 1000); index++, cByte++)
22 
23     {
24 
25          *cByte = (*cByte) ^ arrayForEncode[index];
26 
27     }
28 
29     //对NSData进行base64编码
30 
31     NSData *imageDataEncode = [GTMBase64 encodeData:imageDataOrigin];
32 
33     [imageDataEncode writeToFile:filePath atomically:YES];
34 
35 }
复制代码

 

// 解密函数

复制代码
 1 -(void)func_decodeFile
 2 
 3 {
 4 
 5     //NSString *filePath = [NSHomeDirectory() stringByAppendingFormat:@"/Documents/test.png"];
 6 
 7     NSString *filePath = [NSHomeDirectory() stringByAppendingFormat:@"/Documents/iphone4.mov"];
 8 
 9     
10 
11     // 读取被加密文件对应的数据
12 
13     NSData *dataEncoded = [NSData dataWithContentsOfFile:filePath];
14 
15     
16 
17     // 对NSData进行base64解码 
18 
19     NSData *dataDecode = [GTMBase64 decodeData:dataEncoded];
20 
21     
22 
23     // 对前1000位进行异或处理
24 
25     unsigned char * cByte = (unsigned char*)[dataDecode bytes];
26 
27     for (int index = 0; (index < [dataDecode length]) && (index < 10); index++, cByte++)
28 
29     {
30 
31         *cByte = (*cByte) ^ arrayForEncode[index];
32 
33     }
34 
35     
36 
37     [dataDecode writeToFile:filePath atomically:YES];
38 }
39  
复制代码
 
七:获取每一帧推按:
复制代码
 1 [mImageGenerator generateCGImagesAsynchronouslyForTimes:[NSArray arrayWithObject:[NSValue valueWithCMTime:CMTimeMakeWithSeconds(time, NSEC_PER_SEC)]] completionHandler:  
 2     ^(CMTime requestedTime, CGImageRef image, CMTime actualTime, AVAssetImageGeneratorResult result, NSError *error)  
 3     {  
 4            NSLog(@"actual got image at time:%f", CMTimeGetSeconds(actualTime));          if (image)  
 5         {  
 6             [CATransaction begin];  
 7             [CATransaction setDisableActions:YES];  
 8             [layer setContents:(id)image];  
 9    
10             //UIImage *img = [UIImage imageWithCGImage:image];  
11             //UIImageWriteToSavedPhotosAlbum(img, self, nil, nil);  
12    
13             [CATransaction commit];  
14         }  
15     }];  
复制代码
 
八:iOS开发之流媒体常识
 
实时流媒体传输必须保证数据包的传输速度大于文件的播放速度,否则用户看到的视频会出现暂停。当网络堵塞情况下视频质量会下降,所以要想保证视频的质量渐进式下载会更好一些。

实时流媒体协议:

  • RTSP(Real Time Streaming Protocol)
  • MMS(Microsoft Media Server protocol)
  • HLS(Http Live Streaming)

这里主要介绍HLS,

 
HLS(HTTP Live Streaming)是苹果公司针对iPhone、iPod、iTouch和iPad等移动设备而开发的基于HTTP协议的流媒体解决方案
 
 
九:M3U8文件概念
M3U8文件是指UTF-8编码格式的M3U文件。M3U文件是记录了一个索引纯文本文件,打开它时播放软件并不是播放它,而是根据它的索引找到对应的音视频文件的网络地址进行在线播放。
 
 
十:swift中autoclosure
 
@autoclosure 把一句表达式自动封装成一个闭包(closure)
 
 
posted @ 2016-07-02 15:40  ekhome  阅读(251)  评论(0编辑  收藏  举报