Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add MacCatalyst target and sample app #1848

Merged
merged 4 commits into from
Aug 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
- Add the Sentry iOS SDK ([#1829](https://github.com/getsentry/sentry-dotnet/pull/1829))
- Enable Scope Sync for iOS ([#1834](https://github.com/getsentry/sentry-dotnet/pull/1834))
- Add API for deliberately crashing an app ([#1842](https://github.com/getsentry/sentry-dotnet/pull/1842))
- Add Mac Catalyst target ([#1848](https://github.com/getsentry/sentry-dotnet/pull/1848))

### Fixes

Expand Down
8 changes: 8 additions & 0 deletions Sentry.sln
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sentry.Samples.Ios", "sampl
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sentry.Testing.CrashableApp", "test\Sentry.Testing.CrashableApp\Sentry.Testing.CrashableApp.csproj", "{DA3CECBB-83BE-441A-852C-077809C48307}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sentry.Samples.MacCatalyst", "samples\Sentry.Samples.MacCatalyst\Sentry.Samples.MacCatalyst.csproj", "{3506539B-983C-44FD-BD95-1931562E7919}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -355,6 +357,11 @@ Global
{DA3CECBB-83BE-441A-852C-077809C48307}.Release|Any CPU.Build.0 = Release|Any CPU
{DA3CECBB-83BE-441A-852C-077809C48307}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{DA3CECBB-83BE-441A-852C-077809C48307}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3506539B-983C-44FD-BD95-1931562E7919}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{3506539B-983C-44FD-BD95-1931562E7919}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3506539B-983C-44FD-BD95-1931562E7919}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3506539B-983C-44FD-BD95-1931562E7919}.Release|Any CPU.Build.0 = Release|Any CPU
{3506539B-983C-44FD-BD95-1931562E7919}.Debug|Any CPU.Deploy.0 = Debug|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -411,6 +418,7 @@ Global
{143076C0-8D6B-4054-9F45-06B21655F417} = {83263231-1A2A-4733-B759-EEFF14E8C5D5}
{C2876321-A612-4E66-AF33-D3928FA6366F} = {77454495-55EE-4B40-A089-71B9E8F82E89}
{DA3CECBB-83BE-441A-852C-077809C48307} = {83263231-1A2A-4733-B759-EEFF14E8C5D5}
{3506539B-983C-44FD-BD95-1931562E7919} = {77454495-55EE-4B40-A089-71B9E8F82E89}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {0C652B1A-DF72-4EE5-A98B-194FE2C054F6}
Expand Down
1 change: 1 addition & 0 deletions SentryMaui.slnf
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"projects": [
"samples\\Sentry.Samples.Android\\Sentry.Samples.Android.csproj",
"samples\\Sentry.Samples.Ios\\Sentry.Samples.Ios.csproj",
"samples\\Sentry.Samples.MacCatalyst\\Sentry.Samples.MacCatalyst.csproj",
"samples\\Sentry.Samples.Maui\\Sentry.Samples.Maui.csproj",
"src\\Sentry.Extensions.Logging\\Sentry.Extensions.Logging.csproj",
"src\\Sentry.Maui\\Sentry.Maui.csproj",
Expand Down
2 changes: 2 additions & 0 deletions samples/Sentry.Samples.Ios/AppDelegate.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#pragma warning disable CS0618

namespace Sentry.Samples.Ios;

[Register("AppDelegate")]
Expand Down
46 changes: 46 additions & 0 deletions samples/Sentry.Samples.MacCatalyst/AppDelegate.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#pragma warning disable CS0618

namespace Sentry.Samples.MacCatalyst;

[Register ("AppDelegate")]
public class AppDelegate : UIApplicationDelegate {
public override UIWindow? Window {
get;
set;
}

public override bool FinishedLaunching (UIApplication application, NSDictionary launchOptions)
{
// Init the Sentry SDK
SentrySdk.Init(o =>
{
o.Debug = true;
o.Dsn = "https://eb18e953812b41c3aeb042e666fd3b5c@o447951.ingest.sentry.io/5428537";
});

// create a new window instance based on the screen size
Window = new UIWindow (UIScreen.MainScreen.Bounds);

// create a UIViewController with a single UILabel
var vc = new UIViewController ();
vc.View!.AddSubview (new UILabel (Window!.Frame) {
BackgroundColor = UIColor.SystemBackground,
TextAlignment = UITextAlignment.Center,
Text = "Hello, Catalyst!",
AutoresizingMask = UIViewAutoresizing.All,
});
Window.RootViewController = vc;

// make the window visible
Window.MakeKeyAndVisible ();

// Try out the Sentry SDK
SentrySdk.CaptureMessage("From Mac Catalyst");

// Uncomment to try these
// throw new Exception("Test Unhandled Managed Exception");
// SentrySdk.CauseCrash(CrashType.Native);

return true;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
{
"images": [
{
"idiom" : "mac",
"scale" : "1x",
"size" : "16x16",
"filename": "Icon16.png"
},
{
"idiom" : "mac",
"scale" : "2x",
"size" : "16x16",
"filename": "Icon32.png"
},
{
"idiom" : "mac",
"scale" : "1x",
"size" : "32x32",
"filename": "Icon32.png"
},
{
"idiom" : "mac",
"scale" : "2x",
"size" : "32x32",
"filename": "Icon64.png"
},
{
"idiom" : "mac",
"scale" : "1x",
"size" : "128x128",
"filename": "Icon128.png"
},
{
"idiom" : "mac",
"scale" : "2x",
"size" : "128x128",
"filename": "Icon256.png"
},
{
"idiom" : "mac",
"scale" : "1x",
"size" : "256x256",
"filename": "Icon256.png"
},
{
"idiom" : "mac",
"scale" : "2x",
"size" : "256x256",
"filename": "Icon512.png"
},
{
"idiom" : "mac",
"scale" : "1x",
"size" : "512x512",
"filename": "Icon512.png"
},
{
"idiom" : "mac",
"scale" : "2x",
"size" : "512x512",
"filename": "Icon1024.png"
}
],
"info": {
"version": 1,
"author": "xcode"
},
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions samples/Sentry.Samples.MacCatalyst/Entitlements.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
</dict>
</plist>
26 changes: 26 additions & 0 deletions samples/Sentry.Samples.MacCatalyst/Info.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDisplayName</key>
<string>Sentry.Samples.MacCatalyst</string>
<key>CFBundleIdentifier</key>
<string>com.companyname.Sentry.Samples.MacCatalyst</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleVersion</key>
<string>1.0</string>
<key>UIDeviceFamily</key>
<array>
<integer>2</integer>
</array>
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>XSAppIconAssets</key>
<string>Assets.xcassets/AppIcon.appiconset</string>
</dict>
</plist>
6 changes: 6 additions & 0 deletions samples/Sentry.Samples.MacCatalyst/Main.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
using Sentry.Samples.MacCatalyst;

// This is the main entry point of the application.
// If you want to use a different Application Delegate class from "AppDelegate"
// you can specify it here.
UIApplication.Main (args, null, typeof (AppDelegate));
43 changes: 43 additions & 0 deletions samples/Sentry.Samples.MacCatalyst/Resources/LaunchScreen.xib
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="6214" systemVersion="14A314h" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" useTraitCollections="YES">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="6207" />
<capability name="Constraints with non-1.0 multipliers" minToolsVersion="5.1" />
</dependencies>
<objects>
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner" />
<placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder" />
<view contentMode="scaleToFill" id="iN0-l3-epB">
<rect key="frame" x="0.0" y="0.0" width="480" height="480" />
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES" />
<subviews>
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text=" Copyright (c) 2017 " textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines"
minimumFontSize="9" translatesAutoresizingMaskIntoConstraints="NO" id="8ie-xW-0ye">
<rect key="frame" x="20" y="439" width="441" height="21" />
<fontDescription key="fontDescription" type="system" pointSize="17" />
<color key="textColor" cocoaTouchSystemColor="darkTextColor" />
<nil key="highlightedColor" />
</label>
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="NewApp" textAlignment="center" lineBreakMode="middleTruncation" baselineAdjustment="alignBaselines"
minimumFontSize="18" translatesAutoresizingMaskIntoConstraints="NO" id="kId-c2-rCX">
<rect key="frame" x="20" y="140" width="441" height="43" />
<fontDescription key="fontDescription" type="boldSystem" pointSize="36" />
<color key="textColor" cocoaTouchSystemColor="darkTextColor" />
<nil key="highlightedColor" />
</label>
</subviews>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite" />
<constraints>
<constraint firstItem="kId-c2-rCX" firstAttribute="centerY" secondItem="iN0-l3-epB" secondAttribute="bottom" multiplier="1/3" constant="1" id="5cJ-9S-tgC" />
<constraint firstAttribute="centerX" secondItem="kId-c2-rCX" secondAttribute="centerX" id="Koa-jz-hwk" />
<constraint firstAttribute="bottom" secondItem="8ie-xW-0ye" secondAttribute="bottom" constant="20" id="Kzo-t9-V3l" />
<constraint firstItem="8ie-xW-0ye" firstAttribute="leading" secondItem="iN0-l3-epB" secondAttribute="leading" constant="20" symbolic="YES" id="MfP-vx-nX0" />
<constraint firstAttribute="centerX" secondItem="8ie-xW-0ye" secondAttribute="centerX" id="ZEH-qu-HZ9" />
<constraint firstItem="kId-c2-rCX" firstAttribute="leading" secondItem="iN0-l3-epB" secondAttribute="leading" constant="20" symbolic="YES" id="fvb-Df-36g" />
</constraints>
<nil key="simulatedStatusBarMetrics" />
<freeformSimulatedSizeMetrics key="simulatedDestinationMetrics" />
<point key="canvasLocation" x="548" y="455" />
</view>
</objects>
</document>
54 changes: 54 additions & 0 deletions samples/Sentry.Samples.MacCatalyst/SceneDelegate.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
namespace Sentry.Samples.MacCatalyst;

[Register ("SceneDelegate")]
public class SceneDelegate : UIResponder, IUIWindowSceneDelegate {

[Export ("window")]
public UIWindow? Window { get; set; }

[Export ("scene:willConnectToSession:options:")]
public void WillConnect (UIScene scene, UISceneSession session, UISceneConnectionOptions connectionOptions)
{
// Use this method to optionally configure and attach the UIWindow `window` to the provided UIWindowScene `scene`.
// If using a storyboard, the `window` property will automatically be initialized and attached to the scene.
// This delegate does not imply the connecting scene or session are new (see UIApplicationDelegate `GetConfiguration` instead).
}

[Export ("sceneDidDisconnect:")]
public void DidDisconnect (UIScene scene)
{
// Called as the scene is being released by the system.
// This occurs shortly after the scene enters the background, or when its session is discarded.
// Release any resources associated with this scene that can be re-created the next time the scene connects.
// The scene may re-connect later, as its session was not neccessarily discarded (see UIApplicationDelegate `DidDiscardSceneSessions` instead).
}

[Export ("sceneDidBecomeActive:")]
public void DidBecomeActive (UIScene scene)
{
// Called when the scene has moved from an inactive state to an active state.
// Use this method to restart any tasks that were paused (or not yet started) when the scene was inactive.
}

[Export ("sceneWillResignActive:")]
public void WillResignActive (UIScene scene)
{
// Called when the scene will move from an active state to an inactive state.
// This may occur due to temporary interruptions (ex. an incoming phone call).
}

[Export ("sceneWillEnterForeground:")]
public void WillEnterForeground (UIScene scene)
{
// Called as the scene transitions from the background to the foreground.
// Use this method to undo the changes made on entering the background.
}

[Export ("sceneDidEnterBackground:")]
public void DidEnterBackground (UIScene scene)
{
// Called as the scene transitions from the foreground to the background.
// Use this method to save data, release shared resources, and store enough scene-specific state information
// to restore the scene back to its current state.
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0-maccatalyst</TargetFramework>
<RuntimeIdentifier>maccatalyst-x64</RuntimeIdentifier>
<OutputType>Exe</OutputType>
<Nullable>enable</Nullable>
<ImplicitUsings>true</ImplicitUsings>
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
<ImplicitUsings>true</ImplicitUsings>

<SupportedOSPlatformVersion>14.2</SupportedOSPlatformVersion>
</PropertyGroup>

<!--
In a real project, use the PackageReference and set the version to the latest release.
Use that instead of the ProjectReference.
-->

<ItemGroup>
<!-- <PackageReference Include="Sentry" Version="..." /> -->
<ProjectReference Include="..\..\src\Sentry\Sentry.csproj" />
</ItemGroup>

<!--
This next section is to build an empty assembly instead of the actual sample app when not building on a Mac.
We do this here so we don't have to worry about solution configurations or filters in CI.
It is not needed in a real application.
-->
<PropertyGroup Condition="!$([MSBuild]::IsOSPlatform('OSX'))">
<TargetFramework>net6.0</TargetFramework>
<OutputType>Library</OutputType>
<DefaultItemExcludes>**\*</DefaultItemExcludes>
</PropertyGroup>

<!--
Workaround for https://github.com/dotnet/maui/issues/7272 (also happens for iOS without MAUI)
This should not be needed in a real application.
-->
<Target Name="_SetPublishFolderTypeNoneOnDocFileItems" BeforeTargets="_ComputePublishLocation">
<ItemGroup>
<ResolvedFileToPublish
Update="@(ResolvedFileToPublish)"
Condition="'%(ResolvedFileToPublish.Extension)' == '.xml' And '%(ResolvedFileToPublish.PublishFolderType)' == ''"
PublishFolderType="None" />
</ItemGroup>
</Target>

</Project>
4 changes: 2 additions & 2 deletions samples/Sentry.Samples.Maui/MainPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public MainPage(ILogger<MainPage> logger)
JavaCrashBtn.IsVisible = false;
#endif

#if !(ANDROID || IOS) // TODO: Enable for MACCATALYST
#if !(ANDROID || IOS || MACCATALYST)
NativeCrashBtn.IsVisible = false;
#endif
_logger = logger;
Expand Down Expand Up @@ -64,7 +64,7 @@ private void OnJavaCrashClicked(object sender, EventArgs e)

private void OnNativeCrashClicked(object sender, EventArgs e)
{
#if ANDROID || IOS // TODO: Enable for MACCATALYST
#if ANDROID || IOS || MACCATALYST
SentrySdk.CauseCrash(CrashType.Native);
#endif
}
Expand Down
8 changes: 0 additions & 8 deletions src/Sentry.Maui/Internal/SentryMauiInitializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,6 @@ public void Initialize(IServiceProvider services)
var binder = services.GetRequiredService<MauiEventsBinder>();
binder.BindMauiEvents();

#if IOS || MACCATALYST
// Workaround for https://github.com/xamarin/xamarin-macios/issues/15252
ObjCRuntime.Runtime.MarshalManagedException += (_, args) =>
{
args.ExceptionMode = ObjCRuntime.MarshalManagedExceptionMode.UnwindNativeCode;
};
#endif

// Register with the WinUI unhandled exception handler when needed
RegisterApplicationUnhandledExceptionForWinUI();
}
Expand Down
4 changes: 2 additions & 2 deletions src/Sentry/Internal/ProcessInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ internal ProcessInfo(
// https://issuetracker.unity3d.com/issues/il2cpp-player-crashes-when-calling-process-dot-getcurrentprocess-dot-starttime
if (options.DetectStartupTime == StartupTimeDetectionMode.Best)
{
#if ANDROID
options.LogWarning("StartupTimeDetectionMode.Best is not available on android. Using 'Fast' mode.");
#if ANDROID || IOS || MACCATALYST
options.LogWarning("StartupTimeDetectionMode.Best is not available on this platform. Using 'Fast' mode.");
return;
#else
// StartupTime is set to UtcNow in this constructor.
Expand Down
Loading