Browse Source

VLCAppdelegate: Fix "open in VLC" failure

With the added Files support we switched the LSSupportsOpeningDocumentsInPlace to true.
This lead to urls being securely scoped and turning our "copy to" action into "open in" calls.
These need to be handled by a UIDocument subclass which handles calls to the system regarding access of other sandboxes.
(closes #233 #126)

(cherry picked from commit 20474e51f7cdfe0f5ad6e079b209b373be21e096)
Carola Nitz 7 years ago
parent
commit
25afefec51
3 changed files with 31 additions and 16 deletions
  1. 6 16
      Sources/VLCAppDelegate.m
  2. 21 0
      Sources/VLCDocumentClass.swift
  3. 4 0
      VLC.xcodeproj/project.pbxproj

+ 6 - 16
Sources/VLCAppDelegate.m

@@ -269,22 +269,12 @@ didFailToContinueUserActivityWithType:(NSString *)userActivityType
 //        APLog(@"requested %@ to be opened", url);
 //
 //        if (url.isFileURL) {
-//            NSArray *searchPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
-//            NSString *directoryPath = searchPaths.firstObject;
-//            NSURL *destinationURL = [NSURL fileURLWithPath:[NSString stringWithFormat:@"%@/%@", directoryPath, url.lastPathComponent]];
-//            NSError *theError;
-//            NSFileManager *manager = [NSFileManager defaultManager];
-//            [[NSFileManager defaultManager] moveItemAtURL:url toURL:destinationURL error:&theError];
-//            if (theError.code != noErr)
-//                APLog(@"saving the file failed (%li): %@", (long)theError.code, theError.localizedDescription);
-//
-//            [[VLCMediaFileDiscoverer sharedInstance] updateMediaList];
-//
-//            NSURLRelationship relationship;
-//            [manager getRelationship:&relationship ofDirectoryAtURL:[NSURL fileURLWithPath:directoryPath] toItemAtURL:url error:&theError];
-//            if (relationship == NSURLRelationshipContains) {
-//                [self playWithURL:url completion:nil];
-//            }
+//            VLCDocumentClass *subclass = [[VLCDocumentClass alloc] initWithFileURL:url];
+//            [subclass openWithCompletionHandler:^(BOOL success) {
+//                [self playWithURL:url completion:^(BOOL success) {
+//                    [subclass closeWithCompletionHandler:nil];
+//                }];
+//            }];
 //        } else if ([url.scheme isEqualToString:@"vlc-x-callback"] || [url.host isEqualToString:@"x-callback-url"]) {
 //            // URL confirmes to the x-callback-url specification
 //            // vlc-x-callback://x-callback-url/action?param=value&x-success=callback

+ 21 - 0
Sources/VLCDocumentClass.swift

@@ -0,0 +1,21 @@
+/*****************************************************************************
+ * VLCDocumentClass.swift
+ * VLC for iOS
+ *****************************************************************************
+ * Copyright (c) 2018 VideoLAN. All rights reserved.
+ * $Id$
+ *
+ * Authors: Carola Nitz <nitz.carola # googlemail.com>
+ *
+ * Refer to the COPYING file of the official project for license.
+ *****************************************************************************/
+
+import Foundation
+
+@objc(VLCDocumentClass)
+class DocumentClass: UIDocument {
+    override func load(fromContents contents: Any, ofType typeName: String?) throws {
+        //we should probably test the documenttype here
+    }
+}
+

+ 4 - 0
VLC.xcodeproj/project.pbxproj

@@ -54,6 +54,7 @@
 		41E6BECD207E64E900E158BA /* RemoteNetworkCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 41E6BECC207E64E900E158BA /* RemoteNetworkCell.swift */; };
 		41EA74C120C02DFC001E5D57 /* VLCDropboxController.m in Sources */ = {isa = PBXBuildFile; fileRef = 7D3784AA183A9906009EE944 /* VLCDropboxController.m */; };
 		41EA74C320C02F8E001E5D57 /* VLCBoxController.m in Sources */ = {isa = PBXBuildFile; fileRef = 41CD69591A29D72600E60BCE /* VLCBoxController.m */; };
+		41DFC6C62100BAAF00EEC9E3 /* VLCDocumentClass.swift in Sources */ = {isa = PBXBuildFile; fileRef = 41DFC6C52100BAAF00EEC9E3 /* VLCDocumentClass.swift */; };
 		41EB91D71F7BE6F500821AA5 /* VLCRemoteControlService.m in Sources */ = {isa = PBXBuildFile; fileRef = 417D7F5F1F7BA26200DDF36A /* VLCRemoteControlService.m */; };
 		41EB91DD1F7BFF8500821AA5 /* VLCMetadata.m in Sources */ = {isa = PBXBuildFile; fileRef = 41EB91DC1F7BFF8400821AA5 /* VLCMetadata.m */; };
 		41EB91DE1F7BFF8500821AA5 /* VLCMetadata.m in Sources */ = {isa = PBXBuildFile; fileRef = 41EB91DC1F7BFF8400821AA5 /* VLCMetadata.m */; };
@@ -587,6 +588,7 @@
 		41D7DD2020C1FC2D00AD94F6 /* VLCLabelCell.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; name = VLCLabelCell.xib; path = Resources/VLCLabelCell.xib; sourceTree = "<group>"; };
 		41D7DD2620C3060300AD94F6 /* PagerStripViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = PagerStripViewController.swift; path = Sources/PagerStripViewController.swift; sourceTree = "<group>"; };
 		41E6BECC207E64E900E158BA /* RemoteNetworkCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RemoteNetworkCell.swift; sourceTree = "<group>"; };
+		41DFC6C52100BAAF00EEC9E3 /* VLCDocumentClass.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = VLCDocumentClass.swift; path = Sources/VLCDocumentClass.swift; sourceTree = "<group>"; };
 		41EB91DB1F7BFF8400821AA5 /* VLCMetadata.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = VLCMetadata.h; sourceTree = "<group>"; };
 		41EB91DC1F7BFF8400821AA5 /* VLCMetadata.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = VLCMetadata.m; sourceTree = "<group>"; };
 		41F5C0761F41ED55005EB9CB /* VLCLibrarySearchDisplayDataSource.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = VLCLibrarySearchDisplayDataSource.h; path = Sources/VLCLibrarySearchDisplayDataSource.h; sourceTree = SOURCE_ROOT; };
@@ -1761,6 +1763,7 @@
 				7D6B08BB174A72A900A05173 /* VLCConstants.h */,
 				7DBBF180183AB3B80009A339 /* VLCAppDelegate.h */,
 				7DBBF181183AB3B80009A339 /* VLCAppDelegate.m */,
+				41DFC6C52100BAAF00EEC9E3 /* VLCDocumentClass.swift */,
 				7DF383B41BF20E4600D71A5C /* Network dialogs */,
 				7DBB788E1B305D8300894467 /* Keychain & random singletons */,
 				7D2339AB176DE70E008D223C /* Menu */,
@@ -3228,6 +3231,7 @@
 				DD8F84311B00EB3B0009138A /* VLCPlaybackController+MediaLibrary.m in Sources */,
 				418B144720179C00000447AA /* MediaCategoryViewController.swift in Sources */,
 				41EB91DD1F7BFF8500821AA5 /* VLCMetadata.m in Sources */,
+				41DFC6C62100BAAF00EEC9E3 /* VLCDocumentClass.swift in Sources */,
 				DD3EFF551BDEBCE500B68579 /* VLCLocalNetworkServiceBrowserDSM.m in Sources */,
 				7D37849A183A98D1009EE944 /* VLCPlaylistTableViewCell.m in Sources */,
 				8DD651C4208F786F0052EE68 /* VLCActionSheetSectionHeader.swift in Sources */,