123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253 |
- /*****************************************************************************
- * VLCAppDelegate.m
- * VLC for iOS
- *****************************************************************************
- * Copyright (c) 2013-2019 VideoLAN. All rights reserved.
- * $Id$
- *
- * Authors: Felix Paul Kühne <fkuehne # videolan.org>
- * Gleb Pinigin <gpinigin # gmail.com>
- * Jean-Romain Prévost <jr # 3on.fr>
- * Luis Fernandes <zipleen # gmail.com>
- * Carola Nitz <nitz.carola # googlemail.com>
- * Tamas Timar <ttimar.vlc # gmail.com>
- * Tobias Conradi <videolan # tobias-conradi.de>
- * Soomin Lee <TheHungryBu # gmail.com>
- *
- * Refer to the COPYING file of the official project for license.
- *****************************************************************************/
- #import "VLCAppDelegate.h"
- #import "VLCMediaFileDiscoverer.h"
- #import "NSString+SupportedMedia.h"
- #import "UIDevice+VLC.h"
- #import "VLCHTTPUploaderController.h"
- #import "VLCPlaybackService.h"
- #import "VLCPlaybackService+MediaLibrary.h"
- #import <MediaPlayer/MediaPlayer.h>
- #import <HockeySDK/HockeySDK.h>
- #import "VLCActivityManager.h"
- #import "VLCDropboxConstants.h"
- #import "VLCPlaybackNavigationController.h"
- #import "PAPasscodeViewController.h"
- #import "VLC-Swift.h"
- #import <OneDriveSDK.h>
- #import "VLCOneDriveConstants.h"
- #define BETA_DISTRIBUTION 1
- @interface VLCAppDelegate ()
- {
- BOOL _isComingFromHandoff;
- VLCKeychainCoordinator *_keychainCoordinator;
- AppCoordinator *appCoordinator;
- UITabBarController *rootViewController;
- }
- @end
- @implementation VLCAppDelegate
- + (void)initialize
- {
- NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
- NSDictionary *appDefaults = @{kVLCSettingPasscodeAllowFaceID : @(1),
- kVLCSettingPasscodeAllowTouchID : @(1),
- kVLCSettingContinueAudioInBackgroundKey : @(YES),
- kVLCSettingStretchAudio : @(NO),
- kVLCSettingTextEncoding : kVLCSettingTextEncodingDefaultValue,
- kVLCSettingSkipLoopFilter : kVLCSettingSkipLoopFilterNonRef,
- kVLCSettingSubtitlesFont : kVLCSettingSubtitlesFontDefaultValue,
- kVLCSettingSubtitlesFontColor : kVLCSettingSubtitlesFontColorDefaultValue,
- kVLCSettingSubtitlesFontSize : kVLCSettingSubtitlesFontSizeDefaultValue,
- kVLCSettingSubtitlesBoldFont: kVLCSettingSubtitlesBoldFontDefaultValue,
- kVLCSettingDeinterlace : kVLCSettingDeinterlaceDefaultValue,
- kVLCSettingHardwareDecoding : kVLCSettingHardwareDecodingDefault,
- kVLCSettingNetworkCaching : kVLCSettingNetworkCachingDefaultValue,
- kVLCSettingVolumeGesture : @(YES),
- kVLCSettingPlayPauseGesture : @(YES),
- kVLCSettingBrightnessGesture : @(YES),
- kVLCSettingSeekGesture : @(YES),
- kVLCSettingCloseGesture : @(YES),
- kVLCSettingVariableJumpDuration : @(NO),
- kVLCSettingVideoFullscreenPlayback : @(YES),
- kVLCSettingContinuePlayback : @(1),
- kVLCSettingContinueAudioPlayback : @(1),
- kVLCSettingFTPTextEncoding : kVLCSettingFTPTextEncodingDefaultValue,
- kVLCSettingWiFiSharingIPv6 : kVLCSettingWiFiSharingIPv6DefaultValue,
- kVLCSettingEqualizerProfile : kVLCSettingEqualizerProfileDefaultValue,
- kVLCSettingEqualizerProfileDisabled : @(YES),
- kVLCSettingPlaybackForwardSkipLength : kVLCSettingPlaybackForwardSkipLengthDefaultValue,
- kVLCSettingPlaybackBackwardSkipLength : kVLCSettingPlaybackBackwardSkipLengthDefaultValue,
- kVLCSettingOpenAppForPlayback : kVLCSettingOpenAppForPlaybackDefaultValue,
- kVLCAutomaticallyPlayNextItem : @(YES)};
- [defaults registerDefaults:appDefaults];
- }
- - (void)setup
- {
- void (^setupAppCoordinator)(void) = ^{
- self->appCoordinator = [[AppCoordinator alloc] initWithTabBarController:self->rootViewController];
- [self->appCoordinator start];
- };
- [self validatePasscodeIfNeededWithCompletion:setupAppCoordinator];
- }
- - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
- {
- BITHockeyManager *hockeyManager = [BITHockeyManager sharedHockeyManager];
- [hockeyManager configureWithBetaIdentifier:@"0114ca8e265244ce588d2ebd035c3577"
- liveIdentifier:@"c95f4227dff96c61f8b3a46a25edc584"
- delegate:nil];
- [hockeyManager startManager];
- // Configure Dropbox
- [DBClientsManager setupWithAppKey:kVLCDropboxAppKey];
- // Configure OneDrive
- [ODClient setMicrosoftAccountAppId:kVLCOneDriveClientID scopes:@[@"onedrive.readwrite", @"offline_access"]];
- [VLCApperanceManager setupAppearanceWithTheme:PresentationTheme.current];
- self.orientationLock = UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskLandscape;
- self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
- rootViewController = [UITabBarController new];
- self.window.rootViewController = rootViewController;
- [self.window makeKeyAndVisible];
- [self setup];
- /* add our static shortcut items the dynamic way to ease l10n and dynamic elements to be introduced later */
- if (application.shortcutItems == nil || application.shortcutItems.count < 4) {
- UIApplicationShortcutItem *localVideoItem = [[UIApplicationShortcutItem alloc] initWithType:kVLCApplicationShortcutLocalVideo
- localizedTitle:NSLocalizedString(@"VIDEO",nil)
- localizedSubtitle:nil
- icon:[UIApplicationShortcutIcon iconWithTemplateImageName:@"Video"]
- userInfo:nil];
- UIApplicationShortcutItem *localAudioItem = [[UIApplicationShortcutItem alloc] initWithType:kVLCApplicationShortcutLocalAudio
- localizedTitle:NSLocalizedString(@"AUDIO",nil)
- localizedSubtitle:nil
- icon:[UIApplicationShortcutIcon iconWithTemplateImageName:@"Audio"]
- userInfo:nil];
- UIApplicationShortcutItem *localplaylistItem = [[UIApplicationShortcutItem alloc] initWithType:kVLCApplicationShortcutPlaylist
- localizedTitle:NSLocalizedString(@"PLAYLISTS",nil)
- localizedSubtitle:nil
- icon:[UIApplicationShortcutIcon iconWithTemplateImageName:@"Playlist"]
- userInfo:nil];
- UIApplicationShortcutItem *networkItem = [[UIApplicationShortcutItem alloc] initWithType:kVLCApplicationShortcutNetwork
- localizedTitle:NSLocalizedString(@"NETWORK",nil)
- localizedSubtitle:nil
- icon:[UIApplicationShortcutIcon iconWithTemplateImageName:@"Network"]
- userInfo:nil];
- application.shortcutItems = @[localVideoItem, localAudioItem, localplaylistItem, networkItem];
- }
- return YES;
- }
- #pragma mark - Handoff
- - (BOOL)application:(UIApplication *)application willContinueUserActivityWithType:(NSString *)userActivityType
- {
- return [userActivityType isEqualToString:kVLCUserActivityPlaying];
- }
- - (BOOL)application:(UIApplication *)application
- continueUserActivity:(NSUserActivity *)userActivity
- restorationHandler:(void (^)(NSArray<id<UIUserActivityRestoring>> *))restorationHandler
- {
- VLCMLMedia *media = [appCoordinator mediaForUserActivity:userActivity];
- if (!media) return NO;
- [self validatePasscodeIfNeededWithCompletion:^{
- [[VLCPlaybackService sharedInstance] playMedia:media];
- }];
- return YES;
- }
- - (void)application:(UIApplication *)application
- didFailToContinueUserActivityWithType:(NSString *)userActivityType
- error:(NSError *)error
- {
- if (error.code != NSUserCancelledError){
- //TODO: present alert
- }
- }
- - (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options
- {
- for (id<VLCURLHandler> handler in URLHandlers.handlers) {
- if ([handler canHandleOpenWithUrl:url options:options]) {
- if ([handler performOpenWithUrl:url options:options]) {
- return YES;
- }
- }
- }
- return NO;
- }
- - (void)applicationWillEnterForeground:(UIApplication *)application
- {
- [[MLMediaLibrary sharedMediaLibrary] applicationWillStart];
- }
- - (void)applicationWillResignActive:(UIApplication *)application
- {
- //Touch ID is shown
- if ([_window.rootViewController.presentedViewController isKindOfClass:[UINavigationController class]]){
- UINavigationController *navCon = (UINavigationController *)_window.rootViewController.presentedViewController;
- if ([navCon.topViewController isKindOfClass:[PAPasscodeViewController class]]){
- return;
- }
- }
- [self validatePasscodeIfNeededWithCompletion:^{
- //TODO: handle updating the videoview and
- if ([VLCPlaybackService sharedInstance].isPlaying){
- //TODO: push playback
- }
- }];
- [[MLMediaLibrary sharedMediaLibrary] applicationWillExit];
- }
- - (void)applicationDidBecomeActive:(UIApplication *)application
- {
- if (!_isComingFromHandoff) {
- [[MLMediaLibrary sharedMediaLibrary] updateMediaDatabase];
- // [[VLCMediaFileDiscoverer sharedInstance] updateMediaList];
- [[VLCPlaybackService sharedInstance] recoverDisplayedMetadata];
- } else if(_isComingFromHandoff) {
- _isComingFromHandoff = NO;
- }
- }
- - (void)application:(UIApplication *)application performActionForShortcutItem:(UIApplicationShortcutItem *)shortcutItem completionHandler:(void (^)(BOOL))completionHandler
- {
- [appCoordinator handleShortcutItem:shortcutItem];
- }
- #pragma mark - pass code validation
- - (VLCKeychainCoordinator *)keychainCoordinator
- {
- if (!_keychainCoordinator) {
- _keychainCoordinator = [[VLCKeychainCoordinator alloc] init];
- }
- return _keychainCoordinator;
- }
- - (void)validatePasscodeIfNeededWithCompletion:(void(^)(void))completion
- {
- if ([VLCKeychainCoordinator passcodeLockEnabled]) {
- //TODO: Dimiss playback
- [self.keychainCoordinator validatePasscodeWithCompletion:completion];
- } else {
- completion();
- }
- }
- - (UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
- {
- return self.orientationLock;
- }
- @end
|