VLCAppDelegate.m 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  1. /*****************************************************************************
  2. * VLCAppDelegate.m
  3. * VLC for iOS
  4. *****************************************************************************
  5. * Copyright (c) 2013-2019 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 "VLCHTTPUploaderController.h"
  24. #import "VLCPlaybackController.h"
  25. #import "VLCPlaybackController+MediaLibrary.h"
  26. #import <MediaPlayer/MediaPlayer.h>
  27. #import <HockeySDK/HockeySDK.h>
  28. #import "VLCActivityManager.h"
  29. #import "VLCDropboxConstants.h"
  30. #import "VLCPlaybackNavigationController.h"
  31. #import "PAPasscodeViewController.h"
  32. #import "VLC-Swift.h"
  33. #import <OneDriveSDK.h>
  34. #import "VLCOneDriveConstants.h"
  35. #define BETA_DISTRIBUTION 1
  36. @interface VLCAppDelegate ()
  37. {
  38. BOOL _isComingFromHandoff;
  39. VLCKeychainCoordinator *_keychainCoordinator;
  40. AppCoordinator *appCoordinator;
  41. UITabBarController *rootViewController;
  42. }
  43. @end
  44. @implementation VLCAppDelegate
  45. + (void)initialize
  46. {
  47. NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
  48. NSDictionary *appDefaults = @{kVLCSettingPasscodeAllowFaceID : @(1),
  49. kVLCSettingPasscodeAllowTouchID : @(1),
  50. kVLCSettingContinueAudioInBackgroundKey : @(YES),
  51. kVLCSettingStretchAudio : @(NO),
  52. kVLCSettingTextEncoding : kVLCSettingTextEncodingDefaultValue,
  53. kVLCSettingSkipLoopFilter : kVLCSettingSkipLoopFilterNonRef,
  54. kVLCSettingSubtitlesFont : kVLCSettingSubtitlesFontDefaultValue,
  55. kVLCSettingSubtitlesFontColor : kVLCSettingSubtitlesFontColorDefaultValue,
  56. kVLCSettingSubtitlesFontSize : kVLCSettingSubtitlesFontSizeDefaultValue,
  57. kVLCSettingSubtitlesBoldFont: kVLCSettingSubtitlesBoldFontDefaultValue,
  58. kVLCSettingDeinterlace : kVLCSettingDeinterlaceDefaultValue,
  59. kVLCSettingHardwareDecoding : kVLCSettingHardwareDecodingDefault,
  60. kVLCSettingNetworkCaching : kVLCSettingNetworkCachingDefaultValue,
  61. kVLCSettingVolumeGesture : @(YES),
  62. kVLCSettingPlayPauseGesture : @(YES),
  63. kVLCSettingBrightnessGesture : @(YES),
  64. kVLCSettingSeekGesture : @(YES),
  65. kVLCSettingCloseGesture : @(YES),
  66. kVLCSettingVariableJumpDuration : @(NO),
  67. kVLCSettingVideoFullscreenPlayback : @(YES),
  68. kVLCSettingContinuePlayback : @(1),
  69. kVLCSettingContinueAudioPlayback : @(1),
  70. kVLCSettingFTPTextEncoding : kVLCSettingFTPTextEncodingDefaultValue,
  71. kVLCSettingWiFiSharingIPv6 : kVLCSettingWiFiSharingIPv6DefaultValue,
  72. kVLCSettingEqualizerProfile : kVLCSettingEqualizerProfileDefaultValue,
  73. kVLCSettingEqualizerProfileDisabled : @(YES),
  74. kVLCSettingPlaybackForwardSkipLength : kVLCSettingPlaybackForwardSkipLengthDefaultValue,
  75. kVLCSettingPlaybackBackwardSkipLength : kVLCSettingPlaybackBackwardSkipLengthDefaultValue,
  76. kVLCSettingOpenAppForPlayback : kVLCSettingOpenAppForPlaybackDefaultValue,
  77. kVLCAutomaticallyPlayNextItem : @(YES)};
  78. [defaults registerDefaults:appDefaults];
  79. }
  80. - (void)setup
  81. {
  82. void (^setupAppCoordinator)(void) = ^{
  83. self->appCoordinator = [[AppCoordinator alloc] initWithTabBarController:self->rootViewController];
  84. [self->appCoordinator start];
  85. };
  86. [self validatePasscodeIfNeededWithCompletion:setupAppCoordinator];
  87. }
  88. - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
  89. {
  90. BITHockeyManager *hockeyManager = [BITHockeyManager sharedHockeyManager];
  91. [hockeyManager configureWithBetaIdentifier:@"0114ca8e265244ce588d2ebd035c3577"
  92. liveIdentifier:@"c95f4227dff96c61f8b3a46a25edc584"
  93. delegate:nil];
  94. [hockeyManager startManager];
  95. // Configure Dropbox
  96. [DBClientsManager setupWithAppKey:kVLCDropboxAppKey];
  97. // Configure OneDrive
  98. [ODClient setMicrosoftAccountAppId:kVLCOneDriveClientID scopes:@[@"onedrive.readwrite", @"offline_access"]];
  99. [VLCApperanceManager setupAppearanceWithTheme:PresentationTheme.current];
  100. self.orientationLock = UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskLandscape;
  101. self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
  102. rootViewController = [UITabBarController new];
  103. self.window.rootViewController = rootViewController;
  104. [self.window makeKeyAndVisible];
  105. [self setup];
  106. /* add our static shortcut items the dynamic way to ease l10n and dynamic elements to be introduced later */
  107. if (application.shortcutItems == nil || application.shortcutItems.count < 4) {
  108. UIApplicationShortcutItem *localVideoItem = [[UIApplicationShortcutItem alloc] initWithType:kVLCApplicationShortcutLocalVideo
  109. localizedTitle:NSLocalizedString(@"VIDEO",nil)
  110. localizedSubtitle:nil
  111. icon:[UIApplicationShortcutIcon iconWithTemplateImageName:@"Video"]
  112. userInfo:nil];
  113. UIApplicationShortcutItem *localAudioItem = [[UIApplicationShortcutItem alloc] initWithType:kVLCApplicationShortcutLocalAudio
  114. localizedTitle:NSLocalizedString(@"AUDIO",nil)
  115. localizedSubtitle:nil
  116. icon:[UIApplicationShortcutIcon iconWithTemplateImageName:@"Audio"]
  117. userInfo:nil];
  118. UIApplicationShortcutItem *localplaylistItem = [[UIApplicationShortcutItem alloc] initWithType:kVLCApplicationShortcutPlaylist
  119. localizedTitle:NSLocalizedString(@"PLAYLISTS",nil)
  120. localizedSubtitle:nil
  121. icon:[UIApplicationShortcutIcon iconWithTemplateImageName:@"Playlist"]
  122. userInfo:nil];
  123. UIApplicationShortcutItem *networkItem = [[UIApplicationShortcutItem alloc] initWithType:kVLCApplicationShortcutNetwork
  124. localizedTitle:NSLocalizedString(@"NETWORK",nil)
  125. localizedSubtitle:nil
  126. icon:[UIApplicationShortcutIcon iconWithTemplateImageName:@"Network"]
  127. userInfo:nil];
  128. application.shortcutItems = @[localVideoItem, localAudioItem, localplaylistItem, networkItem];
  129. }
  130. return YES;
  131. }
  132. #pragma mark - Handoff
  133. - (BOOL)application:(UIApplication *)application willContinueUserActivityWithType:(NSString *)userActivityType
  134. {
  135. return [userActivityType isEqualToString:kVLCUserActivityPlaying];
  136. }
  137. - (BOOL)application:(UIApplication *)application
  138. continueUserActivity:(NSUserActivity *)userActivity
  139. restorationHandler:(void (^)(NSArray<id<UIUserActivityRestoring>> *))restorationHandler
  140. {
  141. VLCMLMedia *media = [appCoordinator mediaForUserActivity:userActivity];
  142. if (!media) return NO;
  143. [self validatePasscodeIfNeededWithCompletion:^{
  144. [[VLCPlaybackController sharedInstance] playMedia:media];
  145. }];
  146. return YES;
  147. }
  148. - (void)application:(UIApplication *)application
  149. didFailToContinueUserActivityWithType:(NSString *)userActivityType
  150. error:(NSError *)error
  151. {
  152. if (error.code != NSUserCancelledError){
  153. //TODO: present alert
  154. }
  155. }
  156. - (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options
  157. {
  158. for (id<VLCURLHandler> handler in URLHandlers.handlers) {
  159. if ([handler canHandleOpenWithUrl:url options:options]) {
  160. if ([handler performOpenWithUrl:url options:options]) {
  161. break;
  162. }
  163. }
  164. }
  165. return NO;
  166. }
  167. - (void)applicationWillEnterForeground:(UIApplication *)application
  168. {
  169. [[MLMediaLibrary sharedMediaLibrary] applicationWillStart];
  170. }
  171. - (void)applicationWillResignActive:(UIApplication *)application
  172. {
  173. //Touch ID is shown
  174. if ([_window.rootViewController.presentedViewController isKindOfClass:[UINavigationController class]]){
  175. UINavigationController *navCon = (UINavigationController *)_window.rootViewController.presentedViewController;
  176. if ([navCon.topViewController isKindOfClass:[PAPasscodeViewController class]]){
  177. return;
  178. }
  179. }
  180. [self validatePasscodeIfNeededWithCompletion:^{
  181. //TODO: handle updating the videoview and
  182. if ([VLCPlaybackController sharedInstance].isPlaying){
  183. //TODO: push playback
  184. }
  185. }];
  186. [[MLMediaLibrary sharedMediaLibrary] applicationWillExit];
  187. }
  188. - (void)applicationDidBecomeActive:(UIApplication *)application
  189. {
  190. if (!_isComingFromHandoff) {
  191. [[MLMediaLibrary sharedMediaLibrary] updateMediaDatabase];
  192. // [[VLCMediaFileDiscoverer sharedInstance] updateMediaList];
  193. [[VLCPlaybackController sharedInstance] recoverDisplayedMetadata];
  194. } else if(_isComingFromHandoff) {
  195. _isComingFromHandoff = NO;
  196. }
  197. }
  198. - (void)application:(UIApplication *)application performActionForShortcutItem:(UIApplicationShortcutItem *)shortcutItem completionHandler:(void (^)(BOOL))completionHandler
  199. {
  200. [appCoordinator handleShortcutItem:shortcutItem];
  201. }
  202. #pragma mark - pass code validation
  203. - (VLCKeychainCoordinator *)keychainCoordinator
  204. {
  205. if (!_keychainCoordinator) {
  206. _keychainCoordinator = [[VLCKeychainCoordinator alloc] init];
  207. }
  208. return _keychainCoordinator;
  209. }
  210. - (void)validatePasscodeIfNeededWithCompletion:(void(^)(void))completion
  211. {
  212. if ([VLCKeychainCoordinator passcodeLockEnabled]) {
  213. //TODO: Dimiss playback
  214. [self.keychainCoordinator validatePasscodeWithCompletion:completion];
  215. } else {
  216. completion();
  217. }
  218. }
  219. - (UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
  220. {
  221. return self.orientationLock;
  222. }
  223. @end