forked from mirrors/linphone-iphone
avoid copy files
This commit is contained in:
parent
20ef3e8f44
commit
77f8fd3809
10 changed files with 150 additions and 156 deletions
|
|
@ -28,7 +28,6 @@
|
|||
@protocol ChatConversationDelegate <NSObject>
|
||||
|
||||
- (BOOL)startImageUpload:(UIImage *)image assetId:(NSString *)phAssetId withQuality:(float)quality;
|
||||
- (BOOL)startFileUpload:(NSData *)data assetId:phAssetId;
|
||||
- (void)resendChat:(NSString *)message withExternalUrl:(NSString *)url;
|
||||
- (void)tableViewIsScrolling;
|
||||
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@
|
|||
#include "linphone/linphonecore.h"
|
||||
|
||||
@interface ChatConversationView
|
||||
: TPMultiLayoutViewController <HPGrowingTextViewDelegate, UICompositeViewDelegate, ImagePickerDelegate, ChatConversationDelegate,
|
||||
: TPMultiLayoutViewController <HPGrowingTextViewDelegate, UICompositeViewDelegate, ImagePickerDelegate, ChatConversationDelegate, UIDocumentPickerDelegate,
|
||||
UIDocumentInteractionControllerDelegate, UISearchBarDelegate, UIImageViewDeletableDelegate, UICollectionViewDataSource> {
|
||||
OrderedDictionary *imageQualities;
|
||||
BOOL scrollOnGrowingEnabled;
|
||||
|
|
@ -61,6 +61,7 @@
|
|||
@property (weak, nonatomic) IBOutlet UIIconButton *infoButton;
|
||||
@property (weak, nonatomic) IBOutlet UILabel *particpantsLabel;
|
||||
@property (nonatomic, strong) UIDocumentInteractionController *documentInteractionController;
|
||||
@property (nonatomic, strong) UIDocumentPickerViewController *documentPicker;
|
||||
@property NSMutableArray <UIImage *> *imagesArray;
|
||||
@property NSMutableArray <NSString *> *assetIdsArray;
|
||||
@property NSMutableArray <NSNumber *> *qualitySettingsArray;
|
||||
|
|
@ -80,7 +81,8 @@
|
|||
- (IBAction)onDeleteClick:(id)sender;
|
||||
- (IBAction)onEditionChangeClick:(id)sender;
|
||||
- (void)update;
|
||||
- (void)openResults:(NSString *) filePath;
|
||||
- (void)getIcloudFiles;
|
||||
- (void)openFile:(NSString *) filePath;
|
||||
- (void)clearMessageView;
|
||||
|
||||
@end
|
||||
|
|
|
|||
|
|
@ -233,38 +233,34 @@ static UICompositeViewDescription *compositeDescription = nil;
|
|||
|
||||
- (void)shareFile {
|
||||
NSUserDefaults *defaults = [[NSUserDefaults alloc] initWithSuiteName:groupName];
|
||||
|
||||
NSDictionary *dict = [defaults valueForKey:@"img"];
|
||||
NSDictionary *dictWeb = [defaults valueForKey:@"web"];
|
||||
NSDictionary *dictFile = [defaults valueForKey:@"mov"];
|
||||
NSDictionary *dictText = [defaults valueForKey:@"text"];
|
||||
NSDictionary *dict = [defaults valueForKey:@"photoData"];
|
||||
NSDictionary *dictFile = [defaults valueForKey:@"icloudData"];
|
||||
NSDictionary *dictUrl = [defaults valueForKey:@"url"];
|
||||
if (dict) {
|
||||
//share photo
|
||||
UIImage *image = [[UIImage alloc] initWithData:dict[@"nsData"]];
|
||||
//file shared from photo lib
|
||||
NSString *fileName = dict[@"url"];
|
||||
NSString *key = [[fileName componentsSeparatedByString:@"."] firstObject];
|
||||
NSMutableDictionary <NSString *, PHAsset *> * assetDict = [LinphoneUtils photoAssetsDictionary];
|
||||
[self chooseImageQuality:image assetId:[[assetDict objectForKey:dict[@"url"]] localIdentifier]];
|
||||
[defaults removeObjectForKey:@"img"];
|
||||
} else if (dictWeb) {
|
||||
//share url, if local file, then upload file
|
||||
NSString *url = dictWeb[@"url"];
|
||||
NSURL *fileUrl = [NSURL fileURLWithPath:url];
|
||||
if ([url hasPrefix:@"file"]) {
|
||||
//local file
|
||||
NSData *data = dictWeb[@"nsData"];
|
||||
[self confirmShare:data url:fileUrl text:nil assetId:nil];
|
||||
if ([fileName hasSuffix:@"JPG"] || [fileName hasSuffix:@"PNG"]) {
|
||||
UIImage *image = [[UIImage alloc] initWithData:dict[@"nsData"]];
|
||||
[self chooseImageQuality:image assetId:[[assetDict objectForKey:key] localIdentifier]];
|
||||
} else if ([fileName hasSuffix:@"MOV"]) {
|
||||
[self confirmShare:dict[@"nsData"] url:nil fileName:nil assetId:[[assetDict objectForKey:key] localIdentifier]];
|
||||
} else {
|
||||
[self confirmShare:nil url:nil text:url assetId:nil];
|
||||
LOGE(@"Unable to parse file %@",fileName);
|
||||
}
|
||||
[defaults removeObjectForKey:@"web"];
|
||||
}else if (dictFile) {
|
||||
//share file
|
||||
NSMutableDictionary <NSString *, PHAsset *> * assetDict = [LinphoneUtils photoAssetsDictionary];
|
||||
[self confirmShare:dictFile[@"nsData"] url:nil text:nil assetId:[[assetDict objectForKey:dictFile[@"url"]] localIdentifier]];
|
||||
[defaults removeObjectForKey:@"mov"];
|
||||
}else if (dictText) {
|
||||
//share text
|
||||
[self confirmShare:nil url:nil text:dictText[@"name"] assetId:nil];
|
||||
[defaults removeObjectForKey:@"text"];
|
||||
|
||||
[defaults removeObjectForKey:@"photoData"];
|
||||
} else if (dictFile) {
|
||||
NSString *fileName = dictFile[@"url"];
|
||||
[self confirmShare:dictFile[@"nsData"] url:nil fileName:fileName assetId:nil];
|
||||
|
||||
[defaults removeObjectForKey:@"icloudData"];
|
||||
} else if (dictUrl) {
|
||||
NSString *url = dictUrl[@"url"];
|
||||
[self confirmShare:nil url:url fileName:nil assetId:nil];
|
||||
|
||||
[defaults removeObjectForKey:@"url"];
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -358,15 +354,17 @@ static UICompositeViewDescription *compositeDescription = nil;
|
|||
});
|
||||
}
|
||||
|
||||
- (void)confirmShare:(NSData *)data url:(NSURL *)url text:(NSString *)text assetId:(NSString *)phAssetId {
|
||||
- (void)confirmShare:(NSData *)data url:(NSString *)url fileName:(NSString *)fileName assetId:(NSString *)phAssetId {
|
||||
DTActionSheet *sheet = [[DTActionSheet alloc] initWithTitle:NSLocalizedString(@"", nil)];
|
||||
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
|
||||
[sheet addButtonWithTitle:@"send to this friend"
|
||||
block:^() {
|
||||
if(phAssetId)
|
||||
[self startFileUpload:data assetId:phAssetId];
|
||||
if (url)
|
||||
[self sendMessage:url withExterlBodyUrl:nil withInternalURL:nil];
|
||||
else if (fileName)
|
||||
[self startFileUpload:data withName:fileName];
|
||||
else
|
||||
[self sendMessage:text withExterlBodyUrl:nil withInternalURL:nil];
|
||||
[self startFileUpload:data assetId:phAssetId];
|
||||
}];
|
||||
|
||||
[sheet addCancelButtonWithTitle:NSLocalizedString(@"Cancel", nil) block:nil];
|
||||
|
|
@ -635,9 +633,9 @@ static UICompositeViewDescription *compositeDescription = nil;
|
|||
return TRUE;
|
||||
}
|
||||
|
||||
- (BOOL)startFileUpload:(NSData *)data withUrl:(NSURL *)url {
|
||||
- (BOOL)startFileUpload:(NSData *)data withName:(NSString *)name {
|
||||
FileTransferDelegate *fileTransfer = [[FileTransferDelegate alloc] init];
|
||||
[fileTransfer uploadFile:data forChatRoom:_chatRoom withUrl:url];
|
||||
[fileTransfer uploadFile:data forChatRoom:_chatRoom withName:name];
|
||||
[_tableController scrollToBottom:true];
|
||||
return TRUE;
|
||||
}
|
||||
|
|
@ -909,7 +907,17 @@ void on_chat_room_conference_left(LinphoneChatRoom *cr, const LinphoneEventLog *
|
|||
[view.tableController scrollToBottom:true];
|
||||
}
|
||||
|
||||
- (void)openResults:(NSString *) filePath
|
||||
- (void)getIcloudFiles
|
||||
{
|
||||
_documentPicker = [[UIDocumentPickerViewController alloc] initWithDocumentTypes:@[@"public.data"]
|
||||
inMode:UIDocumentPickerModeImport];
|
||||
_documentPicker.delegate = self;
|
||||
|
||||
_documentPicker.modalPresentationStyle = UIModalPresentationFormSheet;
|
||||
[self presentViewController:_documentPicker animated:YES completion:nil];
|
||||
}
|
||||
|
||||
- (void)openFile:(NSString *) filePath
|
||||
{
|
||||
// Open the controller.
|
||||
_documentInteractionController = [UIDocumentInteractionController interactionControllerWithURL:[NSURL fileURLWithPath:filePath]];
|
||||
|
|
@ -923,6 +931,21 @@ void on_chat_room_conference_left(LinphoneChatRoom *cr, const LinphoneEventLog *
|
|||
}
|
||||
}
|
||||
|
||||
- (void)documentPicker:(UIDocumentPickerViewController *)controller didPickDocumentAtURL:(NSURL *)url {
|
||||
|
||||
NSFileCoordinator *fileCoordinator = [[NSFileCoordinator alloc] initWithFilePresenter:nil];
|
||||
[fileCoordinator coordinateReadingItemAtURL:url options:NSFileCoordinatorReadingWithoutChanges error:nil byAccessor:^(NSURL * _Nonnull newURL) {
|
||||
|
||||
NSString *fileName = [newURL lastPathComponent];
|
||||
NSData *data = [NSData dataWithContentsOfURL:newURL];
|
||||
|
||||
NSString *filePath = [[LinphoneManager cacheDirectory] stringByAppendingPathComponent:fileName];
|
||||
|
||||
[[NSFileManager defaultManager] createFileAtPath:filePath contents:data attributes:nil];
|
||||
[self openFile:filePath];
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)deleteImageWithAssetId:(NSString *)assetId {
|
||||
NSUInteger key = [_assetIdsArray indexOfObject:assetId];
|
||||
[_imagesArray removeObjectAtIndex:key];
|
||||
|
|
|
|||
|
|
@ -129,35 +129,6 @@
|
|||
}];
|
||||
}
|
||||
|
||||
- (void) loadVideoAsset: (AVAsset *) asset {
|
||||
// Calculate a time for the snapshot - I'm using the half way mark.
|
||||
CMTime duration = [asset duration];
|
||||
CMTime snapshot = CMTimeMake(duration.value / 2, duration.timescale);
|
||||
// Create a generator and copy image at the time.
|
||||
// I'm not capturing the actual time or an error.
|
||||
AVAssetImageGenerator *generator =
|
||||
[AVAssetImageGenerator assetImageGeneratorWithAsset:asset];
|
||||
CGImageRef imageRef = [generator copyCGImageAtTime:snapshot
|
||||
actualTime:nil
|
||||
error:nil];
|
||||
|
||||
UIImage *thumb = [UIImage imageWithCGImage:imageRef];
|
||||
CGImageRelease(imageRef);
|
||||
|
||||
UIGraphicsBeginImageContext(videoDefaultSize);
|
||||
[thumb drawInRect:CGRectMake(0, 0, videoDefaultSize.width, videoDefaultSize.height)];
|
||||
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
|
||||
UIGraphicsEndImageContext();
|
||||
|
||||
[self loadImageAsset:nil image:image];
|
||||
|
||||
// put the play button in the top
|
||||
CGRect newFrame = _playButton.frame;
|
||||
newFrame.origin.x = _finalImage.frame.origin.x/2;
|
||||
newFrame.origin.y = _finalImage.frame.origin.y/2;
|
||||
_playButton.frame = newFrame;
|
||||
}
|
||||
|
||||
- (void) loadFileAsset {
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
_fileName.hidden = NO;
|
||||
|
|
@ -212,7 +183,9 @@
|
|||
if (_messageImageView.image == nil) {
|
||||
[_messageImageView startLoading];
|
||||
PHFetchResult<PHAsset *> *assets = [PHAsset fetchAssetsWithLocalIdentifiers:[NSArray arrayWithObject:localImage] options:nil];
|
||||
UIImage *img = [chatTableView.imagesInChatroom objectForKey:localImage];
|
||||
UIImage *img = nil;
|
||||
|
||||
img = [chatTableView.imagesInChatroom objectForKey:localImage];
|
||||
if (![assets firstObject])
|
||||
[self loadPlaceholder];
|
||||
PHAsset *asset = [assets firstObject];
|
||||
|
|
@ -221,23 +194,24 @@
|
|||
else
|
||||
[self loadAsset:asset];
|
||||
}
|
||||
} else if (localVideo) {
|
||||
}
|
||||
else if (localVideo) {
|
||||
if (_messageImageView.image == nil) {
|
||||
|
||||
[_messageImageView startLoading];
|
||||
PHFetchResult<PHAsset *> *assets = [PHAsset fetchAssetsWithLocalIdentifiers:[NSArray arrayWithObject:localVideo] options:nil];
|
||||
if([assets firstObject] .mediaType == PHAssetMediaTypeVideo) {
|
||||
[_messageImageView startLoading];
|
||||
UIImage *img = [chatTableView.imagesInChatroom objectForKey:localImage];
|
||||
if (![assets firstObject])
|
||||
[self loadPlaceholder];
|
||||
PHAsset *asset = [assets firstObject];
|
||||
if (img)
|
||||
[self loadImageAsset:asset image:img];
|
||||
else
|
||||
[self loadAsset:asset];
|
||||
}
|
||||
UIImage *img = nil;
|
||||
|
||||
img = [chatTableView.imagesInChatroom objectForKey:localVideo];
|
||||
if (![assets firstObject])
|
||||
[self loadPlaceholder];
|
||||
PHAsset *asset = [assets firstObject];
|
||||
if (img)
|
||||
[self loadImageAsset:asset image:img];
|
||||
else
|
||||
[self loadAsset:asset];
|
||||
}
|
||||
} else if (localFile) {
|
||||
}
|
||||
else if (localFile) {
|
||||
NSString *text = [NSString stringWithFormat:@"📎 %@",localFile];
|
||||
_fileName.text = text;
|
||||
[self loadFileAsset];
|
||||
|
|
@ -296,22 +270,23 @@
|
|||
[player play];
|
||||
}
|
||||
else {
|
||||
LOGE(@"Can't read video");
|
||||
[self fileErrorBlock];
|
||||
}
|
||||
}];
|
||||
}
|
||||
|
||||
- (IBAction)onOpenClick:(id)event {
|
||||
NSString *localFile = [LinphoneManager getMessageAppDataForKey:@"localfile" inMessage:self.message];
|
||||
NSString *filePath = [LinphoneManager documentFile:localFile];
|
||||
NSFileManager *fileManager = [NSFileManager defaultManager];
|
||||
|
||||
if ([fileManager fileExistsAtPath:filePath]) {
|
||||
ChatConversationView *view = VIEW(ChatConversationView);
|
||||
[view openResults:filePath];
|
||||
} else {
|
||||
[self fileErrorBlock];
|
||||
}
|
||||
ChatConversationView *view = VIEW(ChatConversationView);
|
||||
NSString *cachedFile = [LinphoneManager getMessageAppDataForKey:@"cachedfile" inMessage:self.message];
|
||||
if (cachedFile) {
|
||||
NSFileManager *fileManager = [NSFileManager defaultManager];
|
||||
if ([fileManager fileExistsAtPath:cachedFile]) {
|
||||
[view openFile:cachedFile];
|
||||
} else {
|
||||
[self fileErrorBlock];
|
||||
}
|
||||
} else
|
||||
[view getIcloudFiles];
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -357,6 +357,7 @@ static const CGFloat CELL_MESSAGE_Y_MARGIN = 52; // 44;
|
|||
CGSize fileSize = CGSizeMake(200, 80);
|
||||
size = [self getMediaMessageSizefromOriginalSize:fileSize withWidth:width];
|
||||
} else if (localVideo) {
|
||||
//TODO
|
||||
CGSize videoSize = CGSizeMake(320, 240);
|
||||
size = [self getMediaMessageSizefromOriginalSize:videoSize withWidth:width];
|
||||
size.height += CELL_MESSAGE_X_MARGIN;
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@
|
|||
@interface FileTransferDelegate : NSObject
|
||||
|
||||
- (void)upload:(UIImage *)image withassetId:(NSString *)phAssetId forChatRoom:(LinphoneChatRoom *)chatRoom withQuality:(float)quality;
|
||||
- (void)uploadFile:(NSData *)data forChatRoom:(LinphoneChatRoom *)chatRoom withUrl:(NSURL *)url;
|
||||
- (void)uploadFile:(NSData *)data forChatRoom:(LinphoneChatRoom *)chatRoom withName:(NSString *)name;
|
||||
- (void)uploadVideo:(NSData *)data withassetId:(NSString *)phAssetId forChatRoom:(LinphoneChatRoom *)chatRoom;
|
||||
- (void)cancel;
|
||||
- (BOOL)download:(LinphoneChatMessage *)message;
|
||||
|
|
|
|||
|
|
@ -170,8 +170,7 @@ static void linphone_iphone_file_transfer_recv(LinphoneChatMessage *message, con
|
|||
}];
|
||||
|
||||
} else {
|
||||
[[LinphoneManager.instance fileTransferDelegates] removeObject:thiz];
|
||||
LOGE(@"xxxxxxxxxx");
|
||||
[[LinphoneManager.instance fileTransferDelegates] removeObject:thiz]
|
||||
NSString *key = @"localfile" ;
|
||||
NSString *name =[NSString stringWithUTF8String:linphone_content_get_name(content)];
|
||||
|
||||
|
|
@ -179,12 +178,14 @@ static void linphone_iphone_file_transfer_recv(LinphoneChatMessage *message, con
|
|||
|
||||
//write file to path
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
NSString *filePath = [LinphoneManager documentFile:name];
|
||||
NSString *filePath = [[LinphoneManager cacheDirectory] stringByAppendingPathComponent:name];
|
||||
//NSString *filePath = [LinphoneManager documentFile:name];
|
||||
[[NSFileManager defaultManager] createFileAtPath:filePath
|
||||
contents:thiz.data
|
||||
attributes:nil];
|
||||
|
||||
[LinphoneManager setValueInMessageAppData:name forKey:key inMessage:message];
|
||||
[LinphoneManager setValueInMessageAppData:filePath forKey:@"cachedfile" inMessage:message];
|
||||
|
||||
[NSNotificationCenter.defaultCenter
|
||||
postNotificationName:kLinphoneFileTransferRecvUpdate
|
||||
|
|
@ -289,22 +290,12 @@ static LinphoneBuffer *linphone_iphone_file_transfer_send(LinphoneChatMessage *m
|
|||
}
|
||||
|
||||
- (void)uploadVideo:(NSData *)data withassetId:(NSString *)phAssetId forChatRoom:(LinphoneChatRoom *)chatRoom {
|
||||
NSString *name = [NSString stringWithFormat:@"%f.mov", [NSDate timeIntervalSinceReferenceDate]];
|
||||
NSString *name = [NSString stringWithFormat:@"IMG-%f.MOV", [NSDate timeIntervalSinceReferenceDate]];
|
||||
[self uploadData:data forChatRoom:chatRoom type:@"video" subtype:nil name:name key:@"localvideo" keyData:phAssetId qualityData:nil];
|
||||
}
|
||||
|
||||
- (void)uploadFile:(NSData *)data forChatRoom:(LinphoneChatRoom *)chatRoom withUrl:(NSURL *)url {
|
||||
NSString *name = [url lastPathComponent];
|
||||
//save file to Documents
|
||||
NSString *filePath = [LinphoneManager documentFile:name];
|
||||
[[NSFileManager defaultManager] createFileAtPath:filePath
|
||||
contents:[NSMutableData dataWithData:data]
|
||||
attributes:nil];
|
||||
|
||||
if ([[url pathExtension] isEqualToString:@"MOV"])
|
||||
[self uploadData:data forChatRoom:chatRoom type:@"video" subtype:nil name:name key:@"localvideo" keyData:name qualityData:nil];
|
||||
else
|
||||
[self uploadData:data forChatRoom:chatRoom type:@"file" subtype:nil name:name key:@"localfile" keyData:name qualityData:nil];
|
||||
- (void)uploadFile:(NSData *)data forChatRoom:(LinphoneChatRoom *)chatRoom withName:(NSString *)name {
|
||||
[self uploadData:data forChatRoom:chatRoom type:@"file" subtype:nil name:name key:@"localfile" keyData:name qualityData:nil];
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -4,6 +4,10 @@
|
|||
<dict>
|
||||
<key>aps-environment</key>
|
||||
<string>development</string>
|
||||
<key>com.apple.developer.icloud-container-identifiers</key>
|
||||
<array/>
|
||||
<key>com.apple.developer.ubiquity-kvstore-identifier</key>
|
||||
<string>$(TeamIdentifierPrefix)$(CFBundleIdentifier)</string>
|
||||
<key>com.apple.security.application-groups</key>
|
||||
<array>
|
||||
<string>group.belledonne-communications.linphone.widget</string>
|
||||
|
|
|
|||
|
|
@ -3531,6 +3531,9 @@
|
|||
com.apple.Push = {
|
||||
enabled = 1;
|
||||
};
|
||||
com.apple.iCloud = {
|
||||
enabled = 1;
|
||||
};
|
||||
};
|
||||
};
|
||||
5E3128FF20D7A37E00CF3AAE = {
|
||||
|
|
|
|||
|
|
@ -20,34 +20,35 @@ static NSString* groupName = @"group.belledonne-communications.linphone";
|
|||
|
||||
- (void)didSelectPost {
|
||||
// This is called after the user selects Post. Do the upload of contentText and/or NSExtensionContext attachments.
|
||||
|
||||
BOOL support = TRUE;
|
||||
// Inform the host that we're done, so it un-blocks its UI. Note: Alternatively you could call super's -didSelectPost, which will similarly complete the extension context.
|
||||
for (NSExtensionItem *item in self.extensionContext.inputItems) {
|
||||
for (NSItemProvider *provider in item.attachments) {
|
||||
NSUserDefaults *defaults = [[NSUserDefaults alloc] initWithSuiteName:groupName];
|
||||
// TODO: Use [provider registeredTypeIdentifiersWithFileOptions:0]; to get all type identifiers of the provider instead of this if/else if structure
|
||||
support = TRUE;
|
||||
if ([provider hasItemConformingToTypeIdentifier:@"public.jpeg"]) {
|
||||
[self loadItem:provider typeIdentifier:@"public.jpeg" defaults:defaults key:@"img"];
|
||||
[self loadItem:provider typeIdentifier:@"public.jpeg" defaults:defaults];
|
||||
} else if ([provider hasItemConformingToTypeIdentifier:@"com.compuserve.gif"]) {
|
||||
[self loadItem:provider typeIdentifier:@"com.compuserve.gif" defaults:defaults key:@"img"];
|
||||
[self loadItem:provider typeIdentifier:@"com.compuserve.gif" defaults:defaults];
|
||||
} else if ([provider hasItemConformingToTypeIdentifier:@"public.url"]) {
|
||||
[self loadItem:provider typeIdentifier:@"public.url" defaults:defaults key:@"web"];
|
||||
[self loadItem:provider typeIdentifier:@"public.url" defaults:defaults];
|
||||
} else if ([provider hasItemConformingToTypeIdentifier:@"public.movie"]) {
|
||||
[self loadItem:provider typeIdentifier:@"public.movie" defaults:defaults key:@"mov"];
|
||||
} else if ([provider hasItemConformingToTypeIdentifier:@"public.plain-text"]) {
|
||||
[self loadItem:provider typeIdentifier:@"public.plain-text" defaults:defaults key:@"text"];
|
||||
} else if ([provider hasItemConformingToTypeIdentifier:@"com.adobe.pdf"]) {
|
||||
[self loadItem:provider typeIdentifier:@"com.adobe.pdf" defaults:defaults key:@"web"];
|
||||
}
|
||||
/*else if ([provider hasItemConformingToTypeIdentifier:@"public.png"]) {
|
||||
[self loadItem:provider typeIdentifier:@"public.png" defaults:defaults key:@"img"];
|
||||
}*/
|
||||
else{
|
||||
[self loadItem:provider typeIdentifier:@"public.movie" defaults:defaults];
|
||||
} else if ([provider hasItemConformingToTypeIdentifier:@"com.apple.mapkit.map-item"]) {
|
||||
[self loadItem:provider typeIdentifier:@"com.apple.mapkit.map-item" defaults:defaults];
|
||||
} else if ([provider hasItemConformingToTypeIdentifier:@"com.adobe.pdf"]) {
|
||||
[self loadItem:provider typeIdentifier:@"com.adobe.pdf" defaults:defaults];
|
||||
} else if ([provider hasItemConformingToTypeIdentifier:@"public.png"]) {
|
||||
[self loadItem:provider typeIdentifier:@"public.png" defaults:defaults];
|
||||
} else{
|
||||
NSLog(@"Unkown itemprovider = %@", provider);
|
||||
[self.extensionContext completeRequestReturningItems:@[] completionHandler:nil];
|
||||
support = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!support)
|
||||
[self.extensionContext completeRequestReturningItems:@[] completionHandler:nil];
|
||||
}
|
||||
|
||||
- (NSArray *)configurationItems {
|
||||
|
|
@ -55,52 +56,47 @@ static NSString* groupName = @"group.belledonne-communications.linphone";
|
|||
return @[];
|
||||
}
|
||||
|
||||
- (void)loadItem:(NSItemProvider *)provider typeIdentifier:(NSString *)typeIdentifier defaults:(NSUserDefaults *)defaults key:(NSString *)key {
|
||||
- (void)loadItem:(NSItemProvider *)provider typeIdentifier:(NSString *)typeIdentifier defaults:(NSUserDefaults *)defaults
|
||||
{
|
||||
[provider loadItemForTypeIdentifier:typeIdentifier options:nil completionHandler:^(id<NSSecureCoding> _Nullable item, NSError * _Null_unspecified error) {
|
||||
if([(NSObject*)item isKindOfClass:[NSDictionary class]]) {
|
||||
/*if([(NSObject*)item isKindOfClass:[NSDictionary class]]) {
|
||||
NSDictionary *dico = (NSDictionary *)item;
|
||||
if (dico) {
|
||||
return;
|
||||
}
|
||||
} else if([(NSObject*)item isKindOfClass:[NSURL class]]) {
|
||||
}*/
|
||||
if([(NSObject*)item isKindOfClass:[NSURL class]]) {
|
||||
NSURL *url = (NSURL *)item;
|
||||
NSData *nsData = [NSData dataWithContentsOfURL:url];
|
||||
|
||||
if (nsData) {
|
||||
// We get the corresponding PHAsset identifier so we can display the image in the app without having to duplicate it.
|
||||
NSString *imgPath = url.path;
|
||||
NSString *filename;
|
||||
for ( NSString *comp in [imgPath componentsSeparatedByString:@"/"] ) {
|
||||
if ([comp containsString:@"IMG_"]) {
|
||||
filename = [[comp componentsSeparatedByString:@"."] firstObject];
|
||||
break;
|
||||
}
|
||||
NSString *filename = [imgPath lastPathComponent];
|
||||
if([imgPath containsString:@"var/mobile/Media/PhotoData"]) {
|
||||
// We get the corresponding PHAsset identifier so we can display the image in the app without having to duplicate it.
|
||||
NSDictionary *dict = @{@"nsData" : nsData,
|
||||
@"url" : filename};
|
||||
[defaults setObject:dict forKey:@"photoData"];
|
||||
} else if ([imgPath containsString:@"var/mobile/Library/Mobile Documents/com~apple~CloudDocs"]) {
|
||||
// shared files from icloud drive
|
||||
NSDictionary *dict = @{@"nsData" : nsData,
|
||||
@"url" : filename};
|
||||
[defaults setObject:dict forKey:@"icloudData"];
|
||||
}else {
|
||||
//Others
|
||||
NSDictionary *dict = @{@"url" : [url absoluteString]};
|
||||
[defaults setObject:dict forKey:@"url"];
|
||||
}
|
||||
NSDictionary *dict = @{@"nsData" : nsData,
|
||||
@"url" : filename};
|
||||
[defaults setObject:dict forKey:key];
|
||||
} else {
|
||||
NSLog(@"NSExtensionItem Error, provider = %@", provider);
|
||||
[self.extensionContext completeRequestReturningItems:@[] completionHandler:nil];
|
||||
}
|
||||
} else {
|
||||
//share text
|
||||
NSDictionary *dict = @{@"url" : self.contentText};
|
||||
[defaults setObject:dict forKey:@"url"];
|
||||
}
|
||||
else if ([(NSObject*)item isKindOfClass:[UIImage class]]) {
|
||||
NSLog(@"SHARED PHOTO UIIMAGE");
|
||||
NSData *imgData = UIImagePNGRepresentation((UIImage*)item);
|
||||
if (imgData) {
|
||||
NSDictionary *dict = @{@"nsData" : imgData,
|
||||
};
|
||||
[defaults setObject:dict forKey:key];
|
||||
} else {
|
||||
NSLog(@"NSExtensionItem Error, provider = %@", provider);
|
||||
[self.extensionContext completeRequestReturningItems:@[] completionHandler:nil];
|
||||
}
|
||||
}
|
||||
else {
|
||||
NSLog(@"SHARED PHOTO OTHER");
|
||||
NSDictionary *dict = @{@"name" : self.contentText};
|
||||
[defaults setObject:dict forKey:key];
|
||||
}
|
||||
|
||||
|
||||
UIResponder *responder = self;
|
||||
while (responder != nil) {
|
||||
if ([responder respondsToSelector:@selector(openURL:)]) {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue