VLCAppDelegate.m 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510
  1. /*****************************************************************************
  2. * VLCAppDelegate.m
  3. * VLC for iOS
  4. *****************************************************************************
  5. * Copyright (c) 2013-2015 VideoLAN. All rights reserved.
  6. * $Id$
  7. *
  8. * Authors: Felix Paul Kühne <fkuehne # videolan.org>
  9. * Gleb Pinigin <gpinigin # gmail.com>
  10. * Jean-Romain Prévost <jr # 3on.fr>
  11. * Luis Fernandes <zipleen # gmail.com>
  12. * Carola Nitz <nitz.carola # googlemail.com>
  13. * Tamas Timar <ttimar.vlc # gmail.com>
  14. * Tobias Conradi <videolan # tobias-conradi.de>
  15. * Soomin Lee <TheHungryBu # gmail.com>
  16. *
  17. * Refer to the COPYING file of the official project for license.
  18. *****************************************************************************/
  19. #import "VLCAppDelegate.h"
  20. #import "VLCMediaFileDiscoverer.h"
  21. #import "NSString+SupportedMedia.h"
  22. #import "UIDevice+VLC.h"
  23. #import "VLCLibraryViewController.h"
  24. #import "VLCHTTPUploaderController.h"
  25. #import "VLCMigrationViewController.h"
  26. #import <BoxSDK/BoxSDK.h>
  27. #import "VLCPlaybackController.h"
  28. #import "VLCPlaybackController+MediaLibrary.h"
  29. #import "VLCPlayerDisplayController.h"
  30. #import <MediaPlayer/MediaPlayer.h>
  31. #import <HockeySDK/HockeySDK.h>
  32. #import "VLCSidebarController.h"
  33. #import "VLCKeychainCoordinator.h"
  34. #import "VLCActivityManager.h"
  35. #import "VLCDropboxConstants.h"
  36. #import <ObjectiveDropboxOfficial/ObjectiveDropboxOfficial.h>
  37. NSString *const VLCDropboxSessionWasAuthorized = @"VLCDropboxSessionWasAuthorized";
  38. #define BETA_DISTRIBUTION 1
  39. @interface VLCAppDelegate () <VLCMediaFileDiscovererDelegate>
  40. {
  41. BOOL _passcodeValidated;
  42. BOOL _isRunningMigration;
  43. BOOL _isComingFromHandoff;
  44. VLCWatchCommunication *_watchCommunication;
  45. }
  46. @end
  47. @implementation VLCAppDelegate
  48. + (void)initialize
  49. {
  50. NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
  51. NSDictionary *appDefaults = @{kVLCSettingPasscodeAllowTouchID : @(1),
  52. kVLCSettingContinueAudioInBackgroundKey : @(YES),
  53. kVLCSettingStretchAudio : @(NO),
  54. kVLCSettingTextEncoding : kVLCSettingTextEncodingDefaultValue,
  55. kVLCSettingSkipLoopFilter : kVLCSettingSkipLoopFilterNonRef,
  56. kVLCSettingSubtitlesFont : kVLCSettingSubtitlesFontDefaultValue,
  57. kVLCSettingSubtitlesFontColor : kVLCSettingSubtitlesFontColorDefaultValue,
  58. kVLCSettingSubtitlesFontSize : kVLCSettingSubtitlesFontSizeDefaultValue,
  59. kVLCSettingSubtitlesBoldFont: kVLCSettingSubtitlesBoldFontDefaultValue,
  60. kVLCSettingDeinterlace : kVLCSettingDeinterlaceDefaultValue,
  61. kVLCSettingHardwareDecoding : kVLCSettingHardwareDecodingDefault,
  62. kVLCSettingNetworkCaching : kVLCSettingNetworkCachingDefaultValue,
  63. kVLCSettingVolumeGesture : @(YES),
  64. kVLCSettingPlayPauseGesture : @(YES),
  65. kVLCSettingBrightnessGesture : @(YES),
  66. kVLCSettingSeekGesture : @(YES),
  67. kVLCSettingCloseGesture : @(YES),
  68. kVLCSettingVariableJumpDuration : @(NO),
  69. kVLCSettingVideoFullscreenPlayback : @(YES),
  70. kVLCSettingContinuePlayback : @(1),
  71. kVLCSettingContinueAudioPlayback : @(1),
  72. kVLCSettingFTPTextEncoding : kVLCSettingFTPTextEncodingDefaultValue,
  73. kVLCSettingWiFiSharingIPv6 : kVLCSettingWiFiSharingIPv6DefaultValue,
  74. kVLCSettingEqualizerProfile : kVLCSettingEqualizerProfileDefaultValue,
  75. kVLCSettingPlaybackForwardSkipLength : kVLCSettingPlaybackForwardSkipLengthDefaultValue,
  76. kVLCSettingPlaybackBackwardSkipLength : kVLCSettingPlaybackBackwardSkipLengthDefaultValue,
  77. kVLCSettingOpenAppForPlayback : kVLCSettingOpenAppForPlaybackDefaultValue,
  78. kVLCAutomaticallyPlayNextItem : @(YES)};
  79. [defaults registerDefaults:appDefaults];
  80. }
  81. - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
  82. {
  83. BITHockeyManager *hockeyManager = [BITHockeyManager sharedHockeyManager];
  84. [hockeyManager configureWithBetaIdentifier:@"0114ca8e265244ce588d2ebd035c3577"
  85. liveIdentifier:@"c95f4227dff96c61f8b3a46a25edc584"
  86. delegate:nil];
  87. // Configure Dropbox
  88. [DBClientsManager setupWithAppKey:kVLCDropboxAppKey];
  89. // Configure the SDK in here only!
  90. [hockeyManager startManager];
  91. [hockeyManager.authenticator authenticateInstallation];
  92. /* listen to validation notification */
  93. [[NSNotificationCenter defaultCenter] addObserver:self
  94. selector:@selector(passcodeWasValidated:)
  95. name:VLCPasscodeValidated
  96. object:nil];
  97. // Change the keyboard for UISearchBar
  98. [[UITextField appearance] setKeyboardAppearance:UIKeyboardAppearanceDark];
  99. // For the cursor
  100. [[UITextField appearance] setTintColor:[UIColor VLCOrangeTintColor]];
  101. // Don't override the 'Cancel' button color in the search bar with the previous UITextField call. Use the default blue color
  102. [[UIBarButtonItem appearanceWhenContainedIn:[UISearchBar class], nil] setTitleTextAttributes:@{NSForegroundColorAttributeName: [UIColor colorWithRed:0.0 green:122.0/255.0 blue:1.0 alpha:1.0]} forState:UIControlStateNormal];
  103. // For the edit selection indicators
  104. [[UITableView appearance] setTintColor:[UIColor VLCOrangeTintColor]];
  105. [[UISwitch appearance] setOnTintColor:[UIColor VLCOrangeTintColor]];
  106. // Init the HTTP Server and clean its cache
  107. [[VLCHTTPUploaderController sharedInstance] cleanCache];
  108. self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
  109. // enable crash preventer
  110. void (^setupBlock)() = ^{
  111. _libraryViewController = [[VLCLibraryViewController alloc] init];
  112. VLCSidebarController *sidebarVC = [VLCSidebarController sharedInstance];
  113. VLCNavigationController *navCon = [[VLCNavigationController alloc] initWithRootViewController:_libraryViewController];
  114. sidebarVC.contentViewController = navCon;
  115. VLCPlayerDisplayController *playerDisplayController = [VLCPlayerDisplayController sharedInstance];
  116. playerDisplayController.childViewController = sidebarVC.fullViewController;
  117. self.window.rootViewController = playerDisplayController;
  118. [self.window makeKeyAndVisible];
  119. [self validatePasscode];
  120. BOOL spotlightEnabled = ![[VLCKeychainCoordinator defaultCoordinator] passcodeLockEnabled];
  121. [[MLMediaLibrary sharedMediaLibrary] setSpotlightIndexingEnabled:spotlightEnabled];
  122. [[MLMediaLibrary sharedMediaLibrary] applicationWillStart];
  123. VLCMediaFileDiscoverer *discoverer = [VLCMediaFileDiscoverer sharedInstance];
  124. NSArray *searchPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
  125. discoverer.directoryPath = [searchPaths firstObject];
  126. [discoverer addObserver:self];
  127. [discoverer startDiscovering];
  128. };
  129. NSError *error = nil;
  130. if ([[MLMediaLibrary sharedMediaLibrary] libraryMigrationNeeded]){
  131. _isRunningMigration = YES;
  132. VLCMigrationViewController *migrationController = [[VLCMigrationViewController alloc] initWithNibName:@"VLCMigrationViewController" bundle:nil];
  133. migrationController.completionHandler = ^{
  134. //migrate
  135. setupBlock();
  136. _isRunningMigration = NO;
  137. [[MLMediaLibrary sharedMediaLibrary] updateMediaDatabase];
  138. [[VLCMediaFileDiscoverer sharedInstance] updateMediaList];
  139. };
  140. self.window.rootViewController = migrationController;
  141. [self.window makeKeyAndVisible];
  142. } else {
  143. if (error != nil) {
  144. APLog(@"removed persistentStore since it was corrupt");
  145. NSURL *storeURL = ((MLMediaLibrary *)[MLMediaLibrary sharedMediaLibrary]).persistentStoreURL;
  146. [[NSFileManager defaultManager] removeItemAtURL:storeURL error:&error];
  147. }
  148. setupBlock();
  149. }
  150. if ([VLCWatchCommunication isSupported]) {
  151. _watchCommunication = [VLCWatchCommunication sharedInstance];
  152. // TODO: push DB changes instead
  153. // [_watchCommunication startRelayingNotificationName:NSManagedObjectContextDidSaveNotification object:nil];
  154. [_watchCommunication startRelayingNotificationName:VLCPlaybackControllerPlaybackMetadataDidChange object:nil];
  155. }
  156. /* add our static shortcut items the dynamic way to ease l10n and dynamic elements to be introduced later */
  157. if ([UIApplicationShortcutItem class] != nil) {
  158. if (application.shortcutItems == nil || application.shortcutItems.count < 4) {
  159. UIApplicationShortcutItem *localLibraryItem = [[UIApplicationShortcutItem alloc] initWithType:kVLCApplicationShortcutLocalLibrary
  160. localizedTitle:NSLocalizedString(@"SECTION_HEADER_LIBRARY",nil)
  161. localizedSubtitle:nil
  162. icon:[UIApplicationShortcutIcon iconWithTemplateImageName:@"AllFiles"]
  163. userInfo:nil];
  164. UIApplicationShortcutItem *localServerItem = [[UIApplicationShortcutItem alloc] initWithType:kVLCApplicationShortcutLocalServers
  165. localizedTitle:NSLocalizedString(@"LOCAL_NETWORK",nil)
  166. localizedSubtitle:nil
  167. icon:[UIApplicationShortcutIcon iconWithTemplateImageName:@"Local"]
  168. userInfo:nil];
  169. UIApplicationShortcutItem *openNetworkStreamItem = [[UIApplicationShortcutItem alloc] initWithType:kVLCApplicationShortcutOpenNetworkStream
  170. localizedTitle:NSLocalizedString(@"OPEN_NETWORK",nil)
  171. localizedSubtitle:nil
  172. icon:[UIApplicationShortcutIcon iconWithTemplateImageName:@"OpenNetStream"]
  173. userInfo:nil];
  174. UIApplicationShortcutItem *cloudsItem = [[UIApplicationShortcutItem alloc] initWithType:kVLCApplicationShortcutClouds
  175. localizedTitle:NSLocalizedString(@"CLOUD_SERVICES",nil)
  176. localizedSubtitle:nil
  177. icon:[UIApplicationShortcutIcon iconWithTemplateImageName:@"iCloudIcon"]
  178. userInfo:nil];
  179. application.shortcutItems = @[localLibraryItem, localServerItem, openNetworkStreamItem, cloudsItem];
  180. }
  181. }
  182. return YES;
  183. }
  184. - (void)dealloc
  185. {
  186. [[NSNotificationCenter defaultCenter] removeObserver:self];
  187. }
  188. #pragma mark - Handoff
  189. - (BOOL)application:(UIApplication *)application willContinueUserActivityWithType:(NSString *)userActivityType
  190. {
  191. if ([userActivityType isEqualToString:kVLCUserActivityLibraryMode] ||
  192. [userActivityType isEqualToString:kVLCUserActivityPlaying] ||
  193. [userActivityType isEqualToString:kVLCUserActivityLibrarySelection])
  194. return YES;
  195. return NO;
  196. }
  197. - (BOOL)application:(UIApplication *)application
  198. continueUserActivity:(NSUserActivity *)userActivity
  199. restorationHandler:(void (^)(NSArray *))restorationHandler
  200. {
  201. NSString *userActivityType = userActivity.activityType;
  202. NSDictionary *dict = userActivity.userInfo;
  203. if([userActivityType isEqualToString:kVLCUserActivityLibraryMode] ||
  204. [userActivityType isEqualToString:kVLCUserActivityLibrarySelection]) {
  205. VLCLibraryMode libraryMode = (VLCLibraryMode)[(NSNumber *)dict[@"state"] integerValue];
  206. if (libraryMode <= VLCLibraryModeAllSeries) {
  207. [[VLCSidebarController sharedInstance] selectRowAtIndexPath:[NSIndexPath indexPathForRow:libraryMode inSection:0]
  208. scrollPosition:UITableViewScrollPositionTop];
  209. [self.libraryViewController setLibraryMode:libraryMode];
  210. }
  211. [self.libraryViewController restoreUserActivityState:userActivity];
  212. _isComingFromHandoff = YES;
  213. return YES;
  214. } else {
  215. NSURL *uriRepresentation = nil;
  216. if ([userActivityType isEqualToString:CSSearchableItemActionType]) {
  217. uriRepresentation = [NSURL URLWithString:dict[CSSearchableItemActivityIdentifier]];
  218. } else {
  219. uriRepresentation = dict[@"playingmedia"];
  220. }
  221. if (!uriRepresentation) {
  222. return NO;
  223. }
  224. NSManagedObject *managedObject = [[MLMediaLibrary sharedMediaLibrary] objectForURIRepresentation:uriRepresentation];
  225. if (managedObject == nil) {
  226. APLog(@"%s file not found: %@",__PRETTY_FUNCTION__,userActivity);
  227. return NO;
  228. }
  229. [[VLCPlaybackController sharedInstance] openMediaLibraryObject:managedObject];
  230. return YES;
  231. }
  232. return NO;
  233. }
  234. - (void)application:(UIApplication *)application
  235. didFailToContinueUserActivityWithType:(NSString *)userActivityType
  236. error:(NSError *)error
  237. {
  238. if (error.code != NSUserCancelledError){
  239. //TODO: present alert
  240. }
  241. }
  242. - (BOOL)application:(UIApplication *)application
  243. openURL:(NSURL *)url
  244. sourceApplication:(NSString *)sourceApplication
  245. annotation:(id)annotation
  246. {
  247. //Handles Dropbox Authorization flow.
  248. DBOAuthResult *authResult = [DBClientsManager handleRedirectURL:url];
  249. if (authResult != nil) {
  250. if ([authResult isSuccess]) {
  251. return YES;
  252. }
  253. }
  254. //Handles Google Authorization flow.
  255. if ([_currentGoogleAuthorizationFlow resumeAuthorizationFlowWithURL:url]) {
  256. _currentGoogleAuthorizationFlow = nil;
  257. return YES;
  258. }
  259. if (_libraryViewController && url != nil) {
  260. APLog(@"%@ requested %@ to be opened", sourceApplication, url);
  261. if (url.isFileURL) {
  262. NSArray *searchPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
  263. NSString *directoryPath = searchPaths[0];
  264. NSURL *destinationURL = [NSURL fileURLWithPath:[NSString stringWithFormat:@"%@/%@", directoryPath, url.lastPathComponent]];
  265. NSError *theError;
  266. [[NSFileManager defaultManager] moveItemAtURL:url toURL:destinationURL error:&theError];
  267. if (theError.code != noErr)
  268. APLog(@"saving the file failed (%li): %@", (long)theError.code, theError.localizedDescription);
  269. [[VLCMediaFileDiscoverer sharedInstance] updateMediaList];
  270. } else if ([url.scheme isEqualToString:@"vlc-x-callback"] || [url.host isEqualToString:@"x-callback-url"]) {
  271. // URL confirmes to the x-callback-url specification
  272. // vlc-x-callback://x-callback-url/action?param=value&x-success=callback
  273. APLog(@"x-callback-url with host '%@' path '%@' parameters '%@'", url.host, url.path, url.query);
  274. NSString *action = [url.path stringByReplacingOccurrencesOfString:@"/" withString:@""];
  275. NSURL *movieURL;
  276. NSURL *successCallback;
  277. NSURL *errorCallback;
  278. NSString *fileName;
  279. for (NSString *entry in [url.query componentsSeparatedByString:@"&"]) {
  280. NSArray *keyvalue = [entry componentsSeparatedByString:@"="];
  281. if (keyvalue.count < 2) continue;
  282. NSString *key = keyvalue[0];
  283. NSString *value = [keyvalue[1] stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
  284. if ([key isEqualToString:@"url"])
  285. movieURL = [NSURL URLWithString:value];
  286. else if ([key isEqualToString:@"filename"])
  287. fileName = value;
  288. else if ([key isEqualToString:@"x-success"])
  289. successCallback = [NSURL URLWithString:value];
  290. else if ([key isEqualToString:@"x-error"])
  291. errorCallback = [NSURL URLWithString:value];
  292. }
  293. if ([action isEqualToString:@"stream"] && movieURL) {
  294. VLCPlaybackController *vpc = [VLCPlaybackController sharedInstance];
  295. vpc.fullscreenSessionRequested = YES;
  296. [vpc playURL:movieURL successCallback:successCallback errorCallback:errorCallback];
  297. }
  298. else if ([action isEqualToString:@"download"] && movieURL) {
  299. [self downloadMovieFromURL:movieURL fileNameOfMedia:fileName];
  300. }
  301. } else {
  302. NSString *receivedUrl = [url absoluteString];
  303. if ([receivedUrl length] > 6) {
  304. NSString *verifyVlcUrl = [receivedUrl substringToIndex:6];
  305. if ([verifyVlcUrl isEqualToString:@"vlc://"]) {
  306. NSString *parsedString = [receivedUrl substringFromIndex:6];
  307. NSUInteger location = [parsedString rangeOfString:@"//"].location;
  308. /* Safari & al mangle vlc://http:// so fix this */
  309. if (location != NSNotFound && [parsedString characterAtIndex:location - 1] != 0x3a) { // :
  310. parsedString = [NSString stringWithFormat:@"%@://%@", [parsedString substringToIndex:location], [parsedString substringFromIndex:location+2]];
  311. } else {
  312. parsedString = [receivedUrl substringFromIndex:6];
  313. if (![parsedString hasPrefix:@"http://"] && ![parsedString hasPrefix:@"https://"] && ![parsedString hasPrefix:@"ftp://"]) {
  314. parsedString = [@"http://" stringByAppendingString:[receivedUrl substringFromIndex:6]];
  315. }
  316. }
  317. url = [NSURL URLWithString:parsedString];
  318. }
  319. }
  320. [[VLCSidebarController sharedInstance] selectRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]
  321. scrollPosition:UITableViewScrollPositionNone];
  322. NSString *scheme = url.scheme;
  323. if ([scheme isEqualToString:@"http"] || [scheme isEqualToString:@"https"] || [scheme isEqualToString:@"ftp"]) {
  324. VLCAlertView *alert = [[VLCAlertView alloc] initWithTitle:NSLocalizedString(@"OPEN_STREAM_OR_DOWNLOAD", nil) message:url.absoluteString cancelButtonTitle:NSLocalizedString(@"BUTTON_DOWNLOAD", nil) otherButtonTitles:@[NSLocalizedString(@"PLAY_BUTTON", nil)]];
  325. alert.completion = ^(BOOL cancelled, NSInteger buttonIndex) {
  326. if (cancelled)
  327. [self downloadMovieFromURL:url fileNameOfMedia:nil];
  328. else {
  329. VLCPlaybackController *vpc = [VLCPlaybackController sharedInstance];
  330. [vpc playURL:url successCallback:nil errorCallback:nil];
  331. }
  332. };
  333. [alert show];
  334. } else {
  335. VLCPlaybackController *vpc = [VLCPlaybackController sharedInstance];
  336. vpc.fullscreenSessionRequested = YES;
  337. [vpc playURL:url successCallback:nil errorCallback:nil];
  338. }
  339. }
  340. return YES;
  341. }
  342. return NO;
  343. }
  344. - (void)applicationWillEnterForeground:(UIApplication *)application
  345. {
  346. [[MLMediaLibrary sharedMediaLibrary] applicationWillStart];
  347. }
  348. - (void)applicationWillResignActive:(UIApplication *)application
  349. {
  350. _passcodeValidated = NO;
  351. [self.libraryViewController setEditing:NO animated:NO];
  352. [self validatePasscode];
  353. [[MLMediaLibrary sharedMediaLibrary] applicationWillExit];
  354. }
  355. - (void)applicationDidBecomeActive:(UIApplication *)application
  356. {
  357. if (!_isRunningMigration && !_isComingFromHandoff) {
  358. [[MLMediaLibrary sharedMediaLibrary] updateMediaDatabase];
  359. [[VLCMediaFileDiscoverer sharedInstance] updateMediaList];
  360. } else if(_isComingFromHandoff) {
  361. _isComingFromHandoff = NO;
  362. }
  363. }
  364. - (void)applicationWillTerminate:(UIApplication *)application
  365. {
  366. _passcodeValidated = NO;
  367. [[NSUserDefaults standardUserDefaults] synchronize];
  368. }
  369. - (void)application:(UIApplication *)application performActionForShortcutItem:(UIApplicationShortcutItem *)shortcutItem completionHandler:(void (^)(BOOL))completionHandler
  370. {
  371. [[VLCSidebarController sharedInstance] performActionForShortcutItem:shortcutItem];
  372. }
  373. #pragma mark - media discovering
  374. - (void)mediaFileAdded:(NSString *)fileName loading:(BOOL)isLoading
  375. {
  376. if (!isLoading) {
  377. MLMediaLibrary *sharedLibrary = [MLMediaLibrary sharedMediaLibrary];
  378. [sharedLibrary addFilePaths:@[fileName]];
  379. /* exclude media files from backup (QA1719) */
  380. NSURL *excludeURL = [NSURL fileURLWithPath:fileName];
  381. [excludeURL setResourceValue:@YES forKey:NSURLIsExcludedFromBackupKey error:nil];
  382. // TODO Should we update media db after adding new files?
  383. [sharedLibrary updateMediaDatabase];
  384. [_libraryViewController updateViewContents];
  385. }
  386. }
  387. - (void)mediaFileDeleted:(NSString *)name
  388. {
  389. [[MLMediaLibrary sharedMediaLibrary] updateMediaDatabase];
  390. [_libraryViewController updateViewContents];
  391. }
  392. - (void)mediaFilesFoundRequiringAdditionToStorageBackend:(NSArray<NSString *> *)foundFiles
  393. {
  394. [[MLMediaLibrary sharedMediaLibrary] addFilePaths:foundFiles];
  395. [[(VLCAppDelegate *)[UIApplication sharedApplication].delegate libraryViewController] updateViewContents];
  396. }
  397. #pragma mark - pass code validation
  398. - (void)passcodeWasValidated:(NSNotification *)aNotifcation
  399. {
  400. _passcodeValidated = YES;
  401. [self.libraryViewController updateViewContents];
  402. if ([VLCPlaybackController sharedInstance].isPlaying)
  403. [[VLCPlayerDisplayController sharedInstance] pushPlaybackView];
  404. }
  405. - (BOOL)passcodeValidated
  406. {
  407. return _passcodeValidated;
  408. }
  409. - (void)validatePasscode
  410. {
  411. VLCKeychainCoordinator *keychainCoordinator = [VLCKeychainCoordinator defaultCoordinator];
  412. if (!_passcodeValidated && [keychainCoordinator passcodeLockEnabled]) {
  413. [[VLCPlayerDisplayController sharedInstance] dismissPlaybackView];
  414. [keychainCoordinator validatePasscode];
  415. } else {
  416. _passcodeValidated = YES;
  417. [self passcodeValidated];
  418. }
  419. }
  420. #pragma mark - download handling
  421. - (void)downloadMovieFromURL:(NSURL *)url
  422. fileNameOfMedia:(NSString *)fileName
  423. {
  424. [[VLCDownloadViewController sharedInstance] addURLToDownloadList:url fileNameOfMedia:fileName];
  425. [[VLCSidebarController sharedInstance] selectRowAtIndexPath:[NSIndexPath indexPathForRow:2 inSection:1]
  426. scrollPosition:UITableViewScrollPositionNone];
  427. }
  428. #pragma mark - watch stuff
  429. - (void)application:(UIApplication *)application
  430. handleWatchKitExtensionRequest:(NSDictionary *)userInfo
  431. reply:(void (^)(NSDictionary *))reply
  432. {
  433. if ([VLCWatchCommunication isSupported]) {
  434. [self.watchCommunication session:[WCSession defaultSession] didReceiveMessage:userInfo replyHandler:reply];
  435. }
  436. }
  437. @end