标签:
默认在栈里面,对block做一次copy操作就能将它放到堆里面并且一致使用它,还有一种方法是Block_copy(blockname)非Arc里面
五:使用GTMBase64编码解码字符串
六:编解码函数(可以编解码字符串、图片、视频: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 }];
实时流媒体协议:
这里主要介绍HLS,
标签:
原文地址:http://www.cnblogs.com/stronger-ios-lcx/p/5635470.html