bamlab/react-native-image-resizer

[iOS] No matching function for call to 'transformImage'

ohayou12 opened this issue · 14 comments

run archive receive an error

error details:

No matching function for call to 'transformImage'

Candidate function not viable: no known conversion from 'NSNumber * _Nonnull const __strong' to 'BOOL' (aka 'signed char') for 8th argument

environment

"@bam.tech/react-native-image-resizer": "^3.0.3",

System:
    OS: macOS 12.4
    CPU: (8) x64 Intel(R) Core(TM) i7-4770HQ CPU @ 2.20GHz
    Memory: 3.28 GB / 16.00 GB
    Shell: 5.8.1 - /bin/zsh
  Binaries:
    Node: 14.17.0 - /var/folders/j5/mpyv7n8j7_x9cvfk07zk11hm0000gn/T/yarn--1666575782013-0.44907134180783537/node
    Yarn: 1.22.19 - /var/folders/j5/mpyv7n8j7_x9cvfk07zk11hm0000gn/T/yarn--1666575782013-0.44907134180783537/yarn
    npm: 6.14.13 - /usr/local/bin/npm
    Watchman: Not Found
  Managers:
    CocoaPods: 1.11.3 - /Users/ohayou/.rvm/gems/ruby-3.1.2/bin/pod
  SDKs:
    iOS SDK:
      Platforms: DriverKit 21.4, iOS 15.5, macOS 12.3, tvOS 15.4, watchOS 8.5
    Android SDK: Not Found
  IDEs:
    Android Studio: 2020.3 AI-203.7717.56.2031.7935034
    Xcode: 13.4.1/13F100 - /usr/bin/xcodebuild
  Languages:
    Java: 11.0.11 - /usr/bin/javac
  npmPackages:
    @react-native-community/cli: Not Found
    react: 17.0.1 => 17.0.1 
    react-native: 0.64.1 => 0.64.1 
    react-native-macos: Not Found
  npmGlobalPackages:
    *react-native*: Not Found

variable keepMeta need a Bool in 53 line, but receive a NSNumber

NSDictionary * transformImage(UIImage *image,
NSString * originalPath,
int rotation,
CGSize newSize,
NSString* fullPath,
NSString* format,
int quality,
BOOL keepMeta,
NSDictionary* options)

- (void)createResizedImage:(NSString *)uri width:(double)width height:(double)height format:(NSString *)format quality:(double)quality mode:(NSString *)mode onlyScaleDown:(BOOL)onlyScaleDown rotation:(nonnull NSNumber *)rotation outputPath:(NSString *)outputPath keepMeta:(nonnull NSNumber *)keepMeta resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject {
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
@try {
CGSize newSize = CGSizeMake(width, height);
//Set image extension
NSString *extension = @"jpg";
if ([format isEqualToString:@"PNG"]) {
extension = @"png";
}
NSString* fullPath;
@try {
fullPath = generateFilePath(extension, outputPath);
} @catch (NSException *exception) {
[NSException raise:moduleName format:@"Invalid output path."];
}
NSURL * fileURL = [[NSURL alloc] initWithString:uri];
NSError *err;
if ([fileURL checkResourceIsReachableAndReturnError:&err] == NO){
[NSException raise:moduleName format:@"Image uri invalid."];
}
NSData * imageData = [NSData dataWithContentsOfURL:fileURL];
UIImage *image;
image = [UIImage imageWithData:imageData];
NSDictionary * response = transformImage(image, uri, [rotation integerValue], newSize, fullPath, format, (int)quality, keepMeta, @{@"mode": mode, @"onlyScaleDown": [NSNumber numberWithBool:onlyScaleDown]});
resolve(response);
} @catch (NSException *exception) {
RCTLogError([NSString stringWithFormat:@"Code : %@ / Message : %@", exception.name, exception.reason]);
reject(exception.name, exception.reason, nil);
}
});
}

Hi @ohayou12 ,

Can you provide me an example.

This is what I tried on my side in the example project with last version :

let result = await ImageResizer.createResizedImage(
        image.uri,
        sizeTarget,
        sizeTarget,
        'JPEG',
        100,
        undefined,
        undefined,
        true // keepMeta true, same result with false
      );

And I had no error ...

@ohayou12
Ok, I think the problem is that I did not keep the default value of keepMeta during the migration.

I fixed it in #343.
It is deployed now on 3.0.4. Can you use it and keep me up-to-date?

Hi @taboulot , I 've updated and getting the same error. Additionally, I copied the example you gave but the error remains.

any idea?

Hmmmm.

Can you provide me a repo with a reproducible example ?

i have resolve the probleme by changing in ImageResizer.m the type of keepMeta from (NSString *) to (BOOL)

in two line 19 and 24

for exemple in line 24
i changed
`

  • (void)createResizedImage:(NSString *)uri width:(double)width height:(double)height format:(NSString *)format quality:(double)quality mode:(NSString *)mode onlyScaleDown:(BOOL)onlyScaleDown rotation:(nonnull NSNumber *)rotation outputPath:(NSString *)outputPath keepMeta:(nonnull NSString *)keepMeta resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject {`

By

- (void)createResizedImage:(NSString *)uri width:(double)width height:(double)height format:(NSString *)format quality:(double)quality mode:(NSString *)mode onlyScaleDown:(BOOL)onlyScaleDown rotation:(nonnull NSNumber *)rotation outputPath:(NSString *)outputPath keepMeta:(BOOL)keepMeta resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject {

@skorchi

Since the 3.x.x version the type is not (NSString *) but (NSNumber *) 🧐

See :

RCT_REMAP_METHOD(createResizedImage, uri:(NSString *)uri width:(double)width height:(double)height format:(NSString *)format quality:(double)quality mode:(NSString *)mode onlyScaleDown:(BOOL)onlyScaleDown rotation:(nonnull NSNumber *)rotation outputPath:(NSString *)outputPath keepMeta:(nonnull NSNumber *)keepMeta resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject)
{
[self createResizedImage:uri width:width height:height format:format quality:quality mode:mode onlyScaleDown:onlyScaleDown rotation:rotation outputPath:outputPath keepMeta:keepMeta resolve:resolve reject:reject];
}
- (void)createResizedImage:(NSString *)uri width:(double)width height:(double)height format:(NSString *)format quality:(double)quality mode:(NSString *)mode onlyScaleDown:(BOOL)onlyScaleDown rotation:(nonnull NSNumber *)rotation outputPath:(NSString *)outputPath keepMeta:(nonnull NSNumber *)keepMeta resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject {
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{

@davidarnaub7

And Are you able to reproduce it in the example project of the repo?

@taboulot

i have the same problem, i fixed by changing the type of keepMeta by BOOL in line 19 and 24

@taboulot
in xcode, I run Product -> Archive, then I receive this error. It is normal if yarn ios is run.

keepMeta is a Bool at line 337, but NSNumber at line 53, which I think is probably due to the xcode version. Then I change keepMeta to true or false at line 53 and run Product -> Archive again and it works fine.


NSDictionary * response = transformImage(image, uri, [rotation integerValue], newSize, fullPath, format, (int)quality, keepMeta, @{@"mode": mode, @"onlyScaleDown": [NSNumber numberWithBool:onlyScaleDown]});

same here.

@ohayou12 can you create a PR to fix this?

@chj-damon Thank you for your contribution. Would you mind continuing the discussion in the PR ?

A fix has been published in 3.0.5.