I'm trying to send data from an application Source to application Target. Everything works fine except the image part. When I encode the image as base64 and send it, the base64 code is truncated. I'm only getting the first 1024 characters.
Here is the code from Source application:
let uiimage = UIImage(data: selectedImageData!)
let uiimagebASE64 = uiimage!.jpegData(compressionQuality: 1)?.base64EncodedString() ?? ""
let strURL = "targetapp://x-callback-url/translate?x-success=sourceapp://x-callback-url/acceptTranslation&x-source=SourceApp&x-error=sourceapp://x-callback-url/translationError&word=Hello&username=\(username)&isPrivate=\(isPrivate)¬ificationsEnabled=\(notificationsEnabled)&previewIndex=\(previewIndex)&version=\(version)&selectedImage=\(uiimagebASE64)"
if let encoded = strURL.addingPercentEncoding(withAllowedCharacters: .urlFragmentAllowed),
let myURL = URL(string: encoded) {
print(myURL)
if (UIApplication.shared.canOpenURL(myURL)){
UIApplication.shared.open(myURL, options: [:], completionHandler: nil)
}
}
The code from target app :
func handleURL(_ url: URL) {
let parameters = url.queryParameters
let dataString = (parameters!["selectedImage"]!)
let dataStringDecoded = dataString.removingPercentEncoding!
let imageData = Data(base64Encoded: dataString)
let image = UIImage(data: imageData!)
...
I even deleted addingPercentEncoding
in the source app and removingPercentEncoding
in the target app. I'm getting the same problem.
How can I fix this problem? Is there a best solution to send image data from application A to B?