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碍侦,文件名粱坤,絕對路徑(本地文件),文件大小等參數
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》打開
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.
系統(tǒng)會告訴我們不能直接使用HTTP進行請求梯嗽,需要在Info.plist新增一段用于控制ATS的配置
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
即:
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發(fā)送請求的應用程序的 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. 庫文件
系統(tǒng)庫:WebKit.framework <br>
三方庫:AFNetworking3.x <br>