CCDetail.m 45 KB

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