Skip to content
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

### Fixes

- Don't capture zero size screenshots ([#2459](https://github.com/getsentry/sentry-cocoa/pull/2459))
- Core data span status with error (#2439)

## 7.31.2
Expand Down
7 changes: 6 additions & 1 deletion Sources/Sentry/SentryScreenshot.m
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,12 @@ - (void)saveScreenShots:(NSString *)path

if ([window drawViewHierarchyInRect:window.bounds afterScreenUpdates:false]) {
UIImage *img = UIGraphicsGetImageFromCurrentImageContext();
[result addObject:UIImagePNGRepresentation(img)];
if (img.size.width > 0 || img.size.height > 0) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

m: Can we please add tests for this new functionality? As this code is not really testable you could extract this code into a method, expose it via a private category that you would have to add similar as we have it, for example, for SentryClient+Private.h, and then call it from tests. I can also push the basic solution to your branch if you want @krystofwoldrich.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can push the solution to this branch and I will work with that. It will definitely help me.

Besides exposing it with the private header. Are there any examples in the test on how to mock functions, likely I will have to mock UIGraphicsGetImageFromCurrentImageContext.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code was already testable. I added a test.

NSData *bytes = UIImagePNGRepresentation(img);
if (bytes && bytes.length > 0) {
Comment on lines +51 to +52
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

l: If the image has 0 height or width, it's already empty. I think we don't need to check for bytes && bytes.length > 0 here.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Its not the size of the view that makes the image 0 length, its not being able to render the image.

[result addObject:bytes];
}
}
}

UIGraphicsEndImageContext();
Expand Down