【iOS_GitHub】文档/文件查看器(支持本地或者其余app分享过来的word、excel、pdf、rtf等格式文件)

DocViewer(文档/文件查看器)

Function Description

  • 文档查看器(Word && Excel && PDF && Rft || Network && Local || self && other App)
  • 文件共享 && 查看 (Network && Local)

how to use

1. 相关参数配置

a. JhtLoadDocViewParamModel:文本加载 View 配置Model
JhtLoadDocView内部相关属性的修改可经过修改此model实现
复制代码
b. JhtDocFileOperations:文件操做类
文件保存 && 清理等方法
复制代码
c. JhtShowDumpingViewParamModel:下滑提示框配置参数model
用于设置提示框中的 文字的大小,颜色,位置,背景图,是否包含警示小图标等参数
复制代码
d. JhtFileModel:下载文档的Model
用于设置文件ID,文件名,绝对路径(本地文件),文件大小等参数
复制代码
  • 文本类 default值 亦可经过修改 JhtDocViewer_Default.plist 相应键值对进行修改

2. DocListViewController:文档列表

tableView的数据源是一个装有model的数组,model根据属性fileAbsolutePath(本地绝对路径),判断是否须要下载
复制代码

3. LoadDocViewController:文档详情VC,内部使用JhtLoadDocView

4. JhtLoadDocView:文本加载 View

a. 若是不须要下载,经过webView直接显示
b. 须要下载,则经过JhtDownloadRequest函数中的类方法进行下载,暂停等操做(注意:JhtFileModel属性:fileSize,应写成这种式“KB,MB,GB,Bytes”,为了计算手机剩余内存,关系是否能下载成功


c. 资源共享

《JhtDocViewer》文件用”其余应用“打开

“其余应用”文件用《JhtDocViewer》打开
  
git

d. 无网络弹框


  • 具体使用详见demo

needed to pay attention

1. 若是咱们在iOS9下直接进行HTTP请求是会收到以下错误提示

App Transport Security has blocked a cleartext HTTP (http://) resource load since it is insecure. Temporary exceptions can be configured via your app's Info.plist file.
复制代码

系统会告诉咱们不能直接使用HTTP进行请求,须要在Info.plist新增一段用于控制ATS的配置github

<key>NSAppTransportSecurity</key>
<dict>
    <key>NSAllowsArbitraryLoads</key>
    <true/>
</dict>
复制代码

即:
web

2. 若是想共享本身app的文档查看功能,需在info.plist 中添加以下信息

<key>CFBundleDocumentTypes</key>
	<array>
		<dict>
			<key>CFBundleTypeIconFiles</key>
			<array>
				<string>MySmallIcon.png</string>
				<string>MyLargeIcon.png</string>
			</array>
			<key>CFBundleTypeName</key>
			<string>My File Format</string>
			<key>LSHandlerRank</key>
			<string>Owner</string>
			<key>LSItemContentTypes</key>
			<array>
				<string>com.microsoft.powerpoint.ppt</string>
				<string>public.item</string>
				<string>com.microsoft.word.doc</string>
				<string>com.adobe.pdf</string>
				<string>com.microsoft.excel.xls</string>
				<string>public.image</string>
				<string>public.content</string>
				<string>public.composite-content</string>
				<string>public.archive</string>
				<string>public.audio</string>
				<string>public.movie</string>
				<string>public.text</string>
				<string>public.data</string>
			</array>
		</dict>
	</array>
复制代码

属性说明:
数组

  • CFBundleTypeName:文档的类型名称
  • LSHandlerRank:这里指是否拥有子文档

3. info.plist 中,对应Localization native development region键值 加入Chinese


4. 在第三方调用咱们的APP后,会调用以下方法

- (BOOL)application:(UIApplication *)application openURL:(nonnull NSURL *)url options:(nonnull NSDictionary<NSString *,id> *)options {
    if (options) {
        NSString *str = [NSString stringWithFormat:@"\n发送请求的应用程序的 Bundle ID:%@\n\n文件的NSURL:%@", options[UIApplicationOpenURLOptionsSourceApplicationKey], url];
        NSLog(@"%@", str);
        
        if (self.window && url) {
            // 根据“其余应用” 用“本应用”打开,经过url,进入列表页
            [self pushDocListViewControllerWithUrl:url];
        }
    }
    return YES;
}


#pragma mark ApplicationDelegate Method
/** 根据“其余应用” 用“本应用”打开,经过url,进入列表页 */
- (void)pushDocListViewControllerWithUrl:(NSURL *)url {
    // 根据“其余应用” 用“本应用”打开,经过要打开的url,得到本地地址
    NSString *appFilePath = [[JhtDocFileOperations sharedInstance] findLocalPathFromAppLicationOpenUrl:url];
    // 跳转页面
    DocListViewController *doc = [[DocListViewController alloc] init];
    doc.appFilePath = appFilePath;
    [_nav pushViewController:doc animated:YES];
}
复制代码

5. 库文件

系统库:WebKit.framework <br>
三方库:AFNetworking3.x <br>
复制代码

Github 传送门网络

相关文章
相关标签/搜索