diff --git a/ios/ReactNativeShareExtension.m b/ios/ReactNativeShareExtension.m index f6a18ce5..ddf1e692 100644 --- a/ios/ReactNativeShareExtension.m +++ b/ios/ReactNativeShareExtension.m @@ -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; @@ -100,31 +99,10 @@ - (void)extractDataFromContext:(NSExtensionContext *)context withCallback:(void( }]; } else if (imageProvider) { [imageProvider loadItemForTypeIdentifier:IMAGE_IDENTIFIER options:nil completionHandler:^(id 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) { @@ -148,6 +126,4 @@ - (void)extractDataFromContext:(NSExtensionContext *)context withCallback:(void( } } - - @end