Fix handling of file types in SAE.

This commit is contained in:
Matthew Chen 2018-02-15 13:34:00 -05:00
parent c2787341ae
commit 7ea1f3d926
5 changed files with 1 additions and 65 deletions

View file

@ -10,7 +10,6 @@
2AE2882E4C2B96BFFF9EE27C /* Pods_SignalShareExtension.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 0F94C85CB0B235DA37F68ED0 /* Pods_SignalShareExtension.framework */; };
340B02BA1FA0D6C700F9CFEC /* ConversationViewItemTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 340B02B91FA0D6C700F9CFEC /* ConversationViewItemTest.m */; };
340CB2271EAC25820001CAA1 /* UpdateGroupViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 340CB2261EAC25820001CAA1 /* UpdateGroupViewController.m */; };
341F1BEE20111A5300111571 /* NSItemProvider+OWS.m in Sources */ = {isa = PBXBuildFile; fileRef = 341F1BEC20111A5200111571 /* NSItemProvider+OWS.m */; };
341F2C0F1F2B8AE700D07D6B /* DebugUIMisc.m in Sources */ = {isa = PBXBuildFile; fileRef = 341F2C0E1F2B8AE700D07D6B /* DebugUIMisc.m */; };
3430FE181F7751D4000EC51B /* GiphyAPI.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3430FE171F7751D4000EC51B /* GiphyAPI.swift */; };
34330A5A1E7875FB00DF2FB9 /* fontawesome-webfont.ttf in Resources */ = {isa = PBXBuildFile; fileRef = 34330A591E7875FB00DF2FB9 /* fontawesome-webfont.ttf */; };
@ -485,8 +484,6 @@
340CB2251EAC25820001CAA1 /* UpdateGroupViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UpdateGroupViewController.h; sourceTree = "<group>"; };
340CB2261EAC25820001CAA1 /* UpdateGroupViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = UpdateGroupViewController.m; sourceTree = "<group>"; };
341458471FBE11C4005ABCF9 /* fa */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = fa; path = translations/fa.lproj/Localizable.strings; sourceTree = "<group>"; };
341F1BEC20111A5200111571 /* NSItemProvider+OWS.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSItemProvider+OWS.m"; sourceTree = "<group>"; };
341F1BED20111A5300111571 /* NSItemProvider+OWS.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSItemProvider+OWS.h"; sourceTree = "<group>"; };
341F2C0D1F2B8AE700D07D6B /* DebugUIMisc.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DebugUIMisc.h; sourceTree = "<group>"; };
341F2C0E1F2B8AE700D07D6B /* DebugUIMisc.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = DebugUIMisc.m; sourceTree = "<group>"; };
3430FE171F7751D4000EC51B /* GiphyAPI.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = GiphyAPI.swift; sourceTree = "<group>"; };
@ -1100,8 +1097,6 @@
34480B2F1FD0921000BC14EF /* utils */ = {
isa = PBXGroup;
children = (
341F1BED20111A5300111571 /* NSItemProvider+OWS.h */,
341F1BEC20111A5200111571 /* NSItemProvider+OWS.m */,
34480B341FD0929200BC14EF /* ShareAppExtensionContext.h */,
34480B351FD0929200BC14EF /* ShareAppExtensionContext.m */,
);
@ -2762,7 +2757,6 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
341F1BEE20111A5300111571 /* NSItemProvider+OWS.m in Sources */,
4535186B1FC635DD00210559 /* ShareViewController.swift in Sources */,
34480B361FD0929200BC14EF /* ShareAppExtensionContext.m in Sources */,
3461284B1FD0B94000532771 /* SAELoadViewController.swift in Sources */,

View file

@ -690,19 +690,12 @@ public class ShareViewController: UIViewController, ShareViewDelegate, SAEFailed
} else {
// It's unavoidable that we may sometimes receives data types that we
// don't know how to handle.
//
// See comments on NSItemProvider+OWS.h.
let unexpectedTypeError = ShareViewControllerError.assertionError(description: "unexpected value: \(String(describing: value))")
reject(unexpectedTypeError)
}
}
// See comments on NSItemProvider+OWS.h.
if srcUtiType == kUTTypeURL as String {
itemProvider.loadItem(forTypeIdentifier: srcUtiType, options: nil, completionHandler: loadCompletion)
} else {
itemProvider.loadData(forTypeIdentifier: srcUtiType, options: nil, completionHandler: loadCompletion)
}
itemProvider.loadItem(forTypeIdentifier: srcUtiType, options: nil, completionHandler: loadCompletion)
return promise.then { [weak self] (itemUrl: URL, utiType: String) -> Promise<SignalAttachment> in
guard let strongSelf = self else {

View file

@ -6,7 +6,6 @@
#import <UIKit/UIKit.h>
// Separate iOS Frameworks from other imports.
#import "NSItemProvider+OWS.h"
#import "ShareAppExtensionContext.h"
#import <SignalMessaging/DebugLogger.h>
#import <SignalMessaging/Environment.h>

View file

@ -1,26 +0,0 @@
//
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
//
NS_ASSUME_NONNULL_BEGIN
@interface NSItemProvider (OWS)
// NSItemProvider.loadItem(forTypeIdentifier:...) is unsafe to call from Swift,
// since it can yield values of arbitrary type. It has a highly unusual design
// in which its behavior depends on the _type_ of the completion handler.
// loadItem(forTypeIdentifier:...) tries to satisfy the expected type of the
// completion handler. This "hinting" only works in Objective-C. In Swift,
// The type of the completion handler must agree with the param type.
//
// Therefore we use an Objective-C category to hint to NSItemProvider that we
// prefer an instance of NSData.
//
// See: https://developer.apple.com/documentation/foundation/nsitemprovider/1403900-loaditemfortypeidentifier
- (void)loadDataForTypeIdentifier:(NSString *)typeIdentifier
options:(nullable NSDictionary *)options
completionHandler:(nullable NSItemProviderCompletionHandler)completionHandler;
@end
NS_ASSUME_NONNULL_END

View file

@ -1,24 +0,0 @@
//
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
//
#import "NSItemProvider+OWS.h"
NS_ASSUME_NONNULL_BEGIN
@implementation NSItemProvider (OWS)
- (void)loadDataForTypeIdentifier:(NSString *)typeIdentifier
options:(nullable NSDictionary *)options
completionHandler:(nullable NSItemProviderCompletionHandler)completionHandler
{
[self loadItemForTypeIdentifier:typeIdentifier
options:options
completionHandler:^(NSData *_Nullable item, NSError *__null_unspecified error) {
completionHandler(item, error);
}];
}
@end
NS_ASSUME_NONNULL_END