Skip to content

Commit

Permalink
Merge pull request #132 from alinz/ios_image_processing_fix
Browse files Browse the repository at this point in the history
Restores proper image handling for iOS
  • Loading branch information
AndrewHenderson authored Dec 19, 2018
2 parents 02409d5 + b330e63 commit 3db5320
Showing 1 changed file with 3 additions and 27 deletions.
30 changes: 3 additions & 27 deletions ios/ReactNativeShareExtension.m
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ - (void)viewDidLoad {
}

- (void)extractDataFromContext:(NSExtensionContext *)context withCallback:(void(^)(NSString *value, NSString* contentType, NSException *exception))callback {

@try {
NSExtensionItem *item = [context.inputItems firstObject];
NSArray *attachments = item.attachments;
Expand Down Expand Up @@ -100,31 +99,10 @@ - (void)extractDataFromContext:(NSExtensionContext *)context withCallback:(void(
}];
} else if (imageProvider) {
[imageProvider loadItemForTypeIdentifier:IMAGE_IDENTIFIER options:nil completionHandler:^(id<NSSecureCoding> item, NSError *error) {

/**
* Save the image to NSTemporaryDirectory(), which cleans itself tri-daily.
* This is necessary as the iOS 11 screenshot editor gives us a UIImage, while
* sharing from Photos and similar apps gives us a URL
* Therefore the solution is to save a UIImage, either way, and return the local path to that temp UIImage
* This path will be sent to React Native and can be processed and accessed RN side.
**/

UIImage *sharedImage;
NSString *filePath = [NSTemporaryDirectory() stringByAppendingPathComponent:@"RNSE_TEMP_IMG"];
NSString *fullPath = [filePath stringByAppendingPathExtension:@"png"];

if ([(NSObject *)item isKindOfClass:[UIImage class]]){
sharedImage = (UIImage *)item;
}else if ([(NSObject *)item isKindOfClass:[NSURL class]]){
NSURL* url = (NSURL *)item;
NSData *data = [NSData dataWithContentsOfURL:url];
sharedImage = [UIImage imageWithData:data];
}

[UIImagePNGRepresentation(sharedImage) writeToFile:fullPath atomically:YES];

NSURL *url = (NSURL *)item;

if(callback) {
callback(fullPath, [fullPath pathExtension], nil);
callback([url absoluteString], [[[url absoluteString] pathExtension] lowercaseString], nil);
}
}];
} else if (textProvider) {
Expand All @@ -148,6 +126,4 @@ - (void)extractDataFromContext:(NSExtensionContext *)context withCallback:(void(
}
}



@end

0 comments on commit 3db5320

Please sign in to comment.