fluttercandies / flutter_image_compress

flutter image compress
MIT License
632 stars 215 forks source link

[iOS] Crash on CompressFileHandler #300

Open SleepyFoxer opened 3 months ago

SleepyFoxer commented 3 months ago

Version

1.1.3

Platforms

iOS

Device Model

iPhone 13 Pro Max(iOS 15.6.1)

flutter info

Flutter 2.10.5

How to reproduce?

From Crash analysis

Logs

Last Exception Backtrace:
0   CoreFoundation                  0x1926c5288 __exceptionPreprocess + 220 (NSException.m:200)
1   libobjc.A.dylib                 0x1ab3f5744 objc_exception_throw + 60 (objc-exception.mm:565)
2   Foundation                      0x193f56340 -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 204 (NSException.m:242)
3   Flutter                         0x105f1eea4 -[FlutterStandardTypedData initWithData:type:] + 276
4   Flutter                         0x105f1f18c +[FlutterStandardTypedData typedDataWithData:type:] + 52
5   flutter_image_compress          0x1055b432c -[CompressFileHandler handleMethodCall:result:] + 812 (CompressFileHandler.m:54)
6   flutter_image_compress          0x1055b5538 __47-[ImageCompressPlugin handleMethodCall:result:]_block_invoke + 164 (ImageCompressPlugin.m:0)
7   libdispatch.dylib               0x19232ae6c _dispatch_call_block_and_release + 32 (init.c:1517)
8   libdispatch.dylib               0x19232ca30 _dispatch_client_callout + 20 (object.m:560)
9   libdispatch.dylib               0x19232fb44 _dispatch_queue_override_invoke + 784 (inline_internal.h:2622)
10  libdispatch.dylib               0x19233e164 _dispatch_root_queue_drain + 396 (inline_internal.h:0)
11  libdispatch.dylib               0x19233e96c _dispatch_worker_thread2 + 164 (queue.c:6935)
12  libsystem_pthread.dylib         0x20402d080 _pthread_wqthread + 228 (pthread.c:2612)
13  libsystem_pthread.dylib         0x20402ce5c start_wqthread + 8 (:-1)

Example code (optional)

- (void)handleMethodCall:(FlutterMethodCall *)call result:(FlutterResult)result {

    NSArray *args = call.arguments;
    NSString *path = args[0];
    int minWidth = [args[1] intValue];
    int minHeight = [args[2] intValue];
    int quality = [args[3] intValue];
    int rotate = [args[4] intValue];

    int formatType = [args[6] intValue];
    BOOL keepExif = [args[7] boolValue];

    UIImage *img;

    NSURL *imageUrl = [NSURL fileURLWithPath:path];
    NSData *nsdata = [NSData dataWithContentsOfURL:imageUrl];

    NSString *imageType = [self mimeTypeByGuessingFromData:nsdata];

    //  NSLog(@" nsdata length: %@", imageType);

    SDImageWebPCoder *webPCoder = [SDImageWebPCoder sharedCoder];
    [[SDImageCodersManager sharedManager] addCoder:webPCoder];

    if([imageType  isEqual: @"image/webp"]) {
    img = [[SDImageWebPCoder sharedCoder] decodedImageWithData:nsdata options:nil];
    } else {
        img = [UIImage imageWithData:nsdata];
    }

    NSData *data = [CompressHandler compressWithUIImage:img minWidth:minWidth minHeight:minHeight quality:quality rotate:rotate format:formatType];

    if (keepExif) {
        SYMetadata *metadata = [SYMetadata metadataWithFileURL:[NSURL fileURLWithPath:path]];
        metadata.orientation = @0;
        data = [SYMetadata dataWithImageData:data andMetadata:metadata];
    }

    result([FlutterStandardTypedData typedDataWithBytes:data]);
}

The error points to the last line.

dev3-tech commented 2 months ago

i also got same error