Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/meteor/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Xamarin.ios 从Xcode 12 CarPlay模拟器启动CarPlay parking应用程序时崩溃_Xamarin.ios_Carplay - Fatal编程技术网

Xamarin.ios 从Xcode 12 CarPlay模拟器启动CarPlay parking应用程序时崩溃

Xamarin.ios 从Xcode 12 CarPlay模拟器启动CarPlay parking应用程序时崩溃,xamarin.ios,carplay,Xamarin.ios,Carplay,我们正在为CarPlay扩展Xamarin.iOS应用程序(由Xamarin.Forms提供)。当打开CarPlay模拟器时,应用程序显示在CarPlay的屏幕上,但从CarPlay模拟器启动时崩溃 以下是Info.plist场景配置: <key>UIApplicationSceneManifest</key> <dict> <key>UISceneConfigurations</key>

我们正在为CarPlay扩展Xamarin.iOS应用程序(由Xamarin.Forms提供)。当打开CarPlay模拟器时,应用程序显示在CarPlay的屏幕上,但从CarPlay模拟器启动时崩溃

以下是Info.plist场景配置:

    <key>UIApplicationSceneManifest</key>
    <dict>
        <key>UISceneConfigurations</key>
        <dict>
            <key>CPTemplateApplicationSceneSessionRoleApplication</key>
            <array>
                <dict>
                    <key>UISceneClassName</key>
                    <string>CPTemplateApplicationScene</string>
                    <key>UISceneConfigurationName</key>
                    <string>ParkingPlus-Car</string>
                    <key>UISceneDelegateClassName</key>
                    <string>ParkingPlus.AppSceneDelegateImp</string>
                </dict>
            </array>
        </dict>
    </dict>
当我覆盖AppDelegate.GetConfiguration时,如下所示

public override UISceneConfiguration GetConfiguration(UIApplication application, UISceneSession connectingSceneSession, UISceneConnectionOptions options)
{
...
}

在CarPlay上点击应用程序图标时,将调用该方法。但是当我检查ConnectionSceneSession时,我发现变量成员中存在一些异常。 “CPTemplateApplicationSceneSessionRoleApplication在此平台上没有关联的枚举值”

如果继续,则应用程序将抛出一个异常,该异常似乎表明ScenedLegate未正确加载:

我的环境: Visual studio for mac 8.7.8版 Xamarin.iOS 14.0.0 Xcode 12.0

绑定ios库时,Xamarin.ios 14似乎遗漏了一些内容。任何人都有类似的问题。我是否做错了什么,或者在Xcode/swift中将移动应用程序保留在Xamarin.Forms/Xamarin.iOS上的同时,是否有其他方法可以通过Xcode/swift实现CarPlay部件功能


感谢您的评论或帮助。

在Xamarin.ios团队的帮助下,以下是此问题的完整解决方案:

  • AppDelegate为两种情况(CarPlay和phone)创建场景配置

  • 这种崩溃只发生在iOS 14中吗
    绑定ios库时,Xamarin.ios 14似乎丢失了一些内容。
    ,如果您认为是绑定ios库造成的,可以在Github中使用这些信息打开问题。@JackHua MSFT,谢谢。在我问这个问题之前的一周,我确实提出了一个问题。团队将在Xamarin.iOS上修复该漏洞。我得到了一个建议。当我让它正常工作时,我会在这里回答。太好了+1,你能展示两个AppDelegate(电话/汽车)以及Xamarin是如何加载“主”AppDelegate的吗?它决定加载哪一个?@Suplanus,将调用AppDelegate.GetConfiguration()并确定相应的UI场景(CarPlay或phone)将加载,并返回UISceneConfiguration。在该方法中,在返回UISceneConfiguration之前,必须指定场景代理实现。这就是你所需要做的。上面的代码片段包含所有必需的代码。谢谢。我在这个回购协议中做了一些测试:但它没有按预期工作。@Suplanus,你在info.plist文件中有正确的CarPlay权限和设置吗?我想是的,你可以在回购协议中看到它。我还认为模拟器不需要应用程序的授权(只有设备需要)。
    public override UISceneConfiguration GetConfiguration(UIApplication application, UISceneSession connectingSceneSession, UISceneConnectionOptions options)
    {
    ...
    }
    
    
    
            [DllImport("/usr/lib/libobjc.dylib", EntryPoint = "objc_msgSend")]
            public extern static IntPtr IntPtr_objc_msgSend_IntPtr_IntPtr(IntPtr receiver, IntPtr selector, IntPtr arg1, IntPtr arg2);
    
            public static UISceneConfiguration Create(string? name, NSString sessionRole)
            {
                global::UIKit.UIApplication.EnsureUIThread();
                var nsname = NSString.CreateNative(name);
    
                UISceneConfiguration sceneConfig;
                sceneConfig = Runtime.GetNSObject<UISceneConfiguration>(IntPtr_objc_msgSend_IntPtr_IntPtr(Class.GetHandle("UISceneConfiguration"), Selector.GetHandle("configurationWithName:sessionRole:"), nsname, sessionRole.Handle));
                NSString.ReleaseNative(nsname);
                //Because only the CarPlay scene will be here to create a scene configuration
                //We need manually assign the CarPlay scene delegate here!
                sceneConfig.DelegateType = typeof(AppCarSceneDelegateImp);
                return sceneConfig!;
            }
    
            [Export("application:configurationForConnectingSceneSession:options:")]
            public UISceneConfiguration GetConfiguration(UIApplication application, UISceneSession connectingSceneSession, UISceneConnectionOptions options)
            {
                UIWindowSceneSessionRole sessionRole;
                bool isCarPlaySceneSession = false;
                try
                {
                    //When the connecting scene is a CarPlay scene, an expected exception will be thrown
                    //Under this moment from Xamarin.iOS.
                    sessionRole = connectingSceneSession.Role;
                }
                catch (NotSupportedException ex)
                {
                    if (!string.IsNullOrEmpty(ex.Message) &&
                        ex.Message.Contains("CPTemplateApplicationSceneSessionRoleApplication"))
                    {
                        isCarPlaySceneSession = true;
                    }
                }
    
                if (isCarPlaySceneSession && UIDevice.CurrentDevice.CheckSystemVersion(14,0))
                {
                    return Create("Car", CarPlay.CPTemplateApplicationScene.SessionRoleApplication);
                }
                else
                {
                    //If it is phone scene, we need the regular UIWindow scene
                    UISceneConfiguration phoneScene = new UISceneConfiguration("Phone", UIWindowSceneSessionRole.Application);
                    //And assign the scene delegate here.
                    phoneScene.DelegateType = typeof(AppWindowSceneDelegateImp);
                    return phoneScene;
                }
            }
    
        public class AppWindowSceneDelegateImp : UISceneDelegate
        {
            public override void WillConnect(UIScene scene, UISceneSession session, UISceneConnectionOptions connectionOptions)
            {
                var windowScene = scene as UIWindowScene;
                if (windowScene != null)
                {
                    //Assign the Xamarin.iOS app window to this scene 
                    UIApplication.SharedApplication.KeyWindow.WindowScene = windowScene;
                    UIApplication.SharedApplication.KeyWindow.MakeKeyAndVisible();
                }
            }
        }