From 90e9b4a4f2bafc476e7eb1214fdce828a2a3bd92 Mon Sep 17 00:00:00 2001 From: Michael Kirk Date: Mon, 11 Dec 2017 13:51:36 -0500 Subject: [PATCH] WIP - send all video types --- Signal.xcodeproj/project.pbxproj | 6 +++++ .../attachments/MediaMessageView.swift | 10 ++++++++ .../attachments/SignalAttachment.swift | 12 ++++++--- .../ShareViewController.swift | 2 ++ .../SignalShareExtension-Bridging-Header.h | 25 ++++++++++--------- .../utils/NSItemProvider+OWS.h | 11 ++++++++ .../utils/NSItemProvider+OWS.m | 17 +++++++++++++ 7 files changed, 68 insertions(+), 15 deletions(-) create mode 100644 SignalShareExtension/utils/NSItemProvider+OWS.h create mode 100644 SignalShareExtension/utils/NSItemProvider+OWS.m diff --git a/Signal.xcodeproj/project.pbxproj b/Signal.xcodeproj/project.pbxproj index 3c480ff54..f1398c69e 100644 --- a/Signal.xcodeproj/project.pbxproj +++ b/Signal.xcodeproj/project.pbxproj @@ -291,6 +291,7 @@ 45CB2FA81CB7146C00E1B343 /* Launch Screen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 45CB2FA71CB7146C00E1B343 /* Launch Screen.storyboard */; }; 45CD81EF1DC030E7004C9430 /* SyncPushTokensJob.swift in Sources */ = {isa = PBXBuildFile; fileRef = 45CD81EE1DC030E7004C9430 /* SyncPushTokensJob.swift */; }; 45D231771DC7E8F10034FA89 /* SessionResetJob.swift in Sources */ = {isa = PBXBuildFile; fileRef = 45D231761DC7E8F10034FA89 /* SessionResetJob.swift */; }; + 45D55A231FDF08C6003767F0 /* NSItemProvider+OWS.m in Sources */ = {isa = PBXBuildFile; fileRef = 45D55A221FDF08C6003767F0 /* NSItemProvider+OWS.m */; }; 45DF5DF21DDB843F00C936C7 /* CompareSafetyNumbersActivity.swift in Sources */ = {isa = PBXBuildFile; fileRef = 45DF5DF11DDB843F00C936C7 /* CompareSafetyNumbersActivity.swift */; }; 45E547201FD755E700DFC09E /* AttachmentApprovalViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 45E5471F1FD755E700DFC09E /* AttachmentApprovalViewController.swift */; }; 45E5A6991F61E6DE001E4A8A /* MarqueeLabel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 45E5A6981F61E6DD001E4A8A /* MarqueeLabel.swift */; }; @@ -823,6 +824,8 @@ 45CB2FA71CB7146C00E1B343 /* Launch Screen.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; name = "Launch Screen.storyboard"; path = "Signal/src/util/Launch Screen.storyboard"; sourceTree = SOURCE_ROOT; }; 45CD81EE1DC030E7004C9430 /* SyncPushTokensJob.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SyncPushTokensJob.swift; sourceTree = ""; }; 45D231761DC7E8F10034FA89 /* SessionResetJob.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SessionResetJob.swift; sourceTree = ""; }; + 45D55A211FDF08C6003767F0 /* NSItemProvider+OWS.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "NSItemProvider+OWS.h"; sourceTree = ""; }; + 45D55A221FDF08C6003767F0 /* NSItemProvider+OWS.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "NSItemProvider+OWS.m"; sourceTree = ""; }; 45DF5DF11DDB843F00C936C7 /* CompareSafetyNumbersActivity.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CompareSafetyNumbersActivity.swift; sourceTree = ""; }; 45E282DE1D08E67800ADD4C8 /* gl */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = gl; path = translations/gl.lproj/Localizable.strings; sourceTree = ""; }; 45E282DF1D08E6CC00ADD4C8 /* id */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = id; path = translations/id.lproj/Localizable.strings; sourceTree = ""; }; @@ -1074,6 +1077,8 @@ children = ( 34480B341FD0929200BC14EF /* ShareAppExtensionContext.h */, 34480B351FD0929200BC14EF /* ShareAppExtensionContext.m */, + 45D55A211FDF08C6003767F0 /* NSItemProvider+OWS.h */, + 45D55A221FDF08C6003767F0 /* NSItemProvider+OWS.m */, ); path = utils; sourceTree = ""; @@ -2714,6 +2719,7 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + 45D55A231FDF08C6003767F0 /* NSItemProvider+OWS.m in Sources */, 4535186B1FC635DD00210559 /* ShareViewController.swift in Sources */, 34480B361FD0929200BC14EF /* ShareAppExtensionContext.m in Sources */, 3461284B1FD0B94000532771 /* SAELoadViewController.swift in Sources */, diff --git a/SignalMessaging/attachments/MediaMessageView.swift b/SignalMessaging/attachments/MediaMessageView.swift index 7bee41fcc..5360f329c 100644 --- a/SignalMessaging/attachments/MediaMessageView.swift +++ b/SignalMessaging/attachments/MediaMessageView.swift @@ -464,11 +464,21 @@ public class MediaMessageView: UIView, OWSAudioAttachmentPlayerDelegate { @objc public func playVideo() { guard let dataUrl = attachment.dataUrl else { + owsFail("\(self.logTag) attachment is missing dataUrl") return } + + let filePath = dataUrl.path + guard FileManager.default.fileExists(atPath: filePath) else { + owsFail("\(self.logTag) file at \(filePath) doesn't exist") + return + } + guard let videoPlayer = MPMoviePlayerController(contentURL: dataUrl) else { + owsFail("\(self.logTag) unable to build moview player controller") return } + videoPlayer.prepareToPlay() NotificationCenter.default.addObserver(forName: .MPMoviePlayerWillExitFullscreen, object: nil, queue: nil) { [weak self] _ in diff --git a/SignalMessaging/attachments/SignalAttachment.swift b/SignalMessaging/attachments/SignalAttachment.swift index d9af6d74b..868eda051 100644 --- a/SignalMessaging/attachments/SignalAttachment.swift +++ b/SignalMessaging/attachments/SignalAttachment.swift @@ -240,7 +240,13 @@ public class SignalAttachment: NSObject { } do { - let asset = AVURLAsset(url:mediaUrl) + let filePath = mediaUrl.path + guard FileManager.default.fileExists(atPath: filePath) else { + owsFail("asset at \(filePath) doesn't exist") + return nil + } + + let asset = AVURLAsset(url: mediaUrl) let generator = AVAssetImageGenerator(asset: asset) generator.appliesPreferredTrackTransform = true let cgImage = try generator.copyCGImage(at: CMTimeMake(0, 1), actualTime: nil) @@ -784,9 +790,9 @@ public class SignalAttachment: NSObject { if !isInputVideoValidOutputVideo(dataSource: dataSource, dataUTI: dataUTI) { // Most people won't hit this because we convert video when picked from the media picker - // But the current API allos sending videos that some Signal clients will not + // But the current API allows sending videos that some Signal clients will not // be able to view. (e.g. when picked from document picker) - owsFail("building video with invalid output, migrate to async API using compressVideoAsMp4") +// owsFail("building video with invalid output, migrate to async API using compressVideoAsMp4") } return newAttachment(dataSource: dataSource, diff --git a/SignalShareExtension/ShareViewController.swift b/SignalShareExtension/ShareViewController.swift index 4584b7b06..4eea4f4c0 100644 --- a/SignalShareExtension/ShareViewController.swift +++ b/SignalShareExtension/ShareViewController.swift @@ -488,6 +488,8 @@ public class ShareViewController: UINavigationController, ShareViewDelegate, SAE return promise } + // DO NOT COMMIT +// specificUTIType = "com.apple.quicktime-movie" let attachment = SignalAttachment.attachment(dataSource: dataSource, dataUTI: specificUTIType) return Promise(value: attachment) } diff --git a/SignalShareExtension/SignalShareExtension-Bridging-Header.h b/SignalShareExtension/SignalShareExtension-Bridging-Header.h index 42008bc60..8746dfe0a 100644 --- a/SignalShareExtension/SignalShareExtension-Bridging-Header.h +++ b/SignalShareExtension/SignalShareExtension-Bridging-Header.h @@ -6,19 +6,20 @@ #import // Separate iOS Frameworks from other imports. -#import "DebugLogger.h" -#import "Environment.h" -#import "OWSContactsManager.h" -#import "OWSContactsSyncing.h" -#import "OWSLogger.h" -#import "OWSMath.h" -#import "OWSPreferences.h" -#import "Release.h" +#import "NSItemProvider+OWS.h" #import "ShareAppExtensionContext.h" -#import "UIColor+OWS.h" -#import "UIFont+OWS.h" -#import "UIView+OWS.h" -#import "VersionMigrations.h" +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import #import #import #import diff --git a/SignalShareExtension/utils/NSItemProvider+OWS.h b/SignalShareExtension/utils/NSItemProvider+OWS.h new file mode 100644 index 000000000..aaa6f1d24 --- /dev/null +++ b/SignalShareExtension/utils/NSItemProvider+OWS.h @@ -0,0 +1,11 @@ +// +// Copyright (c) 2017 Open Whisper Systems. All rights reserved. +// + +typedef void (^OWSItemProviderDataCompletionHandler)(NSData *_Nullable data, NSError *_Nullable error); + +@implementation NSItemProvider (OWS) + +- (void)loadItemForTypeIdentifier:(NSString *)typeIdentifier options:(nullable NSDictionary *)options dataCompletionHandler:(nullable OWSItemProviderDataCompletionHandler)completionHandler; + +@end diff --git a/SignalShareExtension/utils/NSItemProvider+OWS.m b/SignalShareExtension/utils/NSItemProvider+OWS.m new file mode 100644 index 000000000..412de795a --- /dev/null +++ b/SignalShareExtension/utils/NSItemProvider+OWS.m @@ -0,0 +1,17 @@ +// +// Copyright (c) 2017 Open Whisper Systems. All rights reserved. +// + +#import "NSItemProvider+OWS.h" + +@implementation NSItemProvider (OWS) + +/* +// Only override drawRect: if you perform custom drawing. +// An empty implementation adversely affects performance during animation. +- (void)drawRect:(CGRect)rect { + // Drawing code +} +*/ + +@end