So we have an app that has been working for a very long time. It is generating a PDF that has a section for crew members that will list details of each crew member including a signature image.
In iOS 15, the signature of the first crew member is being drawn for all crew members. Still working fine in other version of iOS.
Here is the code looping through each crew member:
for (ShiftCrew *crew in delegate.pcr.shift.shiftcrews) {
NSString *tempSignatureFile;
NSString *crewMemberName;
tempSignatureFile = [Utils getFullPathForFile:crew.signature.fileName];
crewMemberName = [NSString stringWithFormat:@"%@, %@", crew.lastName, crew.firstName];
nextY = [self handleCrewMember:pdfContext andCrewMember:crewMemberName andSignatureFile:tempSignatureFile andPosition:position andBaseY:nextY];
}
Code where the signatures etc are being drawn:
if ([signatureFile length] > 0) {
UIImage *myUIImage;
if (self.restricted) {
myUIImage = [UIImage imageNamed:@"Restricted Signature Image.png"];
}
else {
myUIImage = [EncryptionFunctions openEncryptedImage:signatureFile];
}
CGContextDrawImage (pdfContext, CGRectMake(238, nextY - 21, 114, 28), myUIImage.CGImage);
}
Utils getFullPathForFile just appends the passed in file name to the path to the Documents folder.
When I debug, I have verified that the signatureFile string is the correct path to the individual signature file image. To troubleshoot, right before CGContextDrawImage, I have inserted the following code to output the image files to an unencrypted png file:
NSString *filePath = [Utils getFullPathForFile:[NSString stringWithFormat:@"%@.png", crewMember]];
[UIImagePNGRepresentation(myUIImage) writeToFile:filePath atomically:YES];
The resulting files are correct and different from each other.
Administrator, admin:
account, Test:
What actually shows in the PDF:
A few things I have tried:
- Converting to CIImage and then to CGImage
- Using drawInRect on the UIImages instead of drawing from the CGImages.
- Hard coded the different images based on the crew member names.
It does print a different image if I hard code drawing the Restricted Signature Image.png file that is in the bundle for one of the crew members, but that's not too helpful in figuring out how to make this work so far.
I tried to create a new project that just generates a PDF that draws the two signature files. It works fine. I also in the same project, had a separate function that similarly generates a PDF with the two signature files and it also works fine. However, as this app is quite large and old, there is a lot of legacy code, so it is hard to extract and isolate the code that can reproduce this issue.
Anyone have any suggestions on troubleshooting this? Things to look into, or things to try?
What is driving me crazy is how this code:
NSString *filePath = [Utils getFullPathForFile:[NSString stringWithFormat:@"%@.png", crewMember]];
[UIImagePNGRepresentation(myUIImage) writeToFile:filePath atomically:YES];
CGContextDrawImage (pdfContext, signatureRect, myUIImage.CGImage);
Saves two different images, but draws the same image twice. And only in iOS 15.
Thanks for any help.