question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

keepMeta is not working on iOS

See original GitHub issue

I want to keep metadata when resizing an image. I used ImageResizer.createResizedImage with keepMeta = true. However, it is not working on iOS.

As a result of the analysis, getImageMeta() function is not working. It returns before getting the metadata from an image URI.

NSMutableDictionary * getImageMeta(NSString * path)
{
    if([path hasPrefix:@"assets-library"]) {

        __block NSMutableDictionary* res = nil;

        ALAssetsLibraryAssetForURLResultBlock resultblock = ^(ALAsset *myasset)
        {
           // (1) here asynchronous processing
            NSDictionary *exif = [[myasset defaultRepresentation] metadata];
            res = [exif mutableCopy];

        };

        ALAssetsLibrary* assetslibrary = [[ALAssetsLibrary alloc] init];
        NSURL *url = [NSURL URLWithString:[path stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];

        [assetslibrary assetForURL:url resultBlock:resultblock failureBlock:^(NSError *error) { NSLog(@"error couldn't image from assets library"); }];

       // (2) result is returned before (1) is finished.
        return res;

    }

this issue can be prevented by using semaphore system.

environment

iPhoneSE 2generation (IOS 14.81) / iPhone12ProMax (iOS 15.1) react-native: 0.63.4 react-native-image-resizer: 1.4.5

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
ishikawa-takumicommented, Feb 23, 2022

@odexvy Yes, I have prevented this issue applying the following code. node_modules/react-native-image-resizer/ios/RCTImageResizer.m

NSMutableDictionary * getImageMeta(NSString * path)
{
    if([path hasPrefix:@"assets-library"] ) {

        __block NSMutableDictionary* res = nil;
        dispatch_semaphore_t semaphore = dispatch_semaphore_create(0);  
        @try {
            dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), ^{
                ALAssetsLibraryAssetForURLResultBlock resultblock = ^(ALAsset *myasset)
                {

                    NSDictionary *exif = [[myasset defaultRepresentation] metadata];
                    res = [exif mutableCopy];
                    dispatch_semaphore_signal(semaphore);

                };

                ALAssetsLibrary* assetslibrary = [[ALAssetsLibrary alloc] init];
                NSURL *url = [NSURL URLWithString:[path stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];

                [assetslibrary assetForURL:url resultBlock:resultblock failureBlock:^(NSError *error) { NSLog(@"error couldn't image from assets library"); }];
            });
        } 
        @finally {
            dispatch_time_t time = dispatch_time(DISPATCH_TIME_NOW, 3 * NSEC_PER_SEC);
            dispatch_semaphore_wait(semaphore, time);
            return res;
        }
    } else {
1reaction
odexvycommented, Feb 23, 2022

thank you very much @ishikawa-takumi 👍

Read more comments on GitHub >

github_iconTop Results From Across the Web

ios - Safari meta refresh not working with my iphone app
It seems like the meta refresh timer is running in the background and if Safari isn't in the foreground - it won't do...
Read more >
Fix Facebook Keeps Crashing on iPhone, iPad after iOS 16 ...
in this blog post, I'll help you to fix Facebook won't open on ipad/iPhone after the latest iOS update Or App Server &...
Read more >
Solved: Oculus App on iPhone crashing/not launching
Hi everyone, the team is working on this issue with the app that's causing a crash or failing to load after the update....
Read more >
Troubleshoot apps and features - Meta
To report a bug from the Meta Quest mobile app: Shake your phone until the Report a Problem screen appears. Tap Something Isn't...
Read more >
Supported Meta Tags - Apple Developer
Describes the Hypertext Markup Language (HTML) tags and properties that are supported by Safari and WebKit.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found