forked from mirrors/linphone-iphone
minor change to linphone extension to deal with images with no associated asset id
This commit is contained in:
parent
2ca758ff6e
commit
7e2b064c8c
3 changed files with 49 additions and 5 deletions
|
|
@ -49,6 +49,8 @@ typedef enum {
|
|||
+ (NSString *)durationToString:(int)duration;
|
||||
+ (NSString *)intervalToString:(NSTimeInterval)interval ;
|
||||
|
||||
+ (NSMutableDictionary <NSString *, PHAsset *> *)photoAssetsDictionary;
|
||||
|
||||
@end
|
||||
|
||||
@interface NSNumber (HumanReadableSize)
|
||||
|
|
|
|||
|
|
@ -55,6 +55,24 @@
|
|||
return [formatter stringFromTimeInterval:interval];
|
||||
}
|
||||
|
||||
|
||||
+ (NSMutableDictionary <NSString *, PHAsset *> *)photoAssetsDictionary {
|
||||
NSMutableDictionary <NSString *, PHAsset *> *assetDict = [NSMutableDictionary dictionary];
|
||||
|
||||
PHFetchOptions *options = [[PHFetchOptions alloc] init];
|
||||
[options setIncludeHiddenAssets:YES];
|
||||
[options setIncludeAllBurstAssets:YES];
|
||||
|
||||
PHFetchResult *fetchRes = [PHAsset fetchAssetsWithOptions:options];
|
||||
|
||||
for (PHAsset *asset in fetchRes) {
|
||||
NSString *key = [asset valueForKey:@"filename"];
|
||||
[assetDict setObject:asset forKey:[[key componentsSeparatedByString:@"."] firstObject]];
|
||||
}
|
||||
|
||||
return assetDict;
|
||||
}
|
||||
|
||||
+ (NSString *)timeToString:(time_t)time withFormat:(LinphoneDateFormat)format {
|
||||
NSString *formatstr;
|
||||
NSDate *todayDate = [[NSDate alloc] init];
|
||||
|
|
|
|||
|
|
@ -25,9 +25,11 @@ static NSString* groupName = @"group.belledonne-communications.linphone";
|
|||
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
|
||||
if ([provider hasItemConformingToTypeIdentifier:@"public.jpeg"]) {
|
||||
[self loadItem:provider typeIdentifier:@"public.jpeg" defaults:defaults key:@"img"];
|
||||
} else if ([provider hasItemConformingToTypeIdentifier:@"com.compuserve.gif"]) {
|
||||
[self loadItem:provider typeIdentifier:@"com.compuserve.gif" defaults:defaults key:@"img"];
|
||||
} else if ([provider hasItemConformingToTypeIdentifier:@"public.url"]) {
|
||||
[self loadItem:provider typeIdentifier:@"public.url" defaults:defaults key:@"web"];
|
||||
} else if ([provider hasItemConformingToTypeIdentifier:@"public.movie"]) {
|
||||
|
|
@ -55,11 +57,31 @@ static NSString* groupName = @"group.belledonne-communications.linphone";
|
|||
|
||||
- (void)loadItem:(NSItemProvider *)provider typeIdentifier:(NSString *)typeIdentifier defaults:(NSUserDefaults *)defaults key:(NSString *)key {
|
||||
[provider loadItemForTypeIdentifier:typeIdentifier options:nil completionHandler:^(id<NSSecureCoding> _Nullable item, NSError * _Null_unspecified error) {
|
||||
if([(NSObject*)item isKindOfClass:[NSURL class]]) {
|
||||
NSData *nsData = [NSData dataWithContentsOfURL:(NSURL*)item];
|
||||
if([(NSObject*)item isKindOfClass:[NSDictionary class]]) {
|
||||
NSDictionary *dico = (NSDictionary *)item;
|
||||
if (dico) {
|
||||
return;
|
||||
}
|
||||
} else if([(NSObject*)item isKindOfClass:[NSURL class]]) {
|
||||
NSURL *url = (NSURL *)item;
|
||||
NSData *nsData = [NSData dataWithContentsOfURL:url];
|
||||
if (nsData) {
|
||||
NSDictionary *dict = @{@"nsData" : nsData,
|
||||
@"url" : [(NSURL*)item absoluteString]};
|
||||
NSDictionary *dict;
|
||||
// We get the corresponding PHAsset identifier so we can display the image in the app without having to duplicate it.
|
||||
NSString *imgPath = url.path;
|
||||
if ([imgPath hasPrefix:@"/var/mobile/Media/"] && ![imgPath containsString:@"OutgoingTemp"]) { // The image comes from the photos app
|
||||
NSString *filename;
|
||||
for ( NSString *comp in [imgPath componentsSeparatedByString:@"/"] ) {
|
||||
if ([comp containsString:@"IMG_"]) {
|
||||
filename = [[comp componentsSeparatedByString:@"."] firstObject];
|
||||
break;
|
||||
}
|
||||
}
|
||||
dict = @{@"nsData" : nsData,
|
||||
@"url" : filename};
|
||||
} else {
|
||||
dict = @{@"nsData" : nsData};
|
||||
}
|
||||
[defaults setObject:dict forKey:key];
|
||||
} else {
|
||||
NSLog(@"NSExtensionItem Error, provider = %@", provider);
|
||||
|
|
@ -67,6 +89,7 @@ static NSString* groupName = @"group.belledonne-communications.linphone";
|
|||
}
|
||||
}
|
||||
else if ([(NSObject*)item isKindOfClass:[UIImage class]]) {
|
||||
NSLog(@"SHARED PHOTO UIIMAGE");
|
||||
NSData *imgData = UIImagePNGRepresentation((UIImage*)item);
|
||||
if (imgData) {
|
||||
NSDictionary *dict = @{@"nsData" : imgData,
|
||||
|
|
@ -78,6 +101,7 @@ static NSString* groupName = @"group.belledonne-communications.linphone";
|
|||
}
|
||||
}
|
||||
else {
|
||||
NSLog(@"SHARED PHOTO OTHER");
|
||||
NSDictionary *dict = @{@"name" : self.contentText};
|
||||
[defaults setObject:dict forKey:key];
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue