VLCAppDelegate.m 12 KB

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