Skip to content

Commit 0965325

Browse files
committed
WIP
1 parent 25707b5 commit 0965325

File tree

2 files changed

+39
-75
lines changed

2 files changed

+39
-75
lines changed

Samples/iOS-Swift/iOS-Swift-IntentExtension/Sources/IntentHandler.swift

Lines changed: 39 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -9,95 +9,64 @@ class IntentHandler: INExtension, INSendMessageIntentHandling {
99
super.init()
1010
setupSentry()
1111
}
12-
13-
private func setupSentry() {
14-
SentrySDKWrapper.shared.startSentry()
15-
16-
// Small delay to ensure SDK is initialized
17-
DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) {
18-
self.checkANRStatus()
19-
}
20-
}
21-
22-
private func checkANRStatus() {
23-
// Verify ANR tracking is disabled
24-
var anrInstalled = false
25-
if SentrySDK.isEnabled {
26-
let integrationNames = SentrySDKInternal.trimmedInstalledIntegrationNames()
27-
anrInstalled = integrationNames.contains("ANRTracking")
28-
}
29-
30-
if anrInstalled {
31-
print("❌ ERROR: ANR tracking should be disabled in Intent Extension but it's enabled!")
32-
} else {
33-
print("✅ ANR tracking is correctly disabled in Intent Extension")
34-
}
35-
}
36-
12+
3713
override func handler(for intent: INIntent) -> Any {
3814
setupSentry()
3915
return self
4016
}
17+
18+
private func setupSentry() {
19+
// For this extension we need a specific configuration set, therefore we do not use the shared sample initializer
20+
SentrySDK.start { options in
21+
options.dsn = SentrySDKWrapper.defaultDSN
22+
options.debug = true
23+
24+
// App Hang Tracking must be enabled, but should not be installed
25+
options.enableAppHangTracking = true
26+
}
27+
}
4128

4229
// MARK: - INSendMessageIntentHandling
4330

44-
// Implement resolution methods to provide additional information about your intent (optional).
4531
func resolveRecipients(for intent: INSendMessageIntent, with completion: @escaping ([INSendMessageRecipientResolutionResult]) -> Void) {
46-
if let recipients = intent.recipients {
47-
// If no recipients were provided we'll need to prompt for a value.
48-
if recipients.count == 0 {
49-
completion([INSendMessageRecipientResolutionResult.needsValue()])
50-
return
51-
}
52-
53-
var resolutionResults = [INSendMessageRecipientResolutionResult]()
54-
for recipient in recipients {
55-
let matchingContacts = [recipient] // Implement your contact matching logic here to create an array of matching contacts
56-
switch matchingContacts.count {
57-
case 2 ... Int.max:
58-
// We need Siri's help to ask user to pick one from the matches.
59-
resolutionResults += [INSendMessageRecipientResolutionResult.disambiguation(with: matchingContacts)]
60-
61-
case 1:
62-
// We have exactly one matching contact
63-
resolutionResults += [INSendMessageRecipientResolutionResult.success(with: recipient)]
64-
65-
case 0:
66-
// We have no contacts matching the description provided
67-
resolutionResults += [INSendMessageRecipientResolutionResult.unsupported()]
68-
69-
default:
70-
break
71-
}
72-
}
73-
completion(resolutionResults)
74-
} else {
75-
completion([INSendMessageRecipientResolutionResult.needsValue()])
76-
}
32+
let person = INPerson(
33+
personHandle: INPersonHandle(value: "john-snow", type: .unknown),
34+
nameComponents: PersonNameComponents(givenName: "John", familyName: "Snow"),
35+
displayName: "John Snow",
36+
image: nil,
37+
contactIdentifier: nil,
38+
customIdentifier: nil
39+
)
40+
completion([INSendMessageRecipientResolutionResult.success(with: person)])
7741
}
7842

7943
func resolveContent(for intent: INSendMessageIntent, with completion: @escaping (INStringResolutionResult) -> Void) {
80-
if let text = intent.content, !text.isEmpty {
81-
completion(INStringResolutionResult.success(with: text))
82-
} else {
83-
completion(INStringResolutionResult.needsValue())
84-
}
44+
let message = """
45+
Sentry Enabled? \(isSentryEnabled ? "" : "")
46+
ANR Disabled? \(!isANRInstalled ? "" : "")
47+
"""
48+
completion(INStringResolutionResult.success(with: message))
8549
}
8650

87-
// Once resolution is completed, perform validation on the intent and provide confirmation (optional).
8851
func confirm(intent: INSendMessageIntent, completion: @escaping (INSendMessageIntentResponse) -> Void) {
89-
// Verify user is authenticated and your app is ready to send a message.
9052
let userActivity = NSUserActivity(activityType: NSStringFromClass(INSendMessageIntent.self))
91-
let response = INSendMessageIntentResponse(code: .ready, userActivity: userActivity)
92-
completion(response)
53+
completion(INSendMessageIntentResponse(code: .ready, userActivity: userActivity))
9354
}
9455

95-
// Handle the completed intent (required).
9656
func handle(intent: INSendMessageIntent, completion: @escaping (INSendMessageIntentResponse) -> Void) {
97-
print("🔵 IntentHandler.handle(intent:) called")
9857
SentrySDK.capture(message: "iOS-Swift-IntentExtension: handle intent called")
58+
9959
let userActivity = NSUserActivity(activityType: NSStringFromClass(INSendMessageIntent.self))
100-
let response = INSendMessageIntentResponse(code: .success, userActivity: userActivity)
101-
completion(response)
60+
completion(INSendMessageIntentResponse(code: .success, userActivity: userActivity))
61+
}
62+
63+
// MARK: - Helpers
64+
65+
var isANRInstalled: Bool {
66+
return isSentryEnabled && SentrySDKInternal.trimmedInstalledIntegrationNames().contains("ANRTracking")
67+
}
68+
69+
var isSentryEnabled: Bool {
70+
SentrySDK.isEnabled
10271
}
10372
}

Samples/iOS-Swift/iOS-Swift.xcodeproj/xcshareddata/xcschemes/iOS-Swift-IntentExtension.xcscheme

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,6 @@
6666
debugServiceExtension = "internal"
6767
allowLocationSimulation = "YES"
6868
launchAutomaticallySubstyle = "2">
69-
<RemoteRunnable
70-
runnableDebuggingMode = "0"
71-
BundleIdentifier = "com.apple.Maps"
72-
RemotePath = "/var/containers/Bundle/Application/AEF0736D-F834-4160-932E-6AE44AAD3B51/Maps.app">
73-
</RemoteRunnable>
7469
<MacroExpansion>
7570
<BuildableReference
7671
BuildableIdentifier = "primary"

0 commit comments

Comments
 (0)