-
-
Notifications
You must be signed in to change notification settings - Fork 60
Expand file tree
/
Copy pathSentryNativeCocoa.cs
More file actions
111 lines (93 loc) · 3.52 KB
/
Copy pathSentryNativeCocoa.cs
File metadata and controls
111 lines (93 loc) · 3.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
using Sentry.Extensibility;
using Sentry.Unity.Integrations;
using UnityEngine;
namespace Sentry.Unity.iOS;
/// <summary>
/// Access to the Sentry native support on iOS/macOS.
/// </summary>
public static class SentryNativeCocoa
{
private static IDiagnosticLogger? Logger;
/// <summary>
/// Configures the native support.
/// </summary>
/// <param name="options">The Sentry Unity options to use.</param>
public static void Configure(SentryUnityOptions options) =>
Configure(options, ApplicationAdapter.Instance.Platform);
// For testing
internal static void Configure(SentryUnityOptions options, RuntimePlatform platform)
{
Logger = options.DiagnosticLogger;
Logger?.LogInfo("Attempting to configure native support via the Cocoa SDK");
if (!options.IsNativeSupportEnabled(platform))
{
Logger?.LogDebug("Native support is disabled for: '{0}'", platform);
return;
}
if (platform == RuntimePlatform.IPhonePlayer)
{
if (SentryCocoaBridgeProxy.IsEnabled())
{
Logger?.LogDebug("The native SDK is already initialized");
}
else if (!SentryCocoaBridgeProxy.Init(options))
{
Logger?.LogWarning("Failed to initialize the native SDK");
return;
}
options.ScopeObserver = new NativeScopeObserver("iOS", options);
if (options.EnableAppHangTracking)
{
Logger?.LogDebug("Disabling the C# ANR watchdog - sentry-cocoa handles app hang detection.");
options.DisableAnrIntegration();
}
}
else
{
if (!SentryCocoaBridgeProxy.Init(options))
{
Logger?.LogWarning("Failed to initialize the native SDK");
return;
}
options.ScopeObserver = new NativeScopeObserver("macOS", options);
}
SentryCocoaBridgeProxy.SetSdkName(); // Since we're not building the SDK we have to overwrite the name here
options.NativeContextWriter = new NativeContextWriter();
options.EnableScopeSync = true;
options.CrashedLastRun = () =>
{
Logger?.LogDebug("Checking for 'CrashedLastRun'");
var crashedLastRun = SentryCocoaBridgeProxy.CrashedLastRun() == 1;
Logger?.LogDebug("Native SDK reported: 'crashedLastRun': '{0}'", crashedLastRun);
return crashedLastRun;
};
options.NativeSupportCloseCallback += () => Close(options);
if (options.UnityInfo.IL2CPP)
{
var installationId = SentryCocoaBridgeProxy.GetInstallationId();
if (!string.IsNullOrEmpty(installationId))
{
options.DefaultUserId = installationId;
}
else
{
Logger?.LogDebug("Failed to fetch 'Installation ID' from the native SDK.");
}
}
Logger?.LogInfo("Successfully configured the native SDK");
}
/// <summary>
/// Closes the native Cocoa support.
/// </summary>
public static void Close(SentryUnityOptions options)
{
Logger?.LogInfo("Attempting to close the Cocoa SDK");
if (!options.IsNativeSupportEnabled())
{
Logger?.LogDebug("Cocoa Native Support is not enable. Skipping closing the Cocoa SDK");
return;
}
Logger?.LogDebug("Closing the Cocoa SDK");
SentryCocoaBridgeProxy.Close();
}
}