Skip to content

In the scene:willConnectToSession:options:, accessing connectionOptions.UserActivities throws #16378

@mattleibow

Description

@mattleibow

Steps to Reproduce

  1. Add some Info.plist xml
<key>UIApplicationSceneManifest</key>
<dict>
	<key>UIApplicationSupportsMultipleScenes</key>
	<true/>
	<key>UISceneConfigurations</key>
	<dict>
		<key>UIWindowSceneSessionRoleApplication</key>
		<array>
			<dict>
				<key>UISceneConfigurationName</key>
				<string>__MAUI_DEFAULT_SCENE_CONFIGURATION__</string>
				<key>UISceneDelegateClassName</key>
				<string>SceneDelegate</string>
			</dict>
		</array>
	</dict>
</dict>
  1. Override the Scene Delegate method:
[Export("scene:willConnectToSession:options:")]
[System.Runtime.Versioning.SupportedOSPlatform("ios13.0")]
[System.Runtime.Versioning.SupportedOSPlatform("tvos13.0")]
public virtual void WillConnect(UIScene scene, UISceneSession session, UISceneConnectionOptions connectionOptions)
{
    var activities = connectionOptions.UserActivities;
}
  1. Observe an exception:
Unable to cast object of type 'Foundation.NSSet`1[[UIKit.UIScene, Microsoft.iOS, Version=16.0.0.0, Culture=neutral, PublicKeyToken=84e04ff9cfb79065]]' to type 'Foundation.NSSet`1[[Foundation.NSUserActivity, Microsoft.iOS, Version=16.0.0.0, Culture=neutral, PublicKeyToken=84e04ff9cfb79065]]'.

   at ObjCRuntime.Runtime.GetNSObject[NSSet`1](IntPtr ptr)
   at UIKit.UISceneConnectionOptions.get_UserActivities()
   at Microsoft.Maui.Platform.ApplicationExtensions.CreatePlatformWindow(IUIWindowSceneDelegate sceneDelegate, IApplication application, UIScene scene, UISceneSession session, UISceneConnectionOptions connectionOptions) in /Users/matthew/Projects/maui/src/Core/src/Platform/iOS/ApplicationExtensions.cs:line 60
   at Microsoft.Maui.MauiUISceneDelegate.WillConnect(UIScene scene, UISceneSession session, UISceneConnectionOptions connectionOptions) in /Users/matthew/Projects/maui/src/Core/src/Platform/iOS/MauiUISceneDelegate.cs:line 23
   at UIKit.UIApplication.UIApplicationMain(Int32 argc, String[] argv, IntPtr principalClassName, IntPtr delegateClassName)
   at UIKit.UIApplication.Main(String[] args, Type principalClass, Type delegateClass)
   at Maui.Controls.Sample.Platform.Application.Main(String[] args) in /Users/matthew/Projects/maui/src/Controls/samples/Controls.Sample.Sandbox/Platforms/iOS/Main.cs:line 8

Expected Behavior

No exception

Actual Behavior

Exception

Environment

Version information

Build Logs

Example Project (If Possible)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugIf an issue is a bug or a pull request a bug fixdotnetAn issue or pull request related to .NET (6)

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions