'ZXingObjC error in React Native, stringByReplacingPercentEscapesUsingEncoding: is deprecated

The build fails because of this error

CompileC /var/root/Library/Developer/Xcode/DerivedData/printapp3-bdgcuaoitzijpkgdxzcqqilqaxei/Build/Intermediates.noindex/ZXingObjC.build/Debug-iphonesimulator/ZXingObjC-iOS.build/Objects-normal/x86_64/ZXResultParser.o /Users/master/Desktop/biolime/cfprint/node_modules/react-native-bluetooth-escpos-printer/ios/ZXingObjC-3.2.2/ZXingObjC/client/result/ZXResultParser.m normal x86_64 objective-c com.apple.compilers.llvm.clang.1_0.compiler (in target 'ZXingObjC-iOS' from project 'ZXingObjC') (1 failure)

In Xcode as you see in screenshot below show the error with this line of code

Screen Shot 2022-04-21 at 3 53 18 AM (2)

/Users/app/node_modules/react-native-bluetooth-escpos-printer/ios/ZXingObjC-3.2.2/ZXingObjC/client/result/ZXResultParser.m:252:20: 'stringByReplacingPercentEscapesUsingEncoding:' is deprecated: first deprecated in iOS 9.0 - Use -stringByRemovingPercentEncoding instead, which always uses the recommended UTF-8 encoding.

Can please someone assist me with the objective-c part

+ (NSString *)urlDecode:(NSString *)encoded {
  NSString *result = [encoded stringByReplacingOccurrencesOfString:@"+" withString:@" "];
  result = [result stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
  return result;
}

When I replace

result = [result stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

with

result = [result stringByRemovingPercentEncoding:NSUTF8StringEncoding];

I face this error

/Users/app/node_modules/react-native-bluetooth-escpos-printer/ios/ZXingObjC-3.2.2/ZXingObjC/client/result/ZXResultParser.m:252:20: No visible @interface for 'NSString' declares the selector 'stringByRemovingPercentEncoding:'



Solution 1:[1]

stringByRemovingPercentEncoding

does not take any parameters. Just call it on the string you want to affect and it will return an NSString * with the result:

result = [result stringByRemovingPercentEncoding];

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Ric Perrott