Skip to content

Commit 3db5320

Browse files
Merge pull request #132 from alinz/ios_image_processing_fix
Restores proper image handling for iOS
2 parents 02409d5 + b330e63 commit 3db5320

File tree

1 file changed

+3
-27
lines changed

1 file changed

+3
-27
lines changed

ios/ReactNativeShareExtension.m

Lines changed: 3 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ - (void)viewDidLoad {
6868
}
6969

7070
- (void)extractDataFromContext:(NSExtensionContext *)context withCallback:(void(^)(NSString *value, NSString* contentType, NSException *exception))callback {
71-
7271
@try {
7372
NSExtensionItem *item = [context.inputItems firstObject];
7473
NSArray *attachments = item.attachments;
@@ -100,31 +99,10 @@ - (void)extractDataFromContext:(NSExtensionContext *)context withCallback:(void(
10099
}];
101100
} else if (imageProvider) {
102101
[imageProvider loadItemForTypeIdentifier:IMAGE_IDENTIFIER options:nil completionHandler:^(id<NSSecureCoding> item, NSError *error) {
103-
104-
/**
105-
* Save the image to NSTemporaryDirectory(), which cleans itself tri-daily.
106-
* This is necessary as the iOS 11 screenshot editor gives us a UIImage, while
107-
* sharing from Photos and similar apps gives us a URL
108-
* Therefore the solution is to save a UIImage, either way, and return the local path to that temp UIImage
109-
* This path will be sent to React Native and can be processed and accessed RN side.
110-
**/
111-
112-
UIImage *sharedImage;
113-
NSString *filePath = [NSTemporaryDirectory() stringByAppendingPathComponent:@"RNSE_TEMP_IMG"];
114-
NSString *fullPath = [filePath stringByAppendingPathExtension:@"png"];
115-
116-
if ([(NSObject *)item isKindOfClass:[UIImage class]]){
117-
sharedImage = (UIImage *)item;
118-
}else if ([(NSObject *)item isKindOfClass:[NSURL class]]){
119-
NSURL* url = (NSURL *)item;
120-
NSData *data = [NSData dataWithContentsOfURL:url];
121-
sharedImage = [UIImage imageWithData:data];
122-
}
123-
124-
[UIImagePNGRepresentation(sharedImage) writeToFile:fullPath atomically:YES];
125-
102+
NSURL *url = (NSURL *)item;
103+
126104
if(callback) {
127-
callback(fullPath, [fullPath pathExtension], nil);
105+
callback([url absoluteString], [[[url absoluteString] pathExtension] lowercaseString], nil);
128106
}
129107
}];
130108
} else if (textProvider) {
@@ -148,6 +126,4 @@ - (void)extractDataFromContext:(NSExtensionContext *)context withCallback:(void(
148126
}
149127
}
150128

151-
152-
153129
@end

0 commit comments

Comments
 (0)