文档相关

1、调用相机、相册、图库

  1 #import "ViewController.h"
  2 #import <MobileCoreServices/MobileCoreServices.h>
  3 #import <AVFoundation/AVFoundation.h>
  4 #import <MediaPlayer/MediaPlayer.h>
  5
  6
  7 @interface ViewController ()<UIImagePickerControllerDelegate,UINavigationControllerDelegate>
  8 {
  9     BOOL canmerIsOK;
 10     BOOL photoLibaryIsOk;
 11     BOOL photosAlbumIsOk;
 12     UIImagePickerController *_imagePickerController;
 13 }
 14
 15 @property (weak, nonatomic) IBOutlet UIImageView *imageView;
 16
 17 @end
 18
 19 @implementation ViewController
 20 - (IBAction)showImagePickerView:(id)sender {
 21     //NSLog(@"相册");
 22     _imagePickerController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
 23
 24     [self presentViewController:_imagePickerController animated:YES completion:nil];
 25
 26 }
 27 - (IBAction)useCamera:(id)sender {
 28     _imagePickerController.sourceType = UIImagePickerControllerSourceTypeCamera;
 29     //录制视频时长,默认10s
 30     _imagePickerController.videoMaximumDuration = 15;
 31
 32     //相机类型(拍照、录像...)字符串需要做相应的类型转换
 33     _imagePickerController.mediaTypes = @[(NSString *)kUTTypeMovie,(NSString *)kUTTypeImage];
 34
 35     //视频上传质量
 36     //UIImagePickerControllerQualityTypeHigh高清
 37     //UIImagePickerControllerQualityTypeMedium中等质量
 38     //UIImagePickerControllerQualityTypeLow低质量
 39     //UIImagePickerControllerQualityType640x480
 40     _imagePickerController.videoQuality = UIImagePickerControllerQualityTypeHigh;
 41
 42     //设置摄像头模式(拍照,录制视频)为录像模式
 43     _imagePickerController.cameraCaptureMode = UIImagePickerControllerCameraCaptureModePhoto;
 44     [self presentViewController:_imagePickerController animated:YES completion:nil];
 45
 46
 47 }
 48
 49 - (void)viewDidLoad {
 50     [super viewDidLoad];
 51
 52     _imagePickerController = [[UIImagePickerController alloc] init];
 53     _imagePickerController.delegate = self;
 54     _imagePickerController.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
 55     _imagePickerController.allowsEditing = YES;
 56
 57
 58
 59
 60     // Do any additional setup after loading the view, typically from a nib.
 61 }
 62
 63 #pragma mark UIImagePickerControllerDelegate
 64 //该代理方法仅适用于只选取图片时
 65 - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image editingInfo:(nullable NSDictionary<NSString *,id> *)editingInfo {
 66     NSLog(@"选择完毕----image:%@-----info:%@",image,editingInfo);
 67 }
 68
 69
 70 //适用获取所有媒体资源,只需判断资源类型
 71 - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary<NSString *,id> *)info{
 72     NSString *mediaType=[info objectForKey:UIImagePickerControllerMediaType];
 73     //判断资源类型
 74     if ([mediaType isEqualToString:(NSString *)kUTTypeImage]){
 75         //如果是图片
 76         self.imageView.image = info[UIImagePickerControllerEditedImage];
 77         //压缩图片
 78         NSData *fileData = UIImageJPEGRepresentation(self.imageView.image, 1.0);
 79         //保存图片至相册
 80         UIImageWriteToSavedPhotosAlbum(self.imageView.image, self, @selector(image:didFinishSavingWithError:contextInfo:), NULL);
 81         //上传图片
 82 //        [self uploadImageWithData:fileData];
 83
 84     }else{
 85         //如果是视频
 86         NSURL *url = info[UIImagePickerControllerMediaURL];
 87         //播放视频
 88 //        _moviePlayer.contentURL = url;
 89 //        [_moviePlayer play];
 90         //保存视频至相册(异步线程)
 91         NSString *urlStr = [url path];
 92
 93         dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
 94             if (UIVideoAtPathIsCompatibleWithSavedPhotosAlbum(urlStr)) {
 95
 96                 UISaveVideoAtPathToSavedPhotosAlbum(urlStr, self, @selector(video:didFinishSavingWithError:contextInfo:), nil);
 97             }
 98         });
 99         NSData *videoData = [NSData dataWithContentsOfURL:url];
100         //视频上传
101 //        [self uploadVideoWithData:videoData];
102     }
103     [self dismissViewControllerAnimated:YES completion:nil];
104 }
105
106
107 #pragma mark 图片保存完毕的回调
108 - (void) image: (UIImage *) image didFinishSavingWithError:(NSError *) error contextInfo: (void *)contextInf{
109
110 }
111
112 #pragma mark 视频保存完毕的回调
113 - (void)video:(NSString *)videoPath didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInf{
114     if (error) {
115         NSLog(@"保存视频过程中发生错误,错误信息:%@",error.localizedDescription);
116     }else{
117         NSLog(@"视频保存成功.");
118     }
119 }

2、调用iBook

需求调试条件:(iOS4.0 later)

1 1NSString *fileToOpen = [[NSBundle mainBundle] pathForResource:@"readme" ofType:@"pdf"];
2 NSURL *url = [NSURL fileURLWithPath:fileToOpen];
3  docController = [[UIDocumentInteractionController interactionControllerWithURL:url] retain];
4 BOOL isValid = [docController presentOpenInMenuFromRect:CGRectZero inView:self.view animated:YES];

3、打开word、execl、pdf等文档

 1 方法一:
 2 用UIWebView就可以了
 3 -(void)loadDocument:(NSString*)documentName inView:(UIWebView*)webView
 4 {
 5     NSString *path = [[NSBundle mainBundle] pathForResource:documentName ofType:nil];
 6     NSURL *url = [NSURL fileURLWithPath:path];
 7     NSURLRequest *request = [NSURLRequest requestWithURL:url];
 8     [webView loadRequest:request];
 9 }
10
11 // Calling -loadDocument:inView:
12 [self loadDocument:@"test.doc" inView:self.myWebview];
13
14
15 方法我也已经测试过了,希望对大家有帮助,
16
17
18 方法二:
19 下面方法是直接通过QLPreviewController打开文档
20
21 qlViewController = [[QLPreviewController alloc] init];
22    qlViewController.dataSource = self;
23    [self presentModalViewController:qlViewController animated:YES];
24
25
26 - (NSInteger)numberOfPreviewItemsInPreviewController:(QLPreviewController *)controller {
27 return 1;
28 }
29 - (id <QLPreviewItem>)previewController:(QLPreviewController *)controller
30       previewItemAtIndex:(NSInteger)index{
31 //-------------读文件
32 NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
33 NSString *documentsDirectory = [paths objectAtIndex:0];
34 if (!documentsDirectory) {
35   NSLog(@"Documents directory not found!");//return ;
36 }
37 NSString *fileName=[NSString stringWithFormat:@"%@.%@",nameQ,extQ];
38 NSString *appFile = [documentsDirectory stringByAppendingPathComponent:fileName];
39 //-------------
40 NSURL *myQLDocument = [NSURL fileURLWithPath:appFile];
41 return myQLDocument;
42 }
时间: 2024-08-24 02:57:45

文档相关的相关文章

12.1 文档相关 Webbrowser 该文档已被修改,是否保存修改结果

附件:http://files.cnblogs.com/xe2011/Webbrowser_Document_IsModified.rar 该文档已被修改,是否保存修改结果?是:保存修改结果否:放弃修改结果取消:仍打开该文档 触发这个对话框方法 初始化 private void Form1_Load(object sender, EventArgs e) { webBrowser1.Navigate("about:blank"); webBrowser1.Document.Write(

xml和xsd架构文档相关知识

1.使用架构(XSD)验证XML文件 2.使用自动生成工具: 工具目录:C:\Program Files (x86)\Microsoft SDKs\Windows\v8.0A\bin\NETFX 4.0 Tools 工具名称:xsd.exe 使用帮助:生成xml架构文档xsd-->拷贝xml文件到工具目录下,打开命令工具,进入该目录,执行命令:xsd myFile.xml 生成xsd架构文档相关类-->执行命令:xsd /c/language:CS XSDSchemaFile.xsd 更多详细

C++ PDF文档相关操作

人生总是在赶着一个又一个的期限,直到最后的大限. 近来基本没更新过博客,实在是准备雅思看英语加上调节老看英语后的烦躁心情闹的.本来以为考完研就与大考再也不见了,这种想法实在是 Too young,Too naive.之前做过一个项目,是关于在Windows平台下用C++实现PDF文档制作的相关操作的,今天有点心情拿来总结下. 关于PDF的库其实有不少,本人因为一开始用神器搜到的是PDFlib,就用这个库做了.这就是所谓的缘分吧. PDFlib并非是开源库,要使用需要付费,否则会有一个让人不要不要

web前端【第十二篇】jQuery文档相关操作

一.相关知识点总结1.CSS .css() - .css("color") -> 获取color css值 - .css("color", "#ff0000") -> 设置值 - .css({"color": "#cccccc", "border": "1px solid #ff0000"}) -> 设置多个值 - .css(["color

teradata培训文档 相关索引

teradata培训文档 http://wenku.baidu.com/view/ec44c201cc175527072208ba.html Teradata 和Greenplum 的讨论 http://www.itpub.net/forum.php?mod=viewthread&action=printable&tid=1614147 中国邮政Teradata扩容方案及门户优化 http://wenku.baidu.com/view/4f959d6e7e21af45b307a8dc.ht

10 华电内部文档搜索系统 search05

上一节讲述了索引更新的处理方案,这一节首先讲述索引维护的相关方案.每创建一个索引,把文档相关的信息插入到数据库中.这个时候会产生一个唯一的对应的ID,获取这个ID之后,把这个ID又插入到对应的索引文件中. 就是说lucene索引中具体的每一个Document也是包含了一个ID,那么这个ID和数据库的ID是同一个ID.也就是说我们在数据库插入的时候会得到一个ID,那么这个ID是得到之后我们再插入到对应的索引中,就是lucene的索引中. 我们检索的时候首先检索的是索引,那么这个时候这个checkb

搜索引擎的检索模型-查询与文档的相关度计算

1. 检索模型概述 搜索结果排序时搜索引擎最核心的部分,很大程度度上决定了搜索引擎的质量好坏及用户满意度.实际搜索结果排序的因子有很多,但最主要的两个因素是用户查询和网页内容的相关度,以及网页链接情况.这里我们主要总结网页内容和用户查询相关的内容. 判断网页内容是否与用户査询相关,这依赖于搜索引擎所来用的检索模型.检索模型是搜索引擎的理论基础,为量化相关性提供了一种数学模型,是对查询词和文档之间进行相似度计算的框架和方法.其本质就是相关度建模.如图所示,检索模型所在搜索引擎系统架构位置: 当然检

WebAPI使用多个xml文件生成帮助文档

一.前言 上篇有提到在WebAPI项目内,通过在Nuget里安装(Microsoft.AspNet.WebApi.HelpPage)可以根据注释生成帮助文档,查看代码实现会发现是基于解析项目生成的xml文档来作为数据源从而展示出来的.在我们的项目帮助文档需要的类(特指定义的Request和Response)与项目在同一个项目时是没有问题的,但是我们实际工作中会因为其他项目也需要引用该(Request和Response)时,我们会将其抽出来单独作为一个项目供其它调用来引用,这时,查看帮助文档不会报

Java文档上传问题设计

近期公司让做一个文档上传的功能,功能描写叙述大概是这样子滴 书籍名称.书籍定价.书籍封面图片(须要上传).文档内容 (须要上传) .还有其它相关的描写叙述信息. 我的设计  表 A  包括以上字段 ,最初设计  文档上传.和内容保存在同一个页面. 这样后期遇到了一个问题可能用户仅仅是想 改动一下文档描写叙述的相关信息.可是改动的时候不得不 将整个Form表单编辑过后提交,并且那个上传的 俩文档是不会.在改动里面显示出来的 . 这种设计非常糟糕,后来 将这个东西分为两部分.一部分是文档相关定义的提