All tough Ionic team don’t maintain cordova plugins because that is just open module,
I am just notifying this issue.
match.rangeAt(0) -> should be changed to match.range(at:0)
final class PhotoLibraryService {
::::
fileprivate func getDataFromURL(_ url: String) throws -> Data {
if url.hasPrefix(“data:”) {
guard let match = self.dataURLPattern.firstMatch(in: url, options: NSRegularExpression.MatchingOptions(rawValue: 0), range: NSMakeRange(0, url.characters.count)) else { // TODO: firstMatchInString seems to be slow for unknown reason
throw PhotoLibraryError.error(description: "The dataURL could not be parsed")
}
// **this is error line** [
let dataPos = match.rangeAt(0).length
// **this is error line** ]
let base64 = (url as NSString).substring(from: dataPos)
guard let decoded = Data(base64Encoded: base64, options: NSData.Base64DecodingOptions(rawValue: 0)) else {
throw PhotoLibraryError.error(description: "The dataURL could not be decoded")
}
return decoded
} else {
guard let nsURL = URL(string: url) else {
throw PhotoLibraryError.error(description: "The url could not be decoded: \(url)")
}
guard let fileContent = try? Data(contentsOf: nsURL) else {
throw PhotoLibraryError.error(description: "The url could not be read: \(url)")
}
return fileContent
}
}