@@ -5,84 +5,96 @@ import UIKit
55import UniformTypeIdentifiers
66
77class ActionViewController : UIViewController {
8-
8+
9+ required init ? ( coder: NSCoder ) {
10+ super. init ( coder: coder)
11+ setupSentry ( )
12+ }
13+
14+ override init ( nibName nibNameOrNil: String ? , bundle nibBundleOrNil: Bundle ? ) {
15+ super. init ( nibName: nibNameOrNil, bundle: nibBundleOrNil)
16+ setupSentry ( )
17+ }
18+
19+ private func setupSentry( ) {
20+ // For this extension we need a specific configuration set, therefore we do not use the shared sample initializer
21+ SentrySDK . start { options in
22+ options. dsn = SentrySDKWrapper . defaultDSN
23+ options. debug = true
24+
25+ // App Hang Tracking must be enabled, but should not be installed
26+ options. enableAppHangTracking = true
27+ }
28+ }
29+
930 override func viewDidLoad( ) {
1031 super. viewDidLoad ( )
11-
12- // Setup view first
13- view. backgroundColor = . systemBackground
14-
15- // Setup Sentry SDK
16- setupSentrySDK ( )
17-
18- // Display ANR status
19- setupStatusLabel ( )
32+
33+ setupUI ( )
2034 }
21-
22- private func setupSentrySDK( ) {
23- SentrySDKWrapper . shared. startSentry ( )
24-
25- // Small delay to ensure SDK is initialized
26- DispatchQueue . main. asyncAfter ( deadline: . now( ) + 0.1 ) {
27- self . checkANRStatus ( )
28- }
35+
36+ func setupUI( ) {
37+ view. backgroundColor = . systemBackground
38+
39+ setupDoneButton ( )
40+ setupStatusChecklist ( )
2941 }
30-
31- private func checkANRStatus( ) {
32- // Verify ANR tracking is disabled
33- var anrInstalled = false
34- if SentrySDK . isEnabled {
35- let integrationNames = SentrySDKInternal . trimmedInstalledIntegrationNames ( )
36- anrInstalled = integrationNames. contains ( " ANRTracking " )
37- }
38-
39- if anrInstalled {
40- print ( " ❌ ERROR: ANR tracking should be disabled in Action Extension but it's enabled! " )
41- } else {
42- print ( " ✅ ANR tracking is correctly disabled in Action Extension " )
43- }
44-
45- // Update label if view is still loaded
46- if view. window != nil {
47- updateStatusLabel ( anrInstalled: anrInstalled)
48- }
42+
43+ var isANRInstalled : Bool {
44+ return isSentryEnabled && SentrySDKInternal . trimmedInstalledIntegrationNames ( ) . contains ( " ANRTracking " )
4945 }
50-
51- private func setupStatusLabel( ) {
52- // Initial check - might show "checking..." if SDK not ready
53- var anrInstalled = false
54- if SentrySDK . isEnabled {
55- let integrationNames = SentrySDKInternal . trimmedInstalledIntegrationNames ( )
56- anrInstalled = integrationNames. contains ( " ANRTracking " )
57- }
58-
59- updateStatusLabel ( anrInstalled: anrInstalled)
46+
47+ var isSentryEnabled : Bool {
48+ SentrySDK . isEnabled
6049 }
61-
62- private func updateStatusLabel ( anrInstalled : Bool ) {
63- // Remove existing label if any
64- view . subviews . forEach { $0 . removeFromSuperview ( ) }
65-
66- let statusLabel = UILabel ( )
67- statusLabel . text = anrInstalled ? " ❌ ANR Enabled (ERROR!) " : " ✅ ANR Disabled "
68- statusLabel . textColor = anrInstalled ? . red : . green
69- statusLabel . font = . systemFont ( ofSize : 24 , weight : . bold )
70- statusLabel . textAlignment = . center
71- statusLabel . numberOfLines = 0
72- statusLabel . translatesAutoresizingMaskIntoConstraints = false
73-
74- view . addSubview ( statusLabel )
50+
51+ // MARK: - UI
52+
53+ func setupDoneButton ( ) {
54+ var configuration = UIButton . Configuration . borderedProminent ( )
55+ configuration . title = " Done "
56+ configuration . baseBackgroundColor = . systemBlue
57+ configuration . buttonSize = . large
58+
59+ let button = UIButton ( configuration : configuration )
60+ button . addTarget ( self , action : #selector ( doneAction ( _ : ) ) , for : . touchUpInside )
61+ view . addSubview ( button )
62+
63+ button . translatesAutoresizingMaskIntoConstraints = false
7564 NSLayoutConstraint . activate ( [
76- statusLabel. centerXAnchor. constraint ( equalTo: view. centerXAnchor) ,
77- statusLabel. centerYAnchor. constraint ( equalTo: view. centerYAnchor) ,
78- statusLabel. leadingAnchor. constraint ( greaterThanOrEqualTo: view. leadingAnchor, constant: 20 ) ,
79- statusLabel. trailingAnchor. constraint ( lessThanOrEqualTo: view. trailingAnchor, constant: - 20 )
65+ button. bottomAnchor. constraint ( equalTo: view. safeAreaLayoutGuide. bottomAnchor) ,
66+ button. leadingAnchor. constraint ( equalTo: view. safeAreaLayoutGuide. leadingAnchor, constant: 16 ) ,
67+ button. trailingAnchor. constraint ( equalTo: view. safeAreaLayoutGuide. trailingAnchor, constant: - 16 )
8068 ] )
8169 }
82-
83- @IBAction func done ( ) {
70+
71+ @objc func doneAction ( _ sender : UIButton ) {
8472 SentrySDK . capture ( message: " iOS-Swift-ActionExtension: done called " )
8573 let returnItems = extensionContext? . inputItems as? [ NSExtensionItem ] ?? [ ]
8674 extensionContext? . completeRequest ( returningItems: returnItems, completionHandler: nil )
8775 }
76+
77+ func setupStatusChecklist( ) {
78+ let stack = UIStackView ( )
79+ stack. axis = . vertical
80+ stack. spacing = 8
81+ view. addSubview ( stack)
82+
83+ stack. translatesAutoresizingMaskIntoConstraints = false
84+ NSLayoutConstraint . activate ( [
85+ stack. centerXAnchor. constraint ( equalTo: view. centerXAnchor) ,
86+ stack. centerYAnchor. constraint ( equalTo: view. centerYAnchor)
87+ ] )
88+
89+ let sdkStatusLabel = UILabel ( )
90+ sdkStatusLabel. text = isSentryEnabled ? " ✅ Sentry is enabled " : " ❌ Sentry is not enabled "
91+ sdkStatusLabel. textAlignment = . center
92+ stack. addArrangedSubview ( sdkStatusLabel)
93+
94+ let anrStatusLabel = UILabel ( )
95+ // We want the ANR integration to be disabled for share extensions due to false-positives
96+ anrStatusLabel. text = !isANRInstalled ? " ✅ ANR Tracking not installed " : " ❌ ANR Tracking installed "
97+ anrStatusLabel. textAlignment = . center
98+ stack. addArrangedSubview ( anrStatusLabel)
99+ }
88100}
0 commit comments