CCDetail.m 45 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017
  1. //
  2. // CCDetail.m
  3. // Nextcloud iOS
  4. //
  5. // Created by Marino Faggiana on 16/01/15.
  6. // Copyright (c) 2017 Marino Faggiana. All rights reserved.
  7. //
  8. // Author Marino Faggiana <marino.faggiana@nextcloud.com>
  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. #import <KTVHTTPCache/KTVHTTPCache.h>
  29. #import "NCBridgeSwift.h"
  30. #define TOOLBAR_HEIGHT 49.0f
  31. #define alertRequestPasswordPDF 1
  32. @interface CCDetail () <NCTextDelegate, UIDocumentInteractionControllerDelegate>
  33. {
  34. AppDelegate *appDelegate;
  35. UIDocumentInteractionController *docController;
  36. UIBarButtonItem *buttonModifyTxt;
  37. UIBarButtonItem *buttonShare;
  38. UIBarButtonItem *buttonDelete;
  39. NSInteger indexNowVisible;
  40. NSString *fileIDNowVisible;
  41. NSString *fileNameExtension;
  42. }
  43. @end
  44. @implementation CCDetail
  45. #pragma --------------------------------------------------------------------------------------------
  46. #pragma mark ===== init =====
  47. #pragma --------------------------------------------------------------------------------------------
  48. - (id)initWithCoder:(NSCoder *)aDecoder
  49. {
  50. if (self = [super initWithCoder:aDecoder]) {
  51. appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  52. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(changeTheming) name:@"changeTheming" object:nil];
  53. self.metadataDetail = [[tableMetadata alloc] init];
  54. self.photos = [[NSMutableArray alloc] init];
  55. self.photoDataSource = [NSMutableArray new];
  56. indexNowVisible = -1;
  57. fileIDNowVisible = nil;
  58. appDelegate.activeDetail = self;
  59. }
  60. return self;
  61. }
  62. #pragma --------------------------------------------------------------------------------------------
  63. #pragma mark ===== View =====
  64. #pragma --------------------------------------------------------------------------------------------
  65. - (void)viewDidLoad
  66. {
  67. [super viewDidLoad];
  68. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(insertGeocoderLocation:) name:@"insertGeocoderLocation" object:nil];
  69. self.imageBackground.image = [CCGraphics changeThemingColorImage:[UIImage imageNamed:@"logo"] multiplier:2 color:[[[NCBrandColor sharedInstance] brand] colorWithAlphaComponent:0.4]];
  70. // Change bar bottom line shadow and remove title back button <"title"
  71. self.navigationController.navigationBar.shadowImage = [CCGraphics generateSinglePixelImageWithColor:[NCBrandColor sharedInstance].brand];
  72. self.navigationController.navigationBar.topItem.title = @"";
  73. // Color Navigation Controller
  74. [appDelegate aspectNavigationControllerBar:self.navigationController.navigationBar online:[appDelegate.reachability isReachable] hidden:NO];
  75. // TabBar
  76. self.tabBarController.tabBar.hidden = YES;
  77. self.tabBarController.tabBar.translucent = YES;
  78. }
  79. - (void)viewWillAppear:(BOOL)animated
  80. {
  81. [super viewWillAppear:animated];
  82. self.tabBarController.tabBar.hidden = YES;
  83. self.tabBarController.tabBar.translucent = YES;
  84. // Open View
  85. if ([self.metadataDetail.fileNameView length] > 0 || [self.metadataDetail.serverUrl length] > 0 || [self.metadataDetail.fileID length] > 0) {
  86. // open view
  87. [self viewFile];
  88. }
  89. }
  90. - (void)viewWillDisappear:(BOOL)animated
  91. {
  92. [super viewWillDisappear:animated];
  93. [self.navigationController setNavigationBarHidden:false];
  94. }
  95. - (void)viewDidDisappear:(BOOL)animated
  96. {
  97. [super viewDidDisappear:animated];
  98. // If AVPlayer in play -> Stop
  99. if (appDelegate.player != nil && appDelegate.player.rate != 0) {
  100. [appDelegate.player pause];
  101. }
  102. // remove Observer AVPlayer
  103. if (self.isMediaObserver) {
  104. self.isMediaObserver = NO;
  105. @try{
  106. [[NCViewerMedia sharedInstance] removeObserver];
  107. }@catch(id anException) { }
  108. }
  109. }
  110. - (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator
  111. {
  112. [super viewWillTransitionToSize:size withTransitionCoordinator:coordinator];
  113. [coordinator animateAlongsideTransition:nil completion:^(id<UIViewControllerTransitionCoordinatorContext> context) {
  114. if (self.imagemeter) {
  115. [self.imagemeter viewImagemeter];
  116. }
  117. }];
  118. }
  119. - (void)changeTheming
  120. {
  121. [appDelegate changeTheming:self];
  122. if (self.toolbar) {
  123. self.toolbar.barTintColor = [NCBrandColor sharedInstance].tabBar;
  124. self.toolbar.tintColor = [NCBrandColor sharedInstance].brandElement;
  125. }
  126. }
  127. - (void)changeToDisplayMode
  128. {
  129. if (_readerPDFViewController) {
  130. [self.readerPDFViewController updateContentViews];
  131. }
  132. if (self.imagemeter) {
  133. [self.imagemeter viewImagemeter];
  134. }
  135. }
  136. #pragma --------------------------------------------------------------------------------------------
  137. #pragma mark ===== View File =====
  138. #pragma --------------------------------------------------------------------------------------------
  139. - (void)viewFile
  140. {
  141. // Remove all subview except ..
  142. //for (UIView *view in self.view.superview.subviews) {
  143. // NSInteger tag = view.tag;
  144. //}
  145. // Title
  146. self.navigationController.navigationBar.topItem.title = _metadataDetail.fileNameView;
  147. // verifico se esiste l'icona e se la posso creare
  148. if ([[NSFileManager defaultManager] fileExistsAtPath:[CCUtility getDirectoryProviderStorageIconFileID:self.metadataDetail.fileID fileNameView:self.metadataDetail.fileNameView]] == NO) {
  149. [CCGraphics createNewImageFrom:self.metadataDetail.fileNameView fileID:self.metadataDetail.fileID extension:[self.metadataDetail.fileNameView pathExtension] filterGrayScale:NO typeFile:self.metadataDetail.typeFile writeImage:YES];
  150. }
  151. // remove Observer AVPlayer
  152. if (self.isMediaObserver) {
  153. self.isMediaObserver = NO;
  154. [[NCViewerMedia sharedInstance] removeObserver];
  155. }
  156. // IMAGE
  157. if ([self.metadataDetail.typeFile isEqualToString: k_metadataTypeFile_image]) {
  158. self.edgesForExtendedLayout = UIRectEdgeAll;
  159. [self viewImage];
  160. }
  161. // AUDIO VIDEO
  162. if ([self.metadataDetail.typeFile isEqualToString: k_metadataTypeFile_video] || [self.metadataDetail.typeFile isEqualToString: k_metadataTypeFile_audio]) {
  163. self.edgesForExtendedLayout = UIRectEdgeAll;
  164. [self createToolbar];
  165. [[NCViewerMedia sharedInstance] viewMedia:self.metadataDetail detail:self];
  166. }
  167. // DOCUMENT
  168. if ([self.metadataDetail.typeFile isEqualToString: k_metadataTypeFile_document]) {
  169. fileNameExtension = [[self.metadataDetail.fileNameView pathExtension] uppercaseString];
  170. if ([fileNameExtension isEqualToString:@"PDF"]) {
  171. self.edgesForExtendedLayout = UIRectEdgeBottom;
  172. [self createToolbar];
  173. [self viewPDF:@""];
  174. return;
  175. }
  176. // RichDocument
  177. if ([[NCViewerRichdocument sharedInstance] isRichDocument:self.metadataDetail]) {
  178. [[NCUtility sharedInstance] startActivityIndicatorWithView:self.view bottom:0];
  179. if ([self.metadataDetail.url isEqualToString:@""]) {
  180. [[OCNetworking sharedManager] createLinkRichdocumentsWithAccount:appDelegate.activeAccount fileID:self.metadataDetail.fileID completion:^(NSString *account, NSString *link, NSString *message, NSInteger errorCode) {
  181. if (errorCode == 0 && [account isEqualToString:appDelegate.activeAccount]) {
  182. [[NCViewerRichdocument sharedInstance] viewRichDocumentAt:link detail:self];
  183. } else {
  184. [[NCUtility sharedInstance] stopActivityIndicator];
  185. if (errorCode != 0) {
  186. [appDelegate messageNotification:@"_error_" description:message visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode:errorCode];
  187. } else {
  188. NSLog(@"[LOG] It has been changed user during networking process, error.");
  189. }
  190. [self.navigationController popViewControllerAnimated:YES];
  191. }
  192. }];
  193. } else {
  194. [[NCViewerRichdocument sharedInstance] viewRichDocumentAt:self.metadataDetail.url detail:self];
  195. }
  196. return;
  197. }
  198. self.edgesForExtendedLayout = UIRectEdgeBottom;
  199. [self createToolbar];
  200. [[NCViewerDocumentWeb sharedInstance] viewDocumentWebAt:self.metadataDetail detail:self];
  201. }
  202. // IMI File
  203. if ([self.metadataDetail.typeFile isEqualToString: k_metadataTypeFile_imagemeter]) {
  204. self.imagemeter = [[NCViewerImagemeter alloc] initWithMetadata:self.metadataDetail detail:self];
  205. [self.imagemeter viewImagemeter];
  206. [self createToolbar];
  207. }
  208. }
  209. #pragma --------------------------------------------------------------------------------------------
  210. #pragma mark ===== Toolbar =====
  211. #pragma --------------------------------------------------------------------------------------------
  212. - (void)createToolbar
  213. {
  214. CGFloat safeAreaBottom = 0;
  215. if (@available(iOS 11, *)) {
  216. safeAreaBottom = [UIApplication sharedApplication].delegate.window.safeAreaInsets.bottom;
  217. }
  218. self.toolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, self.view.bounds.size.height - TOOLBAR_HEIGHT - safeAreaBottom, self.view.bounds.size.width, TOOLBAR_HEIGHT)];
  219. UIBarButtonItem *flexible = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:self action:nil];
  220. UIBarButtonItem *fixedSpaceMini = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:self action:nil];
  221. fixedSpaceMini.width = 25;
  222. buttonModifyTxt = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"actionSheetModify"] style:UIBarButtonItemStylePlain target:self action:@selector(modifyTxtButtonPressed:)];
  223. if (![NCBrandOptions sharedInstance].disable_openin_file) {
  224. self.buttonAction = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"openFile"] style:UIBarButtonItemStylePlain target:self action:@selector(actionButtonPressed:)];
  225. }
  226. buttonShare = [[UIBarButtonItem alloc] initWithImage:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"share"] width:50 height:50 color:[NCBrandColor sharedInstance].icon] style:UIBarButtonItemStylePlain target:self action:@selector(shareButtonPressed:)];
  227. buttonDelete = [[UIBarButtonItem alloc] initWithImage:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"trash"] width:50 height:50 color:[NCBrandColor sharedInstance].icon] style:UIBarButtonItemStylePlain target:self action:@selector(deleteButtonPressed:)];
  228. if ([CCUtility isDocumentModifiableExtension:fileNameExtension]) {
  229. if ([CCUtility isFolderEncrypted:_metadataDetail.serverUrl account:appDelegate.activeAccount]) // E2EE
  230. [self.toolbar setItems:[NSArray arrayWithObjects: buttonModifyTxt, flexible, buttonDelete, fixedSpaceMini, self.buttonAction, nil]];
  231. else
  232. [self.toolbar setItems:[NSArray arrayWithObjects: buttonModifyTxt, flexible, buttonDelete, fixedSpaceMini, buttonShare, fixedSpaceMini, self.buttonAction, nil]];
  233. } else {
  234. if ([CCUtility isFolderEncrypted:_metadataDetail.serverUrl account:appDelegate.activeAccount]) // E2EE
  235. [self.toolbar setItems:[NSArray arrayWithObjects: flexible, buttonDelete, fixedSpaceMini, self.buttonAction, nil]];
  236. else
  237. [self.toolbar setItems:[NSArray arrayWithObjects: flexible, buttonDelete, fixedSpaceMini, buttonShare, fixedSpaceMini, self.buttonAction, nil]];
  238. }
  239. [self.toolbar setAutoresizingMask:UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleTopMargin];
  240. self.toolbar.barTintColor = [NCBrandColor sharedInstance].tabBar;
  241. self.toolbar.tintColor = [NCBrandColor sharedInstance].brandElement;
  242. [self.view addSubview:self.toolbar];
  243. }
  244. #pragma --------------------------------------------------------------------------------------------
  245. #pragma mark ===== View Image =====
  246. #pragma --------------------------------------------------------------------------------------------
  247. - (void)viewImage
  248. {
  249. self.photoBrowser = [[MWPhotoBrowser alloc] initWithDelegate:self];
  250. indexNowVisible = -1;
  251. fileIDNowVisible = nil;
  252. [self.photos removeAllObjects];
  253. // if not images, exit
  254. if ([self.photoDataSource count] == 0)
  255. return;
  256. NSUInteger index = 0;
  257. for (tableMetadata *metadata in self.photoDataSource) {
  258. // start from here ?
  259. if (self.metadataDetail.fileID && [metadata.fileID isEqualToString:self.metadataDetail.fileID])
  260. [self.photoBrowser setCurrentPhotoIndex:index];
  261. [self.photos addObject:[MWPhoto photoWithImage:nil]];
  262. // add directory
  263. index++;
  264. }
  265. // PhotoBrowser
  266. if ([NCBrandOptions sharedInstance].disable_openin_file) {
  267. self.photoBrowser.displayActionButton = NO;
  268. } else {
  269. self.photoBrowser.displayActionButton = YES;
  270. }
  271. self.photoBrowser.displayDeleteButton = YES;
  272. if ([CCUtility isFolderEncrypted:_metadataDetail.serverUrl account:appDelegate.activeAccount]) // E2EE
  273. self.photoBrowser.displayShareButton = NO;
  274. else
  275. self.photoBrowser.displayShareButton = YES;
  276. self.photoBrowser.displayNavArrows = YES;
  277. self.photoBrowser.displaySelectionButtons = NO;
  278. self.photoBrowser.alwaysShowControls = NO;
  279. self.photoBrowser.zoomPhotosToFill = NO;
  280. self.photoBrowser.autoPlayOnAppear = NO;
  281. self.photoBrowser.delayToHideElements = 15;
  282. if ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPad)
  283. self.photoBrowser.enableSwipeToDismiss = NO;
  284. if (self.traitCollection.horizontalSizeClass == UIUserInterfaceSizeClassCompact) {
  285. [self addChildViewController:self.photoBrowser];
  286. [self.view addSubview:self.photoBrowser.view];
  287. [self.photoBrowser didMoveToParentViewController:self];
  288. } else {
  289. [self.navigationController pushViewController:self.photoBrowser animated:NO];
  290. }
  291. }
  292. - (NSUInteger)numberOfPhotosInPhotoBrowser:(MWPhotoBrowser *)photoBrowser
  293. {
  294. return [self.photoDataSource count];
  295. }
  296. - (NSString *)photoBrowser:(MWPhotoBrowser *)photoBrowser titleForPhotoAtIndex:(NSUInteger)index
  297. {
  298. tableMetadata *metadata = [self.photoDataSource objectAtIndex:index];
  299. NSString *titleDir = metadata.fileNameView;
  300. self.title = titleDir;
  301. return titleDir;
  302. }
  303. - (void)photoBrowser:(MWPhotoBrowser *)photoBrowser didDisplayPhotoAtIndex:(NSUInteger)index
  304. {
  305. tableMetadata *metadata = [self.photoDataSource objectAtIndex:index];
  306. indexNowVisible = index;
  307. fileIDNowVisible = metadata.fileID;
  308. photoBrowser.toolbar.hidden = NO;
  309. // Download image ?
  310. if (metadata) {
  311. NSInteger status;
  312. tableMetadata *metadataDB = [[NCManageDatabase sharedInstance] getMetadataWithPredicate:[NSPredicate predicateWithFormat:@"fileID == %@", metadata.fileID]];
  313. if (metadataDB) {
  314. status = metadataDB.status;
  315. } else {
  316. status = k_metadataStatusNormal;
  317. }
  318. if ([CCUtility fileProviderStorageExists:metadata.fileID fileNameView:metadata.fileNameView] == NO && status == k_metadataStatusNormal) {
  319. if ([[NSFileManager defaultManager] fileExistsAtPath:[CCUtility getDirectoryProviderStorageIconFileID:metadata.fileID fileNameView:metadata.fileNameView]] == NO && metadata.hasPreview) {
  320. [CCGraphics addImageToTitle:NSLocalizedString(@"_...loading..._", nil) colorTitle:[NCBrandColor sharedInstance].brandText imageTitle:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"load"] multiplier:2 color:[NCBrandColor sharedInstance].brandText] imageRight:NO navigationItem:self.navigationItem];
  321. CGFloat width = [[NCUtility sharedInstance] getScreenWidthForPreview];
  322. CGFloat height = [[NCUtility sharedInstance] getScreenHeightForPreview];
  323. [[OCNetworking sharedManager] downloadPreviewWithAccount:appDelegate.activeAccount metadata:metadata withWidth:width andHeight:height completion:^(NSString *account, UIImage *image, NSString *message, NSInteger errorCode) {
  324. self.navigationItem.titleView = nil;
  325. self.title = metadata.fileNameView;
  326. if (errorCode == 0 && [account isEqualToString:appDelegate.activeAccount]) {
  327. [self.photoBrowser reloadData];
  328. }
  329. }];
  330. } else {
  331. [self downloadPhotoBrowser:metadata];
  332. }
  333. }
  334. }
  335. // Title
  336. if (metadata)
  337. self.title = metadata.fileNameView;
  338. }
  339. - (id <MWPhoto>)photoBrowser:(MWPhotoBrowser *)photoBrowser photoAtIndex:(NSUInteger)index
  340. {
  341. UIImage *image;
  342. tableMetadata *metadata = [self.photoDataSource objectAtIndex:index];
  343. if (index < self.photos.count) {
  344. if (metadata.fileID) {
  345. UIImage *imagePreview = [UIImage imageWithContentsOfFile:[CCUtility getDirectoryProviderStorageIconFileID:metadata.fileID fileNameView:metadata.fileNameView]];
  346. // if (!imagePreview) imagePreview = [CCGraphics changeThemingColorImage:[UIImage imageNamed:@"file_photo"] multiplier:3 color:[[NCBrandColor sharedInstance] icon]];
  347. if ([metadata.typeFile isEqualToString: k_metadataTypeFile_image]) {
  348. NSString *fileImage = [CCUtility getDirectoryProviderStorageFileID:metadata.fileID fileNameView:metadata.fileNameView];
  349. NSString *ext = [CCUtility getExtension:metadata.fileNameView];
  350. if ([ext isEqualToString:@"GIF"]) image = [UIImage animatedImageWithAnimatedGIFURL:[NSURL fileURLWithPath:fileImage]];
  351. else image = [UIImage imageWithContentsOfFile:fileImage];
  352. if (image) {
  353. MWPhoto *photo = [MWPhoto photoWithImage:image];
  354. // Location ??
  355. [self setLocationCaptionPhoto:photo fileID:metadata.fileID];
  356. [self.photos replaceObjectAtIndex:index withObject:photo];
  357. } else {
  358. if (metadata.status == k_metadataStatusDownloadError) {
  359. [self.photos replaceObjectAtIndex:index withObject:[MWPhoto photoWithImage:[UIImage imageNamed:@"filePreviewError"]]];
  360. } else {
  361. if (imagePreview)
  362. [self.photos replaceObjectAtIndex:index withObject:[MWPhoto photoWithImage:imagePreview]];
  363. }
  364. }
  365. }
  366. if ([metadata.typeFile isEqualToString: k_metadataTypeFile_video]) {
  367. if ([CCUtility fileProviderStorageExists:metadata.fileID fileNameView:metadata.fileNameView]) {
  368. NSURL *url = [NSURL fileURLWithPath:[CCUtility getDirectoryProviderStorageFileID:metadata.fileID fileNameView:metadata.fileNameView]];
  369. MWPhoto *video = [MWPhoto photoWithImage:[CCGraphics thumbnailImageForVideo:url atTime:1.0]];
  370. video.videoURL = url;
  371. [self.photos replaceObjectAtIndex:index withObject:video];
  372. } else {
  373. if (metadata.status == k_metadataStatusDownloadError) {
  374. [self.photos replaceObjectAtIndex:index withObject:[MWPhoto photoWithImage:[UIImage imageNamed:@"filePreviewError"]]];
  375. } else {
  376. if (imagePreview)
  377. [self.photos replaceObjectAtIndex:index withObject:[MWPhoto photoWithImage:imagePreview]];
  378. }
  379. }
  380. }
  381. if ([metadata.typeFile isEqualToString: k_metadataTypeFile_audio]) {
  382. if ([CCUtility fileProviderStorageExists:metadata.fileID fileNameView:metadata.fileNameView]) {
  383. MWPhoto *audio;
  384. UIImage *audioImage;
  385. NSURL *url = [NSURL fileURLWithPath:[CCUtility getDirectoryProviderStorageFileID:metadata.fileID fileNameView:metadata.fileNameView]];
  386. if ([[NSFileManager defaultManager] fileExistsAtPath:[CCUtility getDirectoryProviderStorageIconFileID:metadata.fileID fileNameView:metadata.fileNameView]]) {
  387. audioImage = [UIImage imageWithContentsOfFile:[CCUtility getDirectoryProviderStorageIconFileID:metadata.fileID fileNameView:metadata.fileNameView]];
  388. } else {
  389. audioImage = [UIImage imageNamed:@"notaMusic"]; //[CCGraphics scaleImage:[UIImage imageNamed:@"notaMusic"] toSize:CGSizeMake(200, 200) isAspectRation:YES];
  390. }
  391. audio = [MWPhoto photoWithImage:audioImage];
  392. audio.videoURL = url;
  393. [self.photos replaceObjectAtIndex:index withObject:audio];
  394. } else {
  395. if (metadata.status == k_metadataStatusDownloadError) {
  396. [self.photos replaceObjectAtIndex:index withObject:[MWPhoto photoWithImage:[UIImage imageNamed:@"filePreviewError"]]];
  397. } else {
  398. if (imagePreview)
  399. [self.photos replaceObjectAtIndex:index withObject:[MWPhoto photoWithImage:imagePreview]];
  400. }
  401. }
  402. }
  403. }
  404. // energy saving memory
  405. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  406. int iPrev = (int)index - 2;
  407. if (iPrev >= 0) {
  408. if ([self.photos objectAtIndex:iPrev] != nil)
  409. [self.photos replaceObjectAtIndex:iPrev withObject:[MWPhoto photoWithImage:nil]];
  410. }
  411. int iNext = (int)index + 2;
  412. if (iNext < _photos.count) {
  413. if ([self.photos objectAtIndex:iNext] != nil)
  414. [self.photos replaceObjectAtIndex:iNext withObject:[MWPhoto photoWithImage:nil]];
  415. }
  416. });
  417. return [self.photos objectAtIndex:index];
  418. }
  419. return nil;
  420. }
  421. - (void)photoBrowser:(MWPhotoBrowser *)photoBrowser actionButtonPressedForPhotoAtIndex:(NSUInteger)index
  422. {
  423. tableMetadata *metadata = [self.photoDataSource objectAtIndex:index];
  424. if (metadata == nil) return;
  425. docController = [UIDocumentInteractionController interactionControllerWithURL:[NSURL fileURLWithPath:[CCUtility getDirectoryProviderStorageFileID:metadata.fileID fileNameView:metadata.fileNameView]]];
  426. docController.delegate = self;
  427. if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
  428. [docController presentOptionsMenuFromRect:photoBrowser.view.frame inView:photoBrowser.view animated:YES];
  429. [docController presentOptionsMenuFromBarButtonItem:photoBrowser.actionButton animated:YES];
  430. }
  431. - (void)photoBrowser:(MWPhotoBrowser *)photoBrowser shareButtonPressedForPhotoAtIndex:(NSUInteger)index
  432. {
  433. tableMetadata *metadata = [self.photoDataSource objectAtIndex:index];
  434. [appDelegate.activeMain readShareWithAccount:appDelegate.activeAccount openWindow:YES metadata:metadata];
  435. }
  436. - (void)photoBrowser:(MWPhotoBrowser *)photoBrowser deleteButtonPressedForPhotoAtIndex:(NSUInteger)index deleteButton:(UIBarButtonItem *)deleteButton
  437. {
  438. tableMetadata *metadata = [self.photoDataSource objectAtIndex:index];
  439. if (metadata == nil || [CCUtility fileProviderStorageExists:metadata.fileID fileNameView:metadata.fileNameView] == NO) {
  440. [appDelegate messageNotification:@"_info_" description:@"_file_not_found_" visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeInfo errorCode:0];
  441. return;
  442. }
  443. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
  444. [alertController addAction: [UIAlertAction actionWithTitle:NSLocalizedString(@"_delete_", nil)
  445. style:UIAlertActionStyleDestructive
  446. handler:^(UIAlertAction *action) {
  447. [self deleteFile:metadata];
  448. }]];
  449. [alertController addAction: [UIAlertAction actionWithTitle:NSLocalizedString(@"_cancel_", nil)
  450. style:UIAlertActionStyleCancel
  451. handler:^(UIAlertAction *action) {
  452. }]];
  453. alertController.popoverPresentationController.barButtonItem = deleteButton;
  454. if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
  455. [alertController.view layoutIfNeeded];
  456. [self.parentViewController presentViewController:alertController animated:YES completion:NULL];
  457. }
  458. - (void)photoBrowserDidFinishPresentation:(MWPhotoBrowser *)photoBrowser
  459. {
  460. [self.navigationController popViewControllerAnimated:YES];
  461. }
  462. - (void)downloadPhotoBrowserSuccessFailure:(tableMetadata *)metadata selector:(NSString *)selector errorCode:(NSInteger)errorCode
  463. {
  464. // if a message for a directory of these
  465. if (![metadata.fileID isEqualToString:fileIDNowVisible])
  466. return;
  467. // Title
  468. self.navigationItem.titleView = nil;
  469. self.title = metadata.fileNameView;
  470. if (errorCode == 0) {
  471. // verifico se esiste l'icona e se la posso creare
  472. if ([[NSFileManager defaultManager] fileExistsAtPath:[CCUtility getDirectoryProviderStorageIconFileID:metadata.fileID fileNameView:metadata.fileNameView]] == NO) {
  473. [CCGraphics createNewImageFrom:metadata.fileNameView fileID:metadata.fileID extension:[metadata.fileNameView pathExtension] filterGrayScale:NO typeFile:metadata.typeFile writeImage:YES];
  474. }
  475. [self.photoBrowser reloadData];
  476. } else {
  477. [appDelegate messageNotification:@"_download_selected_files_" description:@"_error_download_photobrowser_" visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode:errorCode];
  478. [self.navigationController popViewControllerAnimated:YES];
  479. }
  480. }
  481. - (void)downloadPhotoBrowser:(tableMetadata *)metadata
  482. {
  483. tableMetadata *metadataForDownload = [[NCManageDatabase sharedInstance] initNewMetadata:metadata];
  484. metadataForDownload.session = k_download_session;
  485. metadataForDownload.sessionError = @"";
  486. metadataForDownload.sessionSelector = selectorLoadViewImage;
  487. metadataForDownload.status = k_metadataStatusWaitDownload;
  488. // Add Metadata for Download
  489. (void)[[NCManageDatabase sharedInstance] addMetadata:metadataForDownload];
  490. [[NCMainCommon sharedInstance] reloadDatasourceWithServerUrl:metadata.serverUrl fileID:metadataForDownload.fileID action:k_action_MOD];
  491. [appDelegate startLoadAutoDownloadUpload];
  492. [CCGraphics addImageToTitle:NSLocalizedString(@"_...loading..._", nil) colorTitle:[NCBrandColor sharedInstance].brandText imageTitle:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"load"] multiplier:2 color:[NCBrandColor sharedInstance].brandText] imageRight:NO navigationItem:self.navigationItem];
  493. }
  494. - (void)insertGeocoderLocation:(NSNotification *)notification
  495. {
  496. if (notification.userInfo.count == 0)
  497. return;
  498. NSString *fileID = [[notification.userInfo allKeys] objectAtIndex:0];
  499. //NSDate *date = [[notification.userInfo allValues] objectAtIndex:0];
  500. // test [Chrash V 1.14,15]
  501. if (indexNowVisible >= [self.photos count])
  502. return;
  503. if ([fileID isEqualToString:fileIDNowVisible]) {
  504. MWPhoto *photo = [self.photos objectAtIndex:indexNowVisible];
  505. [self setLocationCaptionPhoto:photo fileID:fileID];
  506. [self.photoBrowser reloadData];
  507. }
  508. }
  509. - (void)setLocationCaptionPhoto:(MWPhoto *)photo fileID:(NSString *)fileID
  510. {
  511. tableLocalFile *localFile;
  512. // read Geocoder
  513. localFile = [[NCManageDatabase sharedInstance] getTableLocalFileWithPredicate:[NSPredicate predicateWithFormat:@"fileID == %@", fileID]];
  514. if ([localFile.exifLatitude doubleValue] != 0 || [localFile.exifLongitude doubleValue] != 0) {
  515. // Fix BUG Geo latitude & longitude
  516. if ([localFile.exifLatitude doubleValue] == 9999 || [localFile.exifLongitude doubleValue] == 9999) {
  517. tableMetadata *metadata = [[NCManageDatabase sharedInstance] getMetadataWithPredicate:[NSPredicate predicateWithFormat:@"fileID == %@", fileID]];
  518. if (metadata) {
  519. [[CCExifGeo sharedInstance] setExifLocalTableEtag:metadata];
  520. }
  521. }
  522. [[CCExifGeo sharedInstance] setGeocoderEtag:fileID exifDate:localFile.exifDate latitude:localFile.exifLatitude longitude:localFile.exifLongitude];
  523. localFile = [[NCManageDatabase sharedInstance] getTableLocalFileWithPredicate:[NSPredicate predicateWithFormat:@"fileID == %@", fileID]];
  524. if ([localFile.exifLatitude floatValue] != 0 || [localFile.exifLongitude floatValue] != 0) {
  525. NSString *location = [[NCManageDatabase sharedInstance] getLocationFromGeoLatitude:localFile.exifLatitude longitude:localFile.exifLongitude];
  526. if ([localFile.exifDate isEqualToDate:[NSDate distantPast]] == NO && location) {
  527. NSString *localizedDateTime = [NSDateFormatter localizedStringFromDate:localFile.exifDate dateStyle:NSDateFormatterFullStyle timeStyle:NSDateFormatterMediumStyle];
  528. photo.caption = [NSString stringWithFormat:NSLocalizedString(@"%@\n%@", nil), localizedDateTime, location];
  529. }
  530. }
  531. }
  532. }
  533. #pragma --------------------------------------------------------------------------------------------
  534. #pragma mark ===== View PDF =====
  535. #pragma --------------------------------------------------------------------------------------------
  536. - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
  537. {
  538. [alertView dismissWithClickedButtonIndex:buttonIndex animated:YES];
  539. [[alertView textFieldAtIndex:0] resignFirstResponder];
  540. if (alertView.tag == alertRequestPasswordPDF) [self performSelector:@selector(viewPDF:) withObject:[alertView textFieldAtIndex:0].text afterDelay:0.3];
  541. }
  542. - (void)viewPDF:(NSString *)password
  543. {
  544. // remove cache PDF
  545. NSString *filePlistReader = [NSString stringWithFormat:@"%@/%@.plist", [CCUtility getDirectoryReaderMetadata], self.metadataDetail.fileNameView.stringByDeletingPathExtension];
  546. [CCUtility removeFileAtPath:filePlistReader];
  547. NSString *fileNamePath = [CCUtility getDirectoryProviderStorageFileID:self.metadataDetail.fileID fileNameView:self.metadataDetail.fileNameView];
  548. if ([CCUtility fileProviderStorageExists:self.metadataDetail.fileID fileNameView:self.metadataDetail.fileNameView] == NO) {
  549. // read file error
  550. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"_error_", nil) message:NSLocalizedString(@"_read_file_error_", nil) preferredStyle:UIAlertControllerStyleAlert];
  551. UIAlertAction *okAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"_ok_", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {}];
  552. [alertController addAction:okAction];
  553. [self presentViewController:alertController animated:YES completion:nil];
  554. }
  555. CGPDFDocumentRef pdf = CGPDFDocumentCreateWithURL((CFURLRef)[NSURL fileURLWithPath:fileNamePath]);
  556. if (pdf) {
  557. // Encrypted
  558. if (CGPDFDocumentIsEncrypted(pdf) == YES) {
  559. // Try a blank password first, per Apple's Quartz PDF example
  560. if (CGPDFDocumentUnlockWithPassword(pdf, "") == YES) {
  561. // blank password
  562. [self readerPDF:fileNamePath password:@""];
  563. } else {
  564. if ([password length] == 0) {
  565. // password request
  566. UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"_insert_password_pfd_",nil) message:nil delegate:self cancelButtonTitle:nil otherButtonTitles:NSLocalizedString(@"_ok_", nil), nil];
  567. [alertView setAlertViewStyle:UIAlertViewStylePlainTextInput];
  568. alertView.tag = alertRequestPasswordPDF;
  569. [alertView show];
  570. } else {
  571. const char *key = [password UTF8String];
  572. // failure
  573. if (CGPDFDocumentUnlockWithPassword(pdf, key) == NO) {
  574. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"_error_", nil) message:NSLocalizedString(@"_password_pdf_error_", nil) preferredStyle:UIAlertControllerStyleAlert];
  575. UIAlertAction *okAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"_ok_", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {}];
  576. [alertController addAction:okAction];
  577. [self presentViewController:alertController animated:YES completion:nil];
  578. } else {
  579. // pdf with password
  580. [self readerPDF:fileNamePath password:password];
  581. }
  582. }
  583. }
  584. } else{
  585. // No password
  586. [self readerPDF:fileNamePath password:@""];
  587. }
  588. } else {
  589. // read file error
  590. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"_error_", nil) message:NSLocalizedString(@"_read_file_error_", nil) preferredStyle:UIAlertControllerStyleAlert];
  591. UIAlertAction *okAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"_ok_", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {}];
  592. [alertController addAction:okAction];
  593. [self presentViewController:alertController animated:YES completion:nil];
  594. }
  595. }
  596. - (void)readerPDF:(NSString *)fileName password:(NSString *)password
  597. {
  598. ReaderDocument *documentPDF = [ReaderDocument withDocumentFilePath:fileName password:password];
  599. CGFloat safeAreaBottom = 0;
  600. if (@available(iOS 11, *)) {
  601. safeAreaBottom = [UIApplication sharedApplication].delegate.window.safeAreaInsets.bottom;
  602. }
  603. if (documentPDF != nil) {
  604. self.readerPDFViewController = [[ReaderViewController alloc] initWithReaderDocument:documentPDF];
  605. self.readerPDFViewController.delegate = self;
  606. self.readerPDFViewController.view.frame = CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height - TOOLBAR_HEIGHT - safeAreaBottom);
  607. [self.readerPDFViewController updateContentViews];
  608. [self addChildViewController:self.readerPDFViewController];
  609. [self.view addSubview:self.readerPDFViewController.view];
  610. [self.readerPDFViewController didMoveToParentViewController:self];
  611. } else {
  612. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"_error_", nil) message:NSLocalizedString(@"_read_file_error_", nil) preferredStyle:UIAlertControllerStyleAlert];
  613. UIAlertAction *okAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"_ok_", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {}];
  614. [alertController addAction:okAction];
  615. [self presentViewController:alertController animated:YES completion:nil];
  616. }
  617. }
  618. - (void)handleSingleTapReader
  619. {
  620. UILayoutGuide *layoutGuide;
  621. CGFloat safeAreaTop = 0;
  622. CGFloat safeAreaBottom = 0;
  623. if (@available(iOS 11, *)) {
  624. layoutGuide = [UIApplication sharedApplication].delegate.window.safeAreaLayoutGuide;
  625. safeAreaTop = [UIApplication sharedApplication].delegate.window.safeAreaInsets.top;
  626. safeAreaBottom = [UIApplication sharedApplication].delegate.window.safeAreaInsets.bottom;
  627. }
  628. self.navigationController.navigationBarHidden = !self.navigationController.navigationBarHidden;
  629. self.toolbar.hidden = !self.toolbar.isHidden;
  630. if (self.toolbar.isHidden) {
  631. self.readerPDFViewController.view.frame = CGRectMake(0, safeAreaTop, self.view.bounds.size.width, self.view.bounds.size.height - safeAreaTop - safeAreaBottom);
  632. } else {
  633. self.readerPDFViewController.view.frame = CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height - TOOLBAR_HEIGHT - safeAreaBottom);
  634. }
  635. [self.readerPDFViewController updateContentViews];
  636. }
  637. - (void)handleSwipeUpDown
  638. {
  639. // REMOVE IT'S UNUSABLE
  640. /*
  641. self.navigationController.navigationBarHidden = false; // iOS App is unusable after swipe up or down with PDF in fullscreen #526
  642. [self removeAllView];
  643. [self.navigationController popViewControllerAnimated:YES];
  644. */
  645. }
  646. #pragma --------------------------------------------------------------------------------------------
  647. #pragma mark ===== Delete =====
  648. #pragma --------------------------------------------------------------------------------------------
  649. - (void)deleteFile:(tableMetadata *)metadata
  650. {
  651. tableDirectory *tableDirectory = [[NCManageDatabase sharedInstance] getTableDirectoryWithPredicate:[NSPredicate predicateWithFormat:@"account == %@ AND e2eEncrypted == 1 AND serverUrl == %@", appDelegate.activeAccount, metadata.serverUrl]];
  652. [[NCMainCommon sharedInstance ] deleteFileWithMetadatas:[[NSArray alloc] initWithObjects:metadata, nil] e2ee:tableDirectory.e2eEncrypted serverUrl:tableDirectory.serverUrl folderFileID:tableDirectory.fileID completion:^(NSInteger errorCode, NSString *message) {
  653. if (errorCode == 0) {
  654. // reload data source
  655. [[NCMainCommon sharedInstance] reloadDatasourceWithServerUrl:tableDirectory.serverUrl fileID:metadata.fileID action:k_action_DEL];
  656. // Not image
  657. if ([self.metadataDetail.typeFile isEqualToString: k_metadataTypeFile_image] == NO) {
  658. // exit
  659. [self.navigationController popViewControllerAnimated:YES];
  660. } else {
  661. for (NSUInteger index=0; index < [self.photoDataSource count] && _photoBrowser; index++ ) {
  662. tableMetadata *metadataTemp = [self.photoDataSource objectAtIndex:index];
  663. if ([metadata isInvalidated] || [metadataTemp.fileID isEqualToString:metadata.fileID]) {
  664. [self.photoDataSource removeObjectAtIndex:index];
  665. [self.photos removeObjectAtIndex:index];
  666. [self.photoBrowser reloadData];
  667. // exit
  668. if ([self.photoDataSource count] == 0) {
  669. [self.navigationController popViewControllerAnimated:YES];
  670. }
  671. }
  672. }
  673. }
  674. } else {
  675. NSLog(@"[LOG] DeleteFileOrFolder failure error %d, %@", (int)errorCode, message);
  676. }
  677. }];
  678. }
  679. #pragma --------------------------------------------------------------------------------------------
  680. #pragma mark ===== ButtonPressed =====
  681. #pragma --------------------------------------------------------------------------------------------
  682. - (void)dismissTextView
  683. {
  684. if (self.webView) {
  685. NSString *fileNamePath = [NSTemporaryDirectory() stringByAppendingString:self.metadataDetail.fileNameView];
  686. [[NSFileManager defaultManager] removeItemAtPath:fileNamePath error:nil];
  687. [[NSFileManager defaultManager] linkItemAtPath:[CCUtility getDirectoryProviderStorageFileID:self.metadataDetail.fileID fileNameView:self.metadataDetail.fileNameView] toPath:fileNamePath error:nil];
  688. [self.webView reload];
  689. }
  690. }
  691. - (void)modifyTxtButtonPressed:(UIBarButtonItem *)sender
  692. {
  693. tableMetadata *metadata = [[NCManageDatabase sharedInstance] getMetadataWithPredicate:[NSPredicate predicateWithFormat:@"fileID == %@", self.metadataDetail.fileID]];
  694. if (metadata) {
  695. UINavigationController* navigationController = [[UIStoryboard storyboardWithName:@"NCText" bundle:nil] instantiateViewControllerWithIdentifier:@"NCText"];
  696. NCText *viewController = (NCText *)navigationController.topViewController;
  697. viewController.metadata = metadata;
  698. viewController.delegate = self;
  699. navigationController.modalPresentationStyle = UIModalPresentationPageSheet;
  700. navigationController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
  701. [self presentViewController:navigationController animated:YES completion:nil];
  702. }
  703. }
  704. - (void)actionButtonPressed:(UIBarButtonItem *)sender
  705. {
  706. if ([self.metadataDetail.fileNameView length] == 0) return;
  707. NSString *filePath = [CCUtility getDirectoryProviderStorageFileID:self.metadataDetail.fileID fileNameView:self.metadataDetail.fileNameView];
  708. docController = [UIDocumentInteractionController interactionControllerWithURL:[NSURL fileURLWithPath:filePath]];
  709. docController.delegate = self;
  710. if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
  711. [docController presentOptionsMenuFromRect:self.view.frame inView:self.view animated:YES];
  712. [docController presentOptionsMenuFromBarButtonItem:sender animated:YES];
  713. }
  714. - (void)shareButtonPressed:(UIBarButtonItem *)sender
  715. {
  716. [appDelegate.activeMain readShareWithAccount:appDelegate.activeAccount openWindow:YES metadata:self.metadataDetail];
  717. }
  718. - (void)deleteButtonPressed:(UIBarButtonItem *)sender
  719. {
  720. if ([self.metadataDetail.fileNameView length] == 0) return;
  721. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
  722. [alertController addAction: [UIAlertAction actionWithTitle:NSLocalizedString(@"_delete_", nil)
  723. style:UIAlertActionStyleDestructive
  724. handler:^(UIAlertAction *action) {
  725. [self deleteFile:self.metadataDetail];
  726. }]];
  727. [alertController addAction: [UIAlertAction actionWithTitle:NSLocalizedString(@"_cancel_", nil)
  728. style:UIAlertActionStyleCancel
  729. handler:^(UIAlertAction *action) {
  730. [alertController dismissViewControllerAnimated:YES completion:nil];
  731. }]];
  732. alertController.popoverPresentationController.barButtonItem = buttonDelete;
  733. if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
  734. [alertController.view layoutIfNeeded];
  735. [self presentViewController:alertController animated:YES completion:NULL];
  736. }
  737. @end