Skip to content

Commit b3b9593

Browse files
authored
fix: Nullability in SentrySwizzleWrapperHelper (#6970)
* fix: Nullability in SentrySwizzleWrapperHelper * Add test * Improvements
1 parent 9214f4c commit b3b9593

File tree

5 files changed

+29
-2
lines changed

5 files changed

+29
-2
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77
- Add attributes data to `SentryScope` (#6830)
88
- Add `SentryScope` attributes into log messages (#6834)
99

10+
### Fixes
11+
12+
- Fixes crash when null values are passed to `UIApplication sendAction:to:from:forEvent:` (#6970)
13+
1014
## 9.0.0
1115

1216
This changelog lists every breaking change. For a high-level overview and upgrade guidance, see the [migration guide](https://docs.sentry.io/platforms/apple/migration/).
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import SentrySampleShared
2+
import XCTest
3+
4+
final class UIApplicationSwizzleTests: XCTestCase {
5+
6+
// Tests for the crash first reported in https://github.com/getsentry/sentry-cocoa/issues/6966
7+
func testSendEvent() {
8+
let app = XCUIApplication()
9+
app.launchArguments.append(contentsOf: [
10+
SentrySDKOverrides.Other.disableSpotlight.rawValue
11+
])
12+
app.safelyLaunch()
13+
14+
app.buttons["UIApplication sendEmptyEvent"].tap()
15+
}
16+
17+
}

Samples/iOS-SwiftUI/iOS-SwiftUI/ContentView.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,10 @@ struct ContentView: View {
176176
Button(action: captureTransactionAction) {
177177
Text("Capture Transaction")
178178
}
179+
// This is used by a UI test since UIApplication.shared is nil in unit tests.
180+
Button("UIApplication sendEmptyEvent") {
181+
UIApplication.shared.sendAction(#selector(UIResponder.resignFirstResponder), to: nil, from: nil, for: nil)
182+
}
179183
Button(action: showTTD) {
180184
Text("Show TTD")
181185
}.sentryReplayUnmask()

Sources/Sentry/SentrySwizzleWrapperHelper.m

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88

99
@implementation SentrySwizzleWrapperHelper
1010

11-
+ (void)swizzle:(void (^)(SEL action, id target, id sender, UIEvent *event))callback;
11+
+ (void)swizzle:(void (^)(SEL action, _Nullable id target, _Nullable id sender,
12+
UIEvent *_Nullable event))callback;
1213
{
1314
# pragma clang diagnostic push
1415
# pragma clang diagnostic ignored "-Wshadow"

Sources/Sentry/include/SentrySwizzleWrapperHelper.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ NS_ASSUME_NONNULL_BEGIN
88

99
@interface SentrySwizzleWrapperHelper : NSObject
1010

11-
+ (void)swizzle:(void (^)(SEL action, id target, id sender, UIEvent *event))callback;
11+
+ (void)swizzle:(void (^)(SEL action, _Nullable id target, _Nullable id sender,
12+
UIEvent *_Nullable event))callback;
1213

1314
@end
1415

0 commit comments

Comments
 (0)