VLCAppDelegate.m 24 KB

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