VLCAppDelegate.m 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  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.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
  101. rootViewController = [UITabBarController new];
  102. self.window.rootViewController = rootViewController;
  103. [self.window makeKeyAndVisible];
  104. [self setup];
  105. /* add our static shortcut items the dynamic way to ease l10n and dynamic elements to be introduced later */
  106. if (application.shortcutItems == nil || application.shortcutItems.count < 4) {
  107. UIApplicationShortcutItem *localVideoItem = [[UIApplicationShortcutItem alloc] initWithType:kVLCApplicationShortcutLocalVideo
  108. localizedTitle:NSLocalizedString(@"VIDEO",nil)
  109. localizedSubtitle:nil
  110. icon:[UIApplicationShortcutIcon iconWithTemplateImageName:@"Video"]
  111. userInfo:nil];
  112. UIApplicationShortcutItem *localAudioItem = [[UIApplicationShortcutItem alloc] initWithType:kVLCApplicationShortcutLocalAudio
  113. localizedTitle:NSLocalizedString(@"AUDIO",nil)
  114. localizedSubtitle:nil
  115. icon:[UIApplicationShortcutIcon iconWithTemplateImageName:@"Audio"]
  116. userInfo:nil];
  117. UIApplicationShortcutItem *localplaylistItem = [[UIApplicationShortcutItem alloc] initWithType:kVLCApplicationShortcutPlaylist
  118. localizedTitle:NSLocalizedString(@"PLAYLISTS",nil)
  119. localizedSubtitle:nil
  120. icon:[UIApplicationShortcutIcon iconWithTemplateImageName:@"Playlist"]
  121. userInfo:nil];
  122. UIApplicationShortcutItem *networkItem = [[UIApplicationShortcutItem alloc] initWithType:kVLCApplicationShortcutNetwork
  123. localizedTitle:NSLocalizedString(@"NETWORK",nil)
  124. localizedSubtitle:nil
  125. icon:[UIApplicationShortcutIcon iconWithTemplateImageName:@"Network"]
  126. userInfo:nil];
  127. application.shortcutItems = @[localVideoItem, localAudioItem, localplaylistItem, networkItem];
  128. }
  129. return YES;
  130. }
  131. #pragma mark - Handoff
  132. - (BOOL)application:(UIApplication *)application willContinueUserActivityWithType:(NSString *)userActivityType
  133. {
  134. return [userActivityType isEqualToString:kVLCUserActivityPlaying];
  135. }
  136. - (BOOL)application:(UIApplication *)application
  137. continueUserActivity:(NSUserActivity *)userActivity
  138. restorationHandler:(void (^)(NSArray<id<UIUserActivityRestoring>> *))restorationHandler
  139. {
  140. VLCMLMedia *media = [appCoordinator mediaForUserActivity:userActivity];
  141. if (!media) return NO;
  142. [self validatePasscodeIfNeededWithCompletion:^{
  143. [[VLCPlaybackController sharedInstance] playMedia:media];
  144. }];
  145. return YES;
  146. }
  147. - (void)application:(UIApplication *)application
  148. didFailToContinueUserActivityWithType:(NSString *)userActivityType
  149. error:(NSError *)error
  150. {
  151. if (error.code != NSUserCancelledError){
  152. //TODO: present alert
  153. }
  154. }
  155. - (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options
  156. {
  157. for (id<VLCURLHandler> handler in URLHandlers.handlers) {
  158. if ([handler canHandleOpenWithUrl:url options:options]) {
  159. if ([handler performOpenWithUrl:url options:options]) {
  160. break;
  161. }
  162. }
  163. }
  164. return NO;
  165. }
  166. - (void)applicationWillEnterForeground:(UIApplication *)application
  167. {
  168. [[MLMediaLibrary sharedMediaLibrary] applicationWillStart];
  169. }
  170. - (void)applicationWillResignActive:(UIApplication *)application
  171. {
  172. //Touch ID is shown
  173. if ([_window.rootViewController.presentedViewController isKindOfClass:[UINavigationController class]]){
  174. UINavigationController *navCon = (UINavigationController *)_window.rootViewController.presentedViewController;
  175. if ([navCon.topViewController isKindOfClass:[PAPasscodeViewController class]]){
  176. return;
  177. }
  178. }
  179. [self validatePasscodeIfNeededWithCompletion:^{
  180. //TODO: handle updating the videoview and
  181. if ([VLCPlaybackController sharedInstance].isPlaying){
  182. //TODO: push playback
  183. }
  184. }];
  185. [[MLMediaLibrary sharedMediaLibrary] applicationWillExit];
  186. }
  187. - (void)applicationDidBecomeActive:(UIApplication *)application
  188. {
  189. if (!_isComingFromHandoff) {
  190. [[MLMediaLibrary sharedMediaLibrary] updateMediaDatabase];
  191. // [[VLCMediaFileDiscoverer sharedInstance] updateMediaList];
  192. [[VLCPlaybackController sharedInstance] recoverDisplayedMetadata];
  193. } else if(_isComingFromHandoff) {
  194. _isComingFromHandoff = NO;
  195. }
  196. }
  197. - (void)application:(UIApplication *)application performActionForShortcutItem:(UIApplicationShortcutItem *)shortcutItem completionHandler:(void (^)(BOOL))completionHandler
  198. {
  199. [appCoordinator handleShortcutItem:shortcutItem];
  200. }
  201. #pragma mark - pass code validation
  202. - (VLCKeychainCoordinator *)keychainCoordinator
  203. {
  204. if (!_keychainCoordinator) {
  205. _keychainCoordinator = [[VLCKeychainCoordinator alloc] init];
  206. }
  207. return _keychainCoordinator;
  208. }
  209. - (void)validatePasscodeIfNeededWithCompletion:(void(^)(void))completion
  210. {
  211. if ([VLCKeychainCoordinator passcodeLockEnabled]) {
  212. //TODO: Dimiss playback
  213. [self.keychainCoordinator validatePasscodeWithCompletion:completion];
  214. } else {
  215. completion();
  216. }
  217. }
  218. @end