DownFileViewController.m 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428
  1. //
  2. // DownFileViewController.m
  3. // smartRhino
  4. //
  5. // Created by tederen on 2019/11/8.
  6. // Copyright © 2019 tederen. All rights reserved.
  7. //
  8. #import "DownFileViewController.h"
  9. #import <WebKit/WebKit.h>
  10. #import "NoteBookShareVC.h"
  11. #import "SendInfoGroupVC.h"
  12. #import "DrawerView.h"
  13. #import "TabBarController.h"
  14. #import "MyTDGroupViewController.h"
  15. #import "FavoritesViewController.h"
  16. #import "MyTDTopicViewController.h"
  17. #import <Social/Social.h>
  18. #import "MoveViewController.h"
  19. #import "ShareListVC.h"
  20. @interface DownFileViewController ()<WKNavigationDelegate,WKUIDelegate,NoteBookShareVCDelegate>
  21. //@property (nonatomic, strong) UIImageView *imagview;
  22. //@property (nonatomic, strong) UIView *labelView;
  23. @property (nonatomic, strong) UIView *myFooterView;
  24. @property (nonatomic, strong) TDButton *otherButton;
  25. @property (nonatomic, strong) TDButton *shareButton;
  26. @property (strong, nonatomic) NoteBookShareVC * noteBookShareVC;
  27. @property (nonatomic, strong) WKWebView *webView;
  28. @property (nonatomic, strong) DrawerView *drawerView;
  29. @property(nonatomic,strong) UIDocumentInteractionController *documentInteractionController;
  30. // 分割
  31. @property(nonatomic,strong) UIView *sepView;
  32. @end
  33. @implementation DownFileViewController
  34. - (void)viewDidLoad {
  35. [super viewDidLoad];
  36. [self.view addSubview:self.myFooterView];
  37. [self.myFooterView mas_makeConstraints:^(MASConstraintMaker *make) {
  38. make.left.right.mas_equalTo(self.view);
  39. make.height.mas_offset(50);
  40. if (@available(iOS 11.0, *)) {
  41. make.bottom.equalTo(self.view.mas_safeAreaLayoutGuideBottom);
  42. } else {
  43. make.bottom.equalTo(self.view.mas_bottom);
  44. }
  45. }];
  46. [self.view addSubview:self.sepView];
  47. [self.sepView mas_makeConstraints:^(MASConstraintMaker *make) {
  48. make.left.right.equalTo(self.view);
  49. make.bottom.equalTo(self.myFooterView.mas_top);
  50. make.height.mas_equalTo(6);
  51. }];
  52. [self.view layoutIfNeeded];
  53. [self.view addSubview:self.webView];
  54. [self.webView mas_makeConstraints:^(MASConstraintMaker *make) {
  55. make.left.right.mas_equalTo(self.view);
  56. make.top.mas_equalTo(self.myNavigationBar.mas_bottom);
  57. make.bottom.equalTo(self.sepView.mas_top);
  58. }];
  59. self.myNavigationBar.titleLabel.text = self.model.Title;
  60. [self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:self.model.Url]]];
  61. [[UtilsTools getWindow] addSubview:self.noteBookShareVC.view];
  62. }
  63. - (void)openFileWithURL:(NSURL *)URL
  64. {
  65. NSLog(@"now open %@",URL);
  66. if (URL) {
  67. // Initialize Document Interaction Controller
  68. self.documentInteractionController = [UIDocumentInteractionController
  69. interactionControllerWithURL:URL];
  70. // Configure Document Interaction Controller
  71. self.documentInteractionController.delegate = self;
  72. // Preview File
  73. [self.documentInteractionController presentPreviewAnimated:YES];
  74. }
  75. }
  76. #pragma mark - button hander
  77. - (void)otherButtonHander{
  78. // [self SystermOpenFile];
  79. [self shareBtClick];
  80. }
  81. #pragma mark - Social 框架
  82. - (void)share3{
  83. // 判断服务是否可用
  84. [SLComposeViewController isAvailableForServiceType:SLServiceTypeSinaWeibo];
  85. if (![SLComposeViewController isAvailableForServiceType:SLServiceTypeSinaWeibo]) {
  86. NSLog(@"设置界面设置自己的账号");
  87. return;
  88. }
  89. // 弹出分享内容输入界面
  90. SLComposeViewController *cc = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeSinaWeibo];
  91. [cc setInitialText:@"测试文字"]; // 初始化文字
  92. [cc addImage:[UIImage imageNamed:@"zhujun"]]; // 配图
  93. cc.completionHandler = ^(SLComposeViewControllerResult reulst) {
  94. if (reulst == SLComposeViewControllerResultDone) {
  95. NSLog(@"用户发送成功");
  96. } else {
  97. NSLog(@"用户发送失败");
  98. }
  99. };
  100. [self presentViewController:cc animated:YES completion:nil];
  101. // 额外设置
  102. }
  103. - (void)shareBtClick
  104. {
  105. NSString *textToShare = @"灵犀办公";
  106. UIImage *imageToShare = [UIImage imageNamed:@"AppIcon"];
  107. NSURL *urlToShare = [NSURL URLWithString:self.model.Url];
  108. // 分享的图片不能为空
  109. NSArray *activityItems = @[textToShare, imageToShare, urlToShare];
  110. UIActivityViewController *activityVC = [[UIActivityViewController alloc]initWithActivityItems:activityItems applicationActivities:nil];
  111. // 排除(UIActivityTypeAirDrop)AirDrop 共享、(UIActivityTypePostToFacebook)Facebook
  112. activityVC.excludedActivityTypes = @[UIActivityTypePostToFacebook, UIActivityTypeAirDrop];
  113. [self presentViewController:activityVC animated:YES completion:nil];
  114. // 通过block接收结果处理
  115. UIActivityViewControllerCompletionWithItemsHandler completionHandler = ^(UIActivityType __nullable activityType, BOOL completed, NSArray * __nullable returnedItems, NSError * __nullable activityError){
  116. if (completed) {
  117. // [self showAlertViewWithMsg:@"恭喜你,分享成功!"];
  118. }else{
  119. // [self showAlertViewWithMsg:@"很遗憾,分享失败!"];
  120. }
  121. };
  122. activityVC.completionWithItemsHandler = completionHandler;
  123. }
  124. #pragma mark - 调用系统其他app 打开文件
  125. - (void)SystermOpenFile{
  126. NSURL *url = [NSURL fileURLWithPath:self.model.Url];
  127. _documentInteractionController = [UIDocumentInteractionController interactionControllerWithURL:url];
  128. [_documentInteractionController setDelegate:self];
  129. [_documentInteractionController presentOpenInMenuFromRect:CGRectZero inView:self.view animated:YES];
  130. }
  131. #pragma mark - 调用系统 打开文件分享文件
  132. - (void)systermShare{
  133. NSString *shareTitle = @"分享的标题";
  134. UIImage *shareImage = [UIImage imageNamed:@"me"];
  135. NSURL *shareUrl = [NSURL URLWithString:@"https://www.jianshu.com/u/acdcce712303"];
  136. NSArray *activityItems = @[shareTitle,
  137. shareImage,
  138. shareUrl]; // 必须要提供url 才会显示分享标签否则只显示图片
  139. UIActivityViewController *activityVC = [[UIActivityViewController alloc]
  140. initWithActivityItems:activityItems
  141. applicationActivities:nil];
  142. activityVC.excludedActivityTypes = [self excludetypes];
  143. activityVC.completionWithItemsHandler = ^(UIActivityType _Nullable activityType,
  144. BOOL completed,
  145. NSArray * _Nullable returnedItems,
  146. NSError * _Nullable activityError) {
  147. NSLog(@"activityType: %@,\n completed: %d,\n returnedItems:%@,\n activityError:%@",activityType,completed,returnedItems,activityError);
  148. };
  149. [self presentViewController:activityVC animated:YES completion:nil];
  150. }
  151. -(NSArray *)excludetypes{
  152. NSMutableArray *excludeTypesM = [NSMutableArray arrayWithArray:@[//UIActivityTypePostToFacebook,
  153. UIActivityTypePostToTwitter,
  154. UIActivityTypePostToWeibo,
  155. UIActivityTypeMessage,
  156. UIActivityTypeMail,
  157. UIActivityTypePrint,
  158. UIActivityTypeCopyToPasteboard,
  159. UIActivityTypeAssignToContact,
  160. UIActivityTypeSaveToCameraRoll,
  161. UIActivityTypeAddToReadingList,
  162. UIActivityTypePostToFlickr,
  163. UIActivityTypePostToVimeo,
  164. UIActivityTypePostToTencentWeibo,
  165. UIActivityTypeAirDrop,
  166. UIActivityTypeOpenInIBooks]];
  167. if ([[UIDevice currentDevice].systemVersion floatValue] >= 11.0) {
  168. if (@available(iOS 11.0, *)) {
  169. [excludeTypesM addObject:UIActivityTypeMarkupAsPDF];
  170. } else {
  171. // Fallback on earlier versions
  172. }
  173. }
  174. return excludeTypesM;
  175. }
  176. - (void)backButtonAction2:(UIButton *)sender {
  177. [self secondBarButtonItems];
  178. }
  179. - (void)secondBarButtonItems{
  180. [[UtilsTools getWindow] addSubview:self.drawerView];
  181. WS(weakSelf);
  182. self.drawerView.SelectDrawerBlock = ^(NSIndexPath * _Nonnull indexPath) {
  183. if ([weakSelf.navigationController.viewControllers count] > 1) {
  184. [weakSelf.navigationController popToRootViewControllerAnimated:NO];
  185. }
  186. if (indexPath.section == 0) {
  187. [[TabBarController sharedTabBarController] setSelectedIndex:indexPath.row];
  188. }else{
  189. ///@"站内信", @"通知", @"收藏",@"笔记", @"设置"
  190. switch (indexPath.row) {
  191. case 0:
  192. {
  193. [[TabBarController sharedTabBarController] setSelectedIndex:2];
  194. }
  195. break;
  196. case 1:
  197. {
  198. [[TabBarController sharedTabBarController] setSelectedIndex:2];
  199. }
  200. break;
  201. default:
  202. {
  203. [[TabBarController sharedTabBarController] setSelectedIndex:3];
  204. }
  205. break;
  206. }
  207. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  208. [[NSNotificationCenter defaultCenter] postNotificationName:DRAWERPUSHVC object:nil userInfo:@{VCINDEX:@(indexPath.row)}];
  209. });
  210. }
  211. };
  212. self.drawerView.frame = CGRectMake(0,0, SCREEN_WIDTH, SCREEN_HEIGHT);
  213. }
  214. - (DrawerView *)drawerView {
  215. if(!_drawerView) {
  216. _drawerView = [[DrawerView alloc] init];
  217. }
  218. return _drawerView;
  219. }
  220. - (TDButton *)otherButton{
  221. if (!_otherButton) {
  222. _otherButton = [[TDButton alloc]init];
  223. [_otherButton setTitle:@"其他应用打开" forState:UIControlStateNormal];
  224. [_otherButton setTitleColor:UIColorHex(666666) forState:UIControlStateNormal];
  225. [_otherButton setImage:IMG(@"更多") forState:UIControlStateNormal];
  226. [_otherButton addTarget:self action:@selector(otherButtonHander) forControlEvents:UIControlEventTouchUpInside];
  227. [[_otherButton titleLabel] setFont:[UIFont systemFontOfSize:15]];
  228. [_otherButton layoutButtonWithEdgeInsetsStyle:GLButtonEdgeInsetsStyleTop imageTitleSpace:5];
  229. }
  230. return _otherButton;
  231. }
  232. - (TDButton *)shareButton{
  233. if (!_shareButton) {
  234. _shareButton = [[TDButton alloc]init];
  235. [_shareButton setTitle:@"转发" forState:UIControlStateNormal];
  236. [_shareButton setTitleColor:UIColorHex(666666) forState:UIControlStateNormal];
  237. [_shareButton setImage:IMG(@"转发") forState:UIControlStateNormal];
  238. [[_shareButton titleLabel] setFont:[UIFont systemFontOfSize:15]];
  239. [_shareButton addTarget:self action:@selector(shareButtonHander) forControlEvents:UIControlEventTouchUpInside];
  240. [_shareButton layoutButtonWithEdgeInsetsStyle:GLButtonEdgeInsetsStyleTop imageTitleSpace:10];
  241. }
  242. return _shareButton;
  243. }
  244. - (UIView *)myFooterView{
  245. if(!_myFooterView){
  246. _myFooterView = [UIView new];
  247. [_myFooterView addSubview:self.otherButton];
  248. [_myFooterView addSubview:self.shareButton];
  249. [self.otherButton mas_makeConstraints:^(MASConstraintMaker *make) {
  250. make.left.equalTo(self.myFooterView).offset(40);
  251. make.centerY.equalTo(self.myFooterView);
  252. make.width.mas_equalTo(120);
  253. make.height.mas_equalTo(50);
  254. }];
  255. [self.shareButton mas_makeConstraints:^(MASConstraintMaker *make) {
  256. make.right.equalTo(self.myFooterView).offset(-20);
  257. make.centerY.equalTo(self.myFooterView);
  258. make.width.mas_equalTo(120);
  259. make.height.mas_equalTo(50);
  260. }];
  261. }
  262. return _myFooterView;
  263. }
  264. - (WKWebView *)webView {
  265. if (!_webView) {
  266. // 进行配置控制器
  267. WKWebViewConfiguration *configuration = [[WKWebViewConfiguration alloc] init];
  268. // 实例化对象
  269. configuration.userContentController = [WKUserContentController new];
  270. // 调用JS方法
  271. // [configuration.userContentController addScriptMessageHandler:self name:@"uploadPersonImage"];
  272. //window.webkit.messageHandlers.uploadPersonImage.postMessage({body: 'goodsId=1212'}); js调用
  273. // 进行偏好设置
  274. WKPreferences *preferences = [WKPreferences new];
  275. preferences.javaScriptEnabled = YES;
  276. preferences.javaScriptCanOpenWindowsAutomatically = YES;
  277. preferences.minimumFontSize = 40.0;
  278. configuration.preferences = preferences;
  279. _webView = [[WKWebView alloc] init];
  280. // _webView = [[WKWebView alloc] initWithFrame:CGRectMake(0,kNavigationHeight,kGXScreenWidth,kGXScreenHeigh - kNavigationHeight - 71 - self.sepView.height) configuration:configuration];
  281. _webView.navigationDelegate = self;
  282. _webView.opaque = NO;
  283. // _webView.backgroundColor = [UIColor whiteColor];
  284. if (@available(ios 11.0,*)){ _webView.scrollView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;}
  285. }
  286. return _webView;
  287. }
  288. // 页面开始加载时调用
  289. -(void)webView:(WKWebView *)webView didStartProvisionalNavigation:(WKNavigation *)navigation{
  290. SHOWLOADING
  291. }
  292. // 当内容开始返回时调用
  293. - (void)webView:(WKWebView *)webView didCommitNavigation:(WKNavigation *)navigation{
  294. REMOVESHOW
  295. }
  296. // 页面加载完成之后调用
  297. - (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation{//这里修改导航栏的标题,动态改变
  298. REMOVESHOW
  299. }
  300. // 页面加载失败时调用
  301. - (void)webView:(WKWebView *)webView didFailProvisionalNavigation:(WKNavigation *)navigation{
  302. [webView reload];
  303. }
  304. -(UIView *)sepView {
  305. if (!_sepView) {
  306. _sepView = [UIView new];
  307. _sepView.backgroundColor = kColorFromRGB(0xeeeeee);
  308. }
  309. return _sepView;
  310. }
  311. #pragma mark -转发
  312. - (void)shareButtonHander{
  313. [self.noteBookShareVC initNoteBookShareData];
  314. self.noteBookShareVC.isWork = YES;
  315. self.noteBookShareVC.view.hidden = !self.noteBookShareVC.view.hidden;
  316. }
  317. - (NoteBookShareVC *)noteBookShareVC{
  318. if (_noteBookShareVC == nil) {
  319. _noteBookShareVC = [NoteBookShareVC initNoteBookShareVC];
  320. [_noteBookShareVC.view setHidden:YES];
  321. _noteBookShareVC.delegate = self;
  322. }
  323. return _noteBookShareVC;
  324. }
  325. -(void)userSelectType:(NSString *)typeName WithIndexPath:(NSIndexPath *)indexPath{
  326. self.noteBookShareVC.view.hidden = !self.noteBookShareVC.view.hidden;
  327. if ([typeName isEqualToString:@"发给微信好友"]) {
  328. }else if ([typeName isEqualToString:@"发到朋友圈"]){
  329. }else if ([typeName isEqualToString:@"发到微博"]){
  330. }else if ([typeName isEqualToString:@"发给QQ好友"]){
  331. }else if ([typeName isEqualToString:@"发到消息"]){
  332. [self returnToMessage];
  333. }else if ([typeName isEqualToString:@"发到小组"]){
  334. [self returnToGroup];
  335. }else if ([typeName isEqualToString:@"发到笔记"]){
  336. [self returnToNote];
  337. }else if ([typeName isEqualToString:@"发到话题"]){
  338. [self returnToTopic];
  339. }else{
  340. }
  341. }
  342. - (void)returnToMessage
  343. {
  344. ShareListVC * vc = [ShareListVC initShareListVC];
  345. FlowAttachmentsModel * fModel = self.model;
  346. if (fModel.SoureTypeId != 301) {
  347. fModel.MinUrl = @"";
  348. }
  349. vc.sendModel = fModel;
  350. vc.isReturn = YES;
  351. [self.navigationController pushViewController:vc animated:YES];
  352. }
  353. - (void)returnToGroup
  354. {
  355. MyTDGroupViewController * vc = [[MyTDGroupViewController alloc] init];
  356. vc.type = CollectModel_Group;
  357. FlowAttachmentsModel * fModel = self.model;
  358. if (fModel.SoureTypeId != 301) {
  359. fModel.MinUrl = @"";
  360. }
  361. vc.sendModel = fModel;
  362. vc.isReturn = YES;
  363. [self.navigationController pushViewController:vc animated:YES];
  364. }
  365. - (void)returnToNote
  366. {
  367. MyTDTopicCreateVC * vc = [MyTDTopicCreateVC initMyTDTopicCreateVC];
  368. vc.type = CollectModel_NoteBook;
  369. FlowAttachmentsModel * fModel = self.model;
  370. if (fModel.SoureTypeId != 301) {
  371. fModel.MinUrl = @"";
  372. }
  373. vc.sendModel = fModel;
  374. vc.isReturn = YES;
  375. [self.navigationController pushViewController:vc animated:YES];
  376. }
  377. - (void)returnToTopic
  378. {
  379. MyTDTopicCreateVC * vc = [MyTDTopicCreateVC initMyTDTopicCreateVC];
  380. vc.type = CollectModel_NewTopic;
  381. FlowAttachmentsModel * fModel = self.model;
  382. if (fModel.SoureTypeId != 301) {
  383. fModel.MinUrl = @"";
  384. }
  385. vc.sendModel = fModel;
  386. vc.isReturn = YES;
  387. [self.navigationController pushViewController:vc animated:YES];
  388. }
  389. @end