CCDetail.m 44 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007
  1. //
  2. // CCDetail.m
  3. // Nextcloud iOS
  4. //
  5. // Created by Marino Faggiana on 16/01/15.
  6. // Copyright (c) 2017 TWS. All rights reserved.
  7. //
  8. // Author Marino Faggiana <m.faggiana@twsweb.it>
  9. //
  10. // This program is free software: you can redistribute it and/or modify
  11. // it under the terms of the GNU General Public License as published by
  12. // the Free Software Foundation, either version 3 of the License, or
  13. // (at your option) any later version.
  14. //
  15. // This program is distributed in the hope that it will be useful,
  16. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. // GNU General Public License for more details.
  19. //
  20. // You should have received a copy of the GNU General Public License
  21. // along with this program. If not, see <http://www.gnu.org/licenses/>.
  22. //
  23. #import "CCDetail.h"
  24. #import "AppDelegate.h"
  25. #import "CCMain.h"
  26. #import "NCUchardet.h"
  27. #import "NCBridgeSwift.h"
  28. #define TOOLBAR_HEIGHT 49.0f
  29. #define alertRequestPasswordPDF 1
  30. @interface CCDetail () <CCActionsDeleteDelegate>
  31. {
  32. AppDelegate *appDelegate;
  33. UIToolbar *_toolbar;
  34. UIBarButtonItem *_buttonModifyTxt;
  35. UIBarButtonItem *_buttonAction;
  36. UIBarButtonItem *_buttonShare;
  37. UIBarButtonItem *_buttonDelete;
  38. NSInteger _indexNowVisible;
  39. NSString *_fileIDNowVisible;
  40. NSMutableOrderedSet *_dataSourceDirectoryID;
  41. NSString *_fileNameExtension;
  42. CCHud *_hud;
  43. }
  44. @end
  45. @implementation CCDetail
  46. #pragma --------------------------------------------------------------------------------------------
  47. #pragma mark ===== init =====
  48. #pragma --------------------------------------------------------------------------------------------
  49. - (id)initWithCoder:(NSCoder *)aDecoder
  50. {
  51. if (self = [super initWithCoder:aDecoder]) {
  52. appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  53. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(triggerProgressTask:) name:@"NotificationProgressTask" object:nil];
  54. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(changeTheming) name:@"changeTheming" object:nil];
  55. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(backNavigationController) name:@"detailBack" object:nil];
  56. self.metadataDetail = [[tableMetadata alloc] init];
  57. self.photos = [[NSMutableArray alloc] init];
  58. self.dataSourceImagesVideos = [[NSMutableArray alloc] init];
  59. _dataSourceDirectoryID = [[NSMutableOrderedSet alloc] init];
  60. _hud = [[CCHud alloc] initWithView:[[[UIApplication sharedApplication] delegate] window]];
  61. _indexNowVisible = -1;
  62. _fileIDNowVisible = nil;
  63. appDelegate.activeDetail = self;
  64. }
  65. return self;
  66. }
  67. #pragma --------------------------------------------------------------------------------------------
  68. #pragma mark ===== View =====
  69. #pragma --------------------------------------------------------------------------------------------
  70. - (void)viewDidLoad
  71. {
  72. [super viewDidLoad];
  73. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(insertGeocoderLocation:) name:@"insertGeocoderLocation" object:nil];
  74. self.imageBackground.image = [UIImage imageNamed:@"backgroundDetail"];
  75. // Change bar bottom line shadow
  76. self.navigationController.navigationBar.shadowImage = [CCGraphics generateSinglePixelImageWithColor:[NCBrandColor sharedInstance].brand];
  77. if ([self.metadataDetail.fileNameView length] > 0 || [self.metadataDetail.directoryID length] > 0 || [self.metadataDetail.fileID length] > 0) {
  78. // open view
  79. [self viewFile];
  80. }
  81. }
  82. // Apparirà
  83. - (void)viewWillAppear:(BOOL)animated
  84. {
  85. [super viewWillAppear:animated];
  86. if (self.splitViewController.isCollapsed) {
  87. self.tabBarController.tabBar.hidden = YES;
  88. self.tabBarController.tabBar.translucent = YES;
  89. }
  90. if (self.splitViewController.isCollapsed)
  91. [appDelegate plusButtonVisibile:false];
  92. }
  93. // E' scomparso
  94. - (void)viewDidDisappear:(BOOL)animated
  95. {
  96. [super viewDidDisappear:animated];
  97. // remove all
  98. if (self.isMovingFromParentViewController)
  99. [self removeAllView];
  100. }
  101. - (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator
  102. {
  103. [coordinator animateAlongsideTransition:nil completion:^(id<UIViewControllerTransitionCoordinatorContext> context) {
  104. }];
  105. [super viewWillTransitionToSize:size withTransitionCoordinator:coordinator];
  106. }
  107. // remove all view
  108. - (void)removeAllView
  109. {
  110. // Document
  111. if (_webView) {
  112. [_webView removeFromSuperview];
  113. _webView = nil;
  114. }
  115. // PDF
  116. if (_readerPDFViewController) {
  117. [_readerPDFViewController.view removeFromSuperview];
  118. _readerPDFViewController.delegate = nil;
  119. _readerPDFViewController = nil;
  120. }
  121. // Photo-Video-Audio
  122. if (_photoBrowser) {
  123. [_photos removeAllObjects];
  124. _photoBrowser.delegate = nil;
  125. _photoBrowser = nil;
  126. }
  127. // ToolBar
  128. if (_toolbar) {
  129. [_toolbar removeFromSuperview];
  130. _toolbar = nil;
  131. }
  132. // Title
  133. self.title = nil;
  134. }
  135. - (void)backNavigationController
  136. {
  137. [self removeAllView];
  138. [self.navigationController popViewControllerAnimated:NO];
  139. }
  140. - (void)changeToDisplayMode
  141. {
  142. if (_readerPDFViewController)
  143. [self.readerPDFViewController updateContentViews];
  144. }
  145. - (void)createToolbar
  146. {
  147. CGFloat safeAreaBottom = 0;
  148. if (@available(iOS 11, *)) {
  149. safeAreaBottom = [UIApplication sharedApplication].delegate.window.safeAreaInsets.bottom;
  150. }
  151. _toolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, self.view.bounds.size.height - TOOLBAR_HEIGHT - safeAreaBottom, self.view.bounds.size.width, TOOLBAR_HEIGHT)];
  152. UIBarButtonItem *flexible = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:self action:nil];
  153. UIBarButtonItem *fixedSpaceMini = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:self action:nil];
  154. fixedSpaceMini.width = 25;
  155. _buttonModifyTxt = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"actionSheetModify"] style:UIBarButtonItemStylePlain target:self action:@selector(modifyTxtButtonPressed:)];
  156. _buttonAction = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"actionSheetOpenIn"] style:UIBarButtonItemStylePlain target:self action:@selector(actionButtonPressed:)];
  157. _buttonShare = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"share"] style:UIBarButtonItemStylePlain target:self action:@selector(shareButtonPressed:)];
  158. _buttonDelete = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemTrash target:self action:@selector(deleteButtonPressed:)];
  159. if ([_fileNameExtension isEqualToString:@"TXT"]) {
  160. if ([CCUtility isFolderEncrypted:[[NCManageDatabase sharedInstance] getServerUrl:_metadataDetail.directoryID] account:appDelegate.activeAccount]) // E2EE
  161. [_toolbar setItems:[NSArray arrayWithObjects: _buttonModifyTxt, flexible, _buttonDelete, fixedSpaceMini, _buttonAction, nil]];
  162. else
  163. [_toolbar setItems:[NSArray arrayWithObjects: _buttonModifyTxt, flexible, _buttonDelete, fixedSpaceMini, _buttonShare, fixedSpaceMini, _buttonAction, nil]];
  164. } else {
  165. if ([CCUtility isFolderEncrypted:[[NCManageDatabase sharedInstance] getServerUrl:_metadataDetail.directoryID] account:appDelegate.activeAccount]) // E2EE
  166. [_toolbar setItems:[NSArray arrayWithObjects: flexible, _buttonDelete, fixedSpaceMini, _buttonAction, nil]];
  167. else
  168. [_toolbar setItems:[NSArray arrayWithObjects: flexible, _buttonDelete, fixedSpaceMini, _buttonShare, fixedSpaceMini, _buttonAction, nil]];
  169. }
  170. [_toolbar setAutoresizingMask:UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleTopMargin];
  171. _toolbar.barTintColor = [NCBrandColor sharedInstance].tabBar;
  172. _toolbar.tintColor = [NCBrandColor sharedInstance].brandElement;
  173. [self.view addSubview:_toolbar];
  174. }
  175. - (void)changeTheming
  176. {
  177. [appDelegate changeTheming:self];
  178. if (_toolbar) {
  179. _toolbar.barTintColor = [NCBrandColor sharedInstance].tabBar;
  180. _toolbar.tintColor = [NCBrandColor sharedInstance].brandElement;
  181. }
  182. }
  183. #pragma --------------------------------------------------------------------------------------------
  184. #pragma mark ===== View File =====
  185. #pragma --------------------------------------------------------------------------------------------
  186. - (void)viewFile
  187. {
  188. // verifico se esiste l'icona e se la posso creare
  189. if ([[NSFileManager defaultManager] fileExistsAtPath:[NSString stringWithFormat:@"%@/%@.ico", appDelegate.directoryUser, self.metadataDetail.fileID]] == NO) {
  190. [CCGraphics createNewImageFrom:self.metadataDetail.fileID directoryUser:appDelegate.directoryUser fileNameTo:self.metadataDetail.fileID extension:[self.metadataDetail.fileNameView pathExtension] size:@"m" imageForUpload:NO typeFile:self.metadataDetail.typeFile writePreview:YES optimizedFileName:[CCUtility getOptimizedPhoto]];
  191. }
  192. if ([self.metadataDetail.typeFile isEqualToString: k_metadataTypeFile_image] || [self.metadataDetail.typeFile isEqualToString: k_metadataTypeFile_video] || [self.metadataDetail.typeFile isEqualToString: k_metadataTypeFile_audio]) {
  193. self.edgesForExtendedLayout = UIRectEdgeAll;
  194. [self viewImageVideoAudio];
  195. }
  196. if ([self.metadataDetail.typeFile isEqualToString: k_metadataTypeFile_document]) {
  197. _fileNameExtension = [[self.metadataDetail.fileNameView pathExtension] uppercaseString];
  198. if ([_fileNameExtension isEqualToString:@"PDF"]) {
  199. self.edgesForExtendedLayout = UIRectEdgeBottom;
  200. [self viewPDF:@""];
  201. [self createToolbar];
  202. [appDelegate aspectNavigationControllerBar:self.navigationController.navigationBar online:[appDelegate.reachability isReachable] hidden:NO];
  203. } else {
  204. self.edgesForExtendedLayout = UIRectEdgeBottom;
  205. [self viewDocument];
  206. [self createToolbar];
  207. [appDelegate aspectNavigationControllerBar:self.navigationController.navigationBar online:[appDelegate.reachability isReachable] hidden:NO];
  208. }
  209. }
  210. }
  211. #pragma --------------------------------------------------------------------------------------------
  212. #pragma mark ===== View Document =====
  213. #pragma --------------------------------------------------------------------------------------------
  214. - (void)viewDocument
  215. {
  216. NSString *fileName;
  217. CGFloat safeAreaBottom = 0;
  218. if (@available(iOS 11, *)) {
  219. safeAreaBottom = [UIApplication sharedApplication].delegate.window.safeAreaInsets.bottom;
  220. }
  221. fileName = [NSTemporaryDirectory() stringByAppendingString:self.metadataDetail.fileNameView];
  222. [[NSFileManager defaultManager] removeItemAtPath:fileName error:nil];
  223. [[NSFileManager defaultManager] linkItemAtPath:[NSString stringWithFormat:@"%@/%@", appDelegate.directoryUser, self.metadataDetail.fileID] toPath:fileName error:nil];
  224. if ([[NSFileManager defaultManager] fileExistsAtPath:fileName] == NO) {
  225. [self backNavigationController];
  226. return;
  227. }
  228. NSURL *url = [NSURL fileURLWithPath:fileName];
  229. WKPreferences *wkPreferences = [[WKPreferences alloc] init];
  230. wkPreferences.javaScriptEnabled = true;
  231. WKWebViewConfiguration *wkConfig = [[WKWebViewConfiguration alloc] init];
  232. wkConfig.preferences = wkPreferences;
  233. self.webView = [[WKWebView alloc] initWithFrame:(CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height - TOOLBAR_HEIGHT - safeAreaBottom)) configuration:wkConfig];
  234. self.webView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
  235. [self.webView setBackgroundColor:[NCBrandColor sharedInstance].backgroundView];
  236. [self.webView setOpaque:NO];
  237. if ( [_fileNameExtension isEqualToString:@"CSS"] || [_fileNameExtension isEqualToString:@"PY"] || [_fileNameExtension isEqualToString:@"XML"] || [_fileNameExtension isEqualToString:@"JS"] ) {
  238. NSString *dataFile = [[NSString alloc] initWithData:[NSData dataWithContentsOfURL:url] encoding:NSASCIIStringEncoding];
  239. if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
  240. [self.webView loadHTMLString:[NSString stringWithFormat:@"<div style='font-size:%@;font-family:%@;'><pre>%@",@"40",@"Sans-Serif",dataFile] baseURL:nil];
  241. }else{
  242. [self.webView loadHTMLString:[NSString stringWithFormat:@"<div style='font-size:%@;font-family:%@;'><pre>%@",@"20",@"Sans-Serif",dataFile] baseURL:nil];
  243. }
  244. } else if ([_fileNameExtension isEqualToString:@"TXT"] || [_fileNameExtension isEqualToString:@"MD"]) {
  245. NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration defaultSessionConfiguration];
  246. NSURLSession *session = [NSURLSession sessionWithConfiguration:configuration delegate:nil delegateQueue:nil];
  247. NSMutableURLRequest *headRequest = [NSMutableURLRequest requestWithURL:url];
  248. [headRequest setHTTPMethod:@"HEAD"];
  249. NSURLSessionDataTask *task = [session dataTaskWithRequest:headRequest completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
  250. dispatch_async(dispatch_get_main_queue(), ^{
  251. NSString *encodingName = [[NCUchardet sharedNUCharDet] encodingStringDetectWithData:data];
  252. [self.webView loadData:[NSData dataWithContentsOfURL: url] MIMEType:response.MIMEType characterEncodingName:encodingName baseURL:url];
  253. });
  254. }];
  255. [task resume];
  256. } else {
  257. [self.webView loadRequest:[NSMutableURLRequest requestWithURL:url]];
  258. }
  259. [self.view addSubview:self.webView];
  260. }
  261. #pragma --------------------------------------------------------------------------------------------
  262. #pragma mark ===== View Image =====
  263. #pragma --------------------------------------------------------------------------------------------
  264. - (void)viewImageVideoAudio
  265. {
  266. self.photoBrowser = [[MWPhotoBrowser alloc] initWithDelegate:self];
  267. _indexNowVisible = -1;
  268. _fileIDNowVisible = nil;
  269. [self.photos removeAllObjects];
  270. [_dataSourceDirectoryID removeAllObjects];
  271. // if not images, exit
  272. if ([self.dataSourceImagesVideos count] == 0) return;
  273. NSUInteger index = 0;
  274. for (tableMetadata *metadata in self.dataSourceImagesVideos) {
  275. // start from here ?
  276. if (self.metadataDetail.fileID && [metadata.fileID isEqualToString:self.metadataDetail.fileID])
  277. [self.photoBrowser setCurrentPhotoIndex:index];
  278. [self.photos addObject:[MWPhoto photoWithImage:nil]];
  279. // add directory
  280. [_dataSourceDirectoryID addObject:metadata.directoryID];
  281. index++;
  282. }
  283. // PhotoBrowser
  284. self.photoBrowser.displayActionButton = YES;
  285. self.photoBrowser.displayDeleteButton = YES;
  286. if ([CCUtility isFolderEncrypted:[[NCManageDatabase sharedInstance] getServerUrl:_metadataDetail.directoryID] account:appDelegate.activeAccount]) // E2EE
  287. self.photoBrowser.displayShareButton = NO;
  288. else
  289. self.photoBrowser.displayShareButton = YES;
  290. self.photoBrowser.displayNavArrows = YES;
  291. self.photoBrowser.displaySelectionButtons = NO;
  292. self.photoBrowser.alwaysShowControls = NO;
  293. self.photoBrowser.zoomPhotosToFill = NO;
  294. self.photoBrowser.autoPlayOnAppear = NO;
  295. self.photoBrowser.delayToHideElements = 15;
  296. if ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPad)
  297. self.photoBrowser.enableSwipeToDismiss = NO;
  298. if (self.traitCollection.horizontalSizeClass == UIUserInterfaceSizeClassCompact) {
  299. [self addChildViewController:self.photoBrowser];
  300. [self.view addSubview:self.photoBrowser.view];
  301. [self.photoBrowser didMoveToParentViewController:self];
  302. } else {
  303. [self.navigationController pushViewController:self.photoBrowser animated:NO];
  304. }
  305. }
  306. - (NSUInteger)numberOfPhotosInPhotoBrowser:(MWPhotoBrowser *)photoBrowser
  307. {
  308. return [self.dataSourceImagesVideos count];
  309. }
  310. - (NSString *)photoBrowser:(MWPhotoBrowser *)photoBrowser titleForPhotoAtIndex:(NSUInteger)index
  311. {
  312. tableMetadata *metadata = [self.dataSourceImagesVideos objectAtIndex:index];
  313. NSString *titleDir = metadata.fileNameView;
  314. self.title = titleDir;
  315. return titleDir;
  316. }
  317. - (void)photoBrowser:(MWPhotoBrowser *)photoBrowser didDisplayPhotoAtIndex:(NSUInteger)index
  318. {
  319. tableMetadata *metadata = [self.dataSourceImagesVideos objectAtIndex:index];
  320. _indexNowVisible = index;
  321. _fileIDNowVisible = metadata.fileID;
  322. photoBrowser.toolbar.hidden = NO;
  323. // Download image ?
  324. if (metadata) {
  325. tableMetadata *metadataDB = [[NCManageDatabase sharedInstance] getMetadataWithPredicate:[NSPredicate predicateWithFormat:@"fileID = %@", metadata.fileID]];
  326. if ([[NSFileManager defaultManager] fileExistsAtPath:[NSString stringWithFormat:@"%@/%@", appDelegate.directoryUser, metadata.fileID]] == NO && [metadataDB.session length] == 0)
  327. [self downloadPhotoBrowser:metadata];
  328. }
  329. // Title
  330. if (metadata)
  331. self.title = metadata.fileNameView;
  332. }
  333. - (id <MWPhoto>)photoBrowser:(MWPhotoBrowser *)photoBrowser photoAtIndex:(NSUInteger)index
  334. {
  335. UIImage *image;
  336. tableMetadata *metadata = [self.dataSourceImagesVideos objectAtIndex:index];
  337. if (index < self.photos.count) {
  338. if (metadata.fileID) {
  339. if ([metadata.typeFile isEqualToString: k_metadataTypeFile_image]) {
  340. NSString *fileImage = [NSString stringWithFormat:@"%@/%@", appDelegate.directoryUser, metadata.fileID];
  341. NSString *ext = [CCUtility getExtension:metadata.fileNameView];
  342. if ([ext isEqualToString:@"GIF"]) image = [UIImage animatedImageWithAnimatedGIFURL:[NSURL fileURLWithPath:fileImage]];
  343. else image = [UIImage imageWithContentsOfFile:fileImage];
  344. if (image) {
  345. MWPhoto *photo = [MWPhoto photoWithImage:image];
  346. // Location ??
  347. [self setLocationCaptionPhoto:photo fileID:metadata.fileID];
  348. [self.photos replaceObjectAtIndex:index withObject:photo];
  349. } else {
  350. if ([metadata.sessionError length] > 0 ) {
  351. [self.photos replaceObjectAtIndex:index withObject:[MWPhoto photoWithImage:[UIImage imageNamed:@"filePreviewError"]]];
  352. }
  353. }
  354. }
  355. if ([metadata.typeFile isEqualToString: k_metadataTypeFile_video]) {
  356. if ([[NSFileManager defaultManager] fileExistsAtPath:[NSString stringWithFormat:@"%@/%@", appDelegate.directoryUser, metadata.fileID]]) {
  357. // remove and make the simbolic link in temp
  358. NSString *toPath = [NSTemporaryDirectory() stringByAppendingString:metadata.fileNameView];
  359. [[NSFileManager defaultManager] removeItemAtPath:toPath error:nil];
  360. [[NSFileManager defaultManager] linkItemAtPath:[NSString stringWithFormat:@"%@/%@", appDelegate.directoryUser, metadata.fileID] toPath:toPath error:nil];
  361. NSURL *url = [NSURL fileURLWithPath:toPath];
  362. MWPhoto *video = [MWPhoto photoWithImage:[CCGraphics thumbnailImageForVideo:url atTime:1.0]];
  363. video.videoURL = url;
  364. [self.photos replaceObjectAtIndex:index withObject:video];
  365. } else {
  366. if ([metadata.sessionError length] > 0 ) {
  367. [self.photos replaceObjectAtIndex:index withObject:[MWPhoto photoWithImage:[UIImage imageNamed:@"filePreviewError"]]];
  368. }
  369. }
  370. }
  371. if ([metadata.typeFile isEqualToString: k_metadataTypeFile_audio]) {
  372. if ([[NSFileManager defaultManager] fileExistsAtPath:[NSString stringWithFormat:@"%@/%@", appDelegate.directoryUser, metadata.fileID]]) {
  373. MWPhoto *audio;
  374. UIImage *audioImage;
  375. // remove and make the simbolic link in temp
  376. NSString *toPath = [NSTemporaryDirectory() stringByAppendingString:metadata.fileNameView];
  377. [[NSFileManager defaultManager] removeItemAtPath:toPath error:nil];
  378. [[NSFileManager defaultManager] linkItemAtPath:[NSString stringWithFormat:@"%@/%@", appDelegate.directoryUser, metadata.fileID] toPath:toPath error:nil];
  379. NSURL *url = [NSURL fileURLWithPath:toPath];
  380. if ([[NSFileManager defaultManager] fileExistsAtPath:[NSString stringWithFormat:@"%@/%@.ico", appDelegate.directoryUser, metadata.fileID]]) {
  381. audioImage = [UIImage imageWithContentsOfFile:[NSString stringWithFormat:@"%@/%@.ico", appDelegate.directoryUser, metadata.fileID]];
  382. } else {
  383. audioImage = [UIImage imageNamed:@"notaMusic"]; //[CCGraphics scaleImage:[UIImage imageNamed:@"notaMusic"] toSize:CGSizeMake(200, 200) isAspectRation:YES];
  384. }
  385. audio = [MWPhoto photoWithImage:audioImage];
  386. audio.videoURL = url;
  387. [self.photos replaceObjectAtIndex:index withObject:audio];
  388. } else {
  389. if ([metadata.sessionError length] > 0 ) {
  390. [self.photos replaceObjectAtIndex:index withObject:[MWPhoto photoWithImage:[UIImage imageNamed:@"filePreviewError"]]];
  391. }
  392. }
  393. }
  394. }
  395. // energy saving memory
  396. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  397. int iPrev = (int)index - 2;
  398. if (iPrev >= 0) {
  399. if ([self.photos objectAtIndex:iPrev] != nil)
  400. [self.photos replaceObjectAtIndex:iPrev withObject:[MWPhoto photoWithImage:nil]];
  401. }
  402. int iNext = (int)index + 2;
  403. if (iNext < _photos.count) {
  404. if ([self.photos objectAtIndex:iNext] != nil)
  405. [self.photos replaceObjectAtIndex:iNext withObject:[MWPhoto photoWithImage:nil]];
  406. }
  407. });
  408. return [self.photos objectAtIndex:index];
  409. }
  410. return nil;
  411. }
  412. - (void)photoBrowser:(MWPhotoBrowser *)photoBrowser actionButtonPressedForPhotoAtIndex:(NSUInteger)index
  413. {
  414. tableMetadata *metadata = [self.dataSourceImagesVideos objectAtIndex:index];
  415. if (metadata == nil) return;
  416. NSString *filePath = [NSString stringWithFormat:@"%@/%@", appDelegate.directoryUser, metadata.fileNameView];
  417. [[NSFileManager defaultManager] removeItemAtPath:filePath error:nil];
  418. [[NSFileManager defaultManager] linkItemAtPath:[NSString stringWithFormat:@"%@/%@", appDelegate.directoryUser, metadata.fileID] toPath:filePath error:nil];
  419. self.docController = [UIDocumentInteractionController interactionControllerWithURL:[NSURL fileURLWithPath:filePath]];
  420. self.docController.delegate = self;
  421. if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
  422. [self.docController presentOptionsMenuFromRect:photoBrowser.view.frame inView:photoBrowser.view animated:YES];
  423. [self.docController presentOptionsMenuFromBarButtonItem:photoBrowser.actionButton animated:YES];
  424. }
  425. - (void)photoBrowser:(MWPhotoBrowser *)photoBrowser shareButtonPressedForPhotoAtIndex:(NSUInteger)index
  426. {
  427. tableMetadata *metadata = [self.dataSourceImagesVideos objectAtIndex:index];
  428. [appDelegate.activeMain openWindowShare:metadata];
  429. }
  430. - (void)photoBrowser:(MWPhotoBrowser *)photoBrowser deleteButtonPressedForPhotoAtIndex:(NSUInteger)index deleteButton:(UIBarButtonItem *)deleteButton
  431. {
  432. tableMetadata *metadata = [self.dataSourceImagesVideos objectAtIndex:index];
  433. if (metadata == nil || [[NSFileManager defaultManager] fileExistsAtPath:[NSString stringWithFormat:@"%@/%@", appDelegate.directoryUser, metadata.fileID]] == NO) {
  434. [appDelegate messageNotification:@"_info_" description:@"_file_not_found_" visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeInfo errorCode:0];
  435. return;
  436. }
  437. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
  438. [alertController addAction: [UIAlertAction actionWithTitle:NSLocalizedString(@"_delete_", nil)
  439. style:UIAlertActionStyleDestructive
  440. handler:^(UIAlertAction *action) {
  441. [[CCActions sharedInstance] deleteFileOrFolder:metadata delegate:self hud:nil hudTitled:nil];
  442. }]];
  443. [alertController addAction: [UIAlertAction actionWithTitle:NSLocalizedString(@"_cancel_", nil)
  444. style:UIAlertActionStyleCancel
  445. handler:^(UIAlertAction *action) {
  446. [alertController dismissViewControllerAnimated:YES completion:nil];
  447. }]];
  448. alertController.popoverPresentationController.barButtonItem = deleteButton;
  449. if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
  450. [alertController.view layoutIfNeeded];
  451. [self.parentViewController presentViewController:alertController animated:YES completion:NULL];
  452. }
  453. - (void)photoBrowserDidFinishPresentation:(MWPhotoBrowser *)photoBrowser
  454. {
  455. [self removeAllView];
  456. [self.navigationController popViewControllerAnimated:YES];
  457. }
  458. - (void)triggerProgressTask:(NSNotification *)notification
  459. {
  460. NSDictionary *dict = notification.userInfo;
  461. NSString *fileID = [dict valueForKey:@"fileID"];
  462. //NSString *serverUrl = [dict valueForKey:@"serverUrl"];
  463. float progress = [[dict valueForKey:@"progress"] floatValue];
  464. if ([fileID isEqualToString:_fileIDNowVisible])
  465. [_hud progress:progress];
  466. }
  467. - (void)downloadPhotoBrowserSuccessFailure:(tableMetadata *)metadata selector:(NSString *)selector errorCode:(NSInteger)errorCode
  468. {
  469. // if a message for a directory of these
  470. if (![metadata.fileID isEqualToString:_fileIDNowVisible])
  471. return;
  472. [_hud hideHud];
  473. if (errorCode == 0) {
  474. // verifico se esiste l'icona e se la posso creare
  475. if ([[NSFileManager defaultManager] fileExistsAtPath:[NSString stringWithFormat:@"%@/%@.ico", appDelegate.directoryUser, metadata.fileID]] == NO)
  476. [CCGraphics createNewImageFrom:metadata.fileID directoryUser:appDelegate.directoryUser fileNameTo:metadata.fileID extension:[metadata.fileNameView pathExtension] size:@"m" imageForUpload:NO typeFile:metadata.typeFile writePreview:YES optimizedFileName:[CCUtility getOptimizedPhoto]];
  477. } else {
  478. [appDelegate messageNotification:@"_download_selected_files_" description:@"_error_download_photobrowser_" visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode:errorCode];
  479. }
  480. [self.photoBrowser reloadData];
  481. }
  482. - (void)downloadPhotoBrowser:(tableMetadata *)metadata
  483. {
  484. NSString *serverUrl = [[NCManageDatabase sharedInstance] getServerUrl:metadata.directoryID];
  485. if (serverUrl) {
  486. [_hud visibleHudTitle:@"" mode:MBProgressHUDModeDeterminate color:[NCBrandColor sharedInstance].brandElement];
  487. [[CCNetworking sharedNetworking] downloadFile:metadata.fileName fileID:metadata.fileID serverUrl:serverUrl selector:selectorLoadViewImage selectorPost:nil session:k_download_session taskStatus:k_taskStatusResume delegate:appDelegate.activeMain];
  488. }
  489. }
  490. - (void)insertGeocoderLocation:(NSNotification *)notification
  491. {
  492. if (notification.userInfo.count == 0)
  493. return;
  494. NSString *fileID = [[notification.userInfo allKeys] objectAtIndex:0];
  495. //NSDate *date = [[notification.userInfo allValues] objectAtIndex:0];
  496. // test [Chrash V 1.14,15]
  497. if (_indexNowVisible >= [self.photos count])
  498. return;
  499. if ([fileID isEqualToString:_fileIDNowVisible]) {
  500. MWPhoto *photo = [self.photos objectAtIndex:_indexNowVisible];
  501. [self setLocationCaptionPhoto:photo fileID:fileID];
  502. [self.photoBrowser reloadData];
  503. }
  504. }
  505. - (void)setLocationCaptionPhoto:(MWPhoto *)photo fileID:(NSString *)fileID
  506. {
  507. tableLocalFile *localFile;
  508. // read Geocoder
  509. localFile = [[NCManageDatabase sharedInstance] getTableLocalFileWithPredicate:[NSPredicate predicateWithFormat:@"fileID = %@", fileID]];
  510. if ([localFile.exifLatitude doubleValue] != 0 || [localFile.exifLongitude doubleValue] != 0) {
  511. // Fix BUG Geo latitude & longitude
  512. if ([localFile.exifLatitude doubleValue] == 9999 || [localFile.exifLongitude doubleValue] == 9999) {
  513. tableMetadata *metadata = [[NCManageDatabase sharedInstance] getMetadataWithPredicate:[NSPredicate predicateWithFormat:@"fileID = %@", fileID]];
  514. if (metadata) {
  515. [[CCExifGeo sharedInstance] setExifLocalTableEtag:metadata directoryUser:appDelegate.directoryUser activeAccount:appDelegate.activeAccount];
  516. }
  517. }
  518. [[CCExifGeo sharedInstance] setGeocoderEtag:fileID exifDate:localFile.exifDate latitude:localFile.exifLatitude longitude:localFile.exifLongitude];
  519. localFile = [[NCManageDatabase sharedInstance] getTableLocalFileWithPredicate:[NSPredicate predicateWithFormat:@"fileID = %@", fileID]];
  520. if ([localFile.exifLatitude floatValue] != 0 || [localFile.exifLongitude floatValue] != 0) {
  521. NSString *location = [[NCManageDatabase sharedInstance] getLocationFromGeoLatitude:localFile.exifLatitude longitude:localFile.exifLongitude];
  522. if ([localFile.exifDate isEqualToDate:[NSDate distantPast]] == NO && location) {
  523. NSString *localizedDateTime = [NSDateFormatter localizedStringFromDate:localFile.exifDate dateStyle:NSDateFormatterFullStyle timeStyle:NSDateFormatterMediumStyle];
  524. photo.caption = [NSString stringWithFormat:NSLocalizedString(@"%@\n%@", nil), localizedDateTime, location];
  525. }
  526. }
  527. }
  528. }
  529. #pragma --------------------------------------------------------------------------------------------
  530. #pragma mark ===== View PDF =====
  531. #pragma --------------------------------------------------------------------------------------------
  532. - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
  533. {
  534. [alertView dismissWithClickedButtonIndex:buttonIndex animated:YES];
  535. [[alertView textFieldAtIndex:0] resignFirstResponder];
  536. if (alertView.tag == alertRequestPasswordPDF) [self performSelector:@selector(viewPDF:) withObject:[alertView textFieldAtIndex:0].text afterDelay:0.3];
  537. }
  538. - (void)viewPDF:(NSString *)password
  539. {
  540. NSString *fileName = [NSTemporaryDirectory() stringByAppendingString:self.metadataDetail.fileNameView];
  541. [[NSFileManager defaultManager] removeItemAtPath:fileName error:nil];
  542. [[NSFileManager defaultManager] linkItemAtPath:[NSString stringWithFormat:@"%@/%@", appDelegate.directoryUser, self.metadataDetail.fileID] toPath:fileName error:nil];
  543. if ([[NSFileManager defaultManager] fileExistsAtPath:fileName isDirectory:nil] == NO) {
  544. // read file error
  545. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"_error_", nil) message:NSLocalizedString(@"_read_file_error_", nil) preferredStyle:UIAlertControllerStyleAlert];
  546. UIAlertAction *okAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"_ok_", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {}];
  547. [alertController addAction:okAction];
  548. [self presentViewController:alertController animated:YES completion:nil];
  549. }
  550. CGPDFDocumentRef pdf = CGPDFDocumentCreateWithURL((CFURLRef)[NSURL fileURLWithPath:fileName]);
  551. if (pdf) {
  552. // Encrypted
  553. if (CGPDFDocumentIsEncrypted(pdf) == YES) {
  554. // Try a blank password first, per Apple's Quartz PDF example
  555. if (CGPDFDocumentUnlockWithPassword(pdf, "") == YES) {
  556. // blank password
  557. [self readerPDF:fileName password:@""];
  558. } else {
  559. if ([password length] == 0) {
  560. // password request
  561. UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"_insert_password_pfd_",nil) message:nil delegate:self cancelButtonTitle:nil otherButtonTitles:NSLocalizedString(@"_ok_", nil), nil];
  562. [alertView setAlertViewStyle:UIAlertViewStylePlainTextInput];
  563. alertView.tag = alertRequestPasswordPDF;
  564. [alertView show];
  565. } else {
  566. const char *key = [password UTF8String];
  567. // failure
  568. if (CGPDFDocumentUnlockWithPassword(pdf, key) == NO) {
  569. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"_error_", nil) message:NSLocalizedString(@"_password_pdf_error_", nil) preferredStyle:UIAlertControllerStyleAlert];
  570. UIAlertAction *okAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"_ok_", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {}];
  571. [alertController addAction:okAction];
  572. [self presentViewController:alertController animated:YES completion:nil];
  573. } else {
  574. // pdf with password
  575. [self readerPDF:fileName password:password];
  576. }
  577. }
  578. }
  579. } else{
  580. // No password
  581. [self readerPDF:fileName password:@""];
  582. }
  583. } else {
  584. // read file error
  585. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"_error_", nil) message:NSLocalizedString(@"_read_file_error_", nil) preferredStyle:UIAlertControllerStyleAlert];
  586. UIAlertAction *okAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"_ok_", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {}];
  587. [alertController addAction:okAction];
  588. [self presentViewController:alertController animated:YES completion:nil];
  589. }
  590. }
  591. - (void)readerPDF:(NSString *)fileName password:(NSString *)password
  592. {
  593. ReaderDocument *documentPDF = [ReaderDocument withDocumentFilePath:fileName password:password];
  594. CGFloat safeAreaBottom = 0;
  595. if (@available(iOS 11, *)) {
  596. safeAreaBottom = [UIApplication sharedApplication].delegate.window.safeAreaInsets.bottom;
  597. }
  598. if (documentPDF != nil) {
  599. self.readerPDFViewController = [[ReaderViewController alloc] initWithReaderDocument:documentPDF];
  600. self.readerPDFViewController.delegate = self;
  601. self.readerPDFViewController.view.frame = CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height - TOOLBAR_HEIGHT - safeAreaBottom);
  602. [self.readerPDFViewController updateContentViews];
  603. [self addChildViewController:self.readerPDFViewController];
  604. [self.view addSubview:self.readerPDFViewController.view];
  605. [self.readerPDFViewController didMoveToParentViewController:self];
  606. } else {
  607. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"_error_", nil) message:NSLocalizedString(@"_read_file_error_", nil) preferredStyle:UIAlertControllerStyleAlert];
  608. UIAlertAction *okAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"_ok_", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {}];
  609. [alertController addAction:okAction];
  610. [self presentViewController:alertController animated:YES completion:nil];
  611. }
  612. }
  613. - (void)handleSingleTapReader
  614. {
  615. UILayoutGuide *layoutGuide;
  616. CGFloat safeAreaTop = 0;
  617. CGFloat safeAreaBottom = 0;
  618. if (@available(iOS 11, *)) {
  619. layoutGuide = [UIApplication sharedApplication].delegate.window.safeAreaLayoutGuide;
  620. safeAreaTop = [UIApplication sharedApplication].delegate.window.safeAreaInsets.top;
  621. safeAreaBottom = [UIApplication sharedApplication].delegate.window.safeAreaInsets.bottom;
  622. }
  623. self.navigationController.navigationBarHidden = !self.navigationController.navigationBarHidden;
  624. _toolbar.hidden = !_toolbar.isHidden;
  625. if (_toolbar.isHidden) {
  626. self.readerPDFViewController.view.frame = CGRectMake(0, safeAreaTop, self.view.bounds.size.width, self.view.bounds.size.height - safeAreaTop - safeAreaBottom);
  627. } else {
  628. self.readerPDFViewController.view.frame = CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height - TOOLBAR_HEIGHT - safeAreaBottom);
  629. }
  630. [self.readerPDFViewController updateContentViews];
  631. }
  632. - (void)handleSwipeUpDown
  633. {
  634. // REMOVE IT'S UNUSABLE
  635. /*
  636. self.navigationController.navigationBarHidden = false; // iOS App is unusable after swipe up or down with PDF in fullscreen #526
  637. [self removeAllView];
  638. [self.navigationController popViewControllerAnimated:YES];
  639. */
  640. }
  641. #pragma --------------------------------------------------------------------------------------------
  642. #pragma mark ===== Delete =====
  643. #pragma --------------------------------------------------------------------------------------------
  644. - (void)deleteFileOrFolderSuccessFailure:(CCMetadataNet *)metadataNet message:(NSString *)message errorCode:(NSInteger)errorCode
  645. {
  646. if (errorCode == 0) {
  647. // reload Main
  648. [appDelegate.activeMain reloadDatasource];
  649. // If removed document (web) or PDF close
  650. if (_webView || _readerPDFViewController)
  651. [self removeAllView];
  652. // if a message for a directory of these
  653. if (![_dataSourceDirectoryID containsObject:metadataNet.directoryID])
  654. return;
  655. // if we are not in browserPhoto and it's removed photo/video in preview then "< Back"
  656. if (!self.photoBrowser && [self.metadataDetail.fileID isEqualToString:metadataNet.fileID]) {
  657. NSArray *viewsToRemove = [self.view subviews];
  658. for (id element in viewsToRemove) {
  659. if ([element isMemberOfClass:[UIView class]] || [element isMemberOfClass:[UIToolbar class]])
  660. [element removeFromSuperview];
  661. }
  662. self.title = @"";
  663. [self.navigationController popViewControllerAnimated:YES];
  664. } else {
  665. // only photoBrowser if exists
  666. for (NSUInteger index=0; index < [self.dataSourceImagesVideos count] && _photoBrowser; index++ ) {
  667. tableMetadata *metadata = [self.dataSourceImagesVideos objectAtIndex:index];
  668. // ricerca index
  669. if ([metadata.fileID isEqualToString:metadataNet.fileID]) {
  670. [self.dataSourceImagesVideos removeObjectAtIndex:index];
  671. [self.photos removeObjectAtIndex:index];
  672. [self.photoBrowser reloadData];
  673. // Title
  674. if ([self.dataSourceImagesVideos count] == 0) {
  675. self.title = @"";
  676. [self.navigationController popViewControllerAnimated:YES];
  677. }
  678. break;
  679. }
  680. }
  681. }
  682. } else {
  683. NSLog(@"[LOG] DeleteFileOrFolder failure error %d, %@", (int)errorCode, message);
  684. }
  685. }
  686. #pragma --------------------------------------------------------------------------------------------
  687. #pragma mark ===== ButtonPressed =====
  688. #pragma --------------------------------------------------------------------------------------------
  689. - (void)modifyTxtButtonPressed:(UIBarButtonItem *)sender
  690. {
  691. UINavigationController* navigationController = [[UIStoryboard storyboardWithName:@"NCText" bundle:nil] instantiateViewControllerWithIdentifier:@"NCText"];
  692. NCText *viewController = (NCText *)navigationController.topViewController;
  693. viewController.metadata = self.metadataDetail;
  694. navigationController.modalPresentationStyle = UIModalPresentationPageSheet;
  695. navigationController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
  696. [self presentViewController:navigationController animated:YES completion:nil];
  697. }
  698. - (void)actionButtonPressed:(UIBarButtonItem *)sender
  699. {
  700. if ([self.metadataDetail.fileNameView length] == 0) return;
  701. NSString *filePath = [NSString stringWithFormat:@"%@%@", NSTemporaryDirectory(), self.metadataDetail.fileNameView];
  702. self.docController = [UIDocumentInteractionController interactionControllerWithURL:[NSURL fileURLWithPath:filePath]];
  703. self.docController.delegate = self;
  704. if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
  705. [self.docController presentOptionsMenuFromRect:self.view.frame inView:self.view animated:YES];
  706. [self.docController presentOptionsMenuFromBarButtonItem:sender animated:YES];
  707. }
  708. - (void)shareButtonPressed:(UIBarButtonItem *)sender
  709. {
  710. [appDelegate.activeMain openWindowShare:self.metadataDetail];
  711. }
  712. - (void)deleteButtonPressed:(UIBarButtonItem *)sender
  713. {
  714. if ([self.metadataDetail.fileNameView length] == 0) return;
  715. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
  716. [alertController addAction: [UIAlertAction actionWithTitle:NSLocalizedString(@"_delete_", nil)
  717. style:UIAlertActionStyleDestructive
  718. handler:^(UIAlertAction *action) {
  719. [[CCActions sharedInstance] deleteFileOrFolder:self.metadataDetail delegate:self hud:nil hudTitled:nil];
  720. }]];
  721. [alertController addAction: [UIAlertAction actionWithTitle:NSLocalizedString(@"_cancel_", nil)
  722. style:UIAlertActionStyleCancel
  723. handler:^(UIAlertAction *action) {
  724. [alertController dismissViewControllerAnimated:YES completion:nil];
  725. }]];
  726. alertController.popoverPresentationController.barButtonItem = _buttonDelete;
  727. if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
  728. [alertController.view layoutIfNeeded];
  729. [self presentViewController:alertController animated:YES completion:NULL];
  730. }
  731. @end