Xamarin Forms错误-'您必须调用Xamarin.Forms.Init();使用之前"-仅适用于TestFlight(iOS) [英] Xamarin Forms error - 'You MUST call Xamarin.Forms.Init(); prior to using it' - TestFlight (iOS) only

查看:309
本文介绍了Xamarin Forms错误-'您必须调用Xamarin.Forms.Init();使用之前"-仅适用于TestFlight(iOS)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在SO和其他地方,我也见过其他几篇有关此错误(System.InvalidOperationException: You MUST call Xamarin.Forms.Init(); prior to using it. at Xamarin.Forms.Device.get_PlatformServices)的文章,但都没有发现我的具体情况.

I've seen several other posts on SO and elsewhere about this error (System.InvalidOperationException: You MUST call Xamarin.Forms.Init(); prior to using it. at Xamarin.Forms.Device.get_PlatformServices), but none of them shed any light on my particular situation.

我创建了一个Xamarin.Forms应用程序,该应用程序在Android(模拟器和设备,包括通过Google Play分发的模拟器和设备)上运行良好,并且在iPhone模拟器和预配置到iPhone上均可以正常运行.当我说效果很好"时,我的意思是能够无错误地进入MainPage".

I've created a Xamarin.Forms application that works great on Android (emulators and device, including when distributed through Google Play), and works fine both on the iPhone simulator and when provisioned to the iPhone. And when I say 'works fine', I mean 'is able to get to the MainPage without error.'

但是,当我使用Ad-Hoc部署并将其上传到Apple以便可以与TestFlight一起分发时,下载的TestFlight版本会显示初始屏幕,然后崩溃,而没有显示MainPage.在查看设备日志时,会出现上述错误,并且在进行一些Internet研究时,很明显,我的AppDelegate需要以global::Xamarin.Forms.Forms.Init();作为FinishedLaunching()方法的第一行.

However, when I use Ad-Hoc deployment and upload it to Apple so it can be distributed with TestFlight, the TestFlight-downloaded version shows the splash screen as expected, and then crashes without ever showing the MainPage. In looking at the device logs, the above error appears, and in doing some Internet research, it's become apparent that my AppDelegate needs to have global::Xamarin.Forms.Forms.Init(); as the first line in the FinishedLaunching() method.

所以我去看了一下,并将该行放入该文件中的该方法中,瞧瞧,它已经存在了.鉴于该应用程序可以在sim上运行,而直接从Visual Studio部署在iPhone上也可以在iPhone上运行,这并不意外.

So I went to take a look and put that line in that method in that file, and lo and behold, it's already there. This is not unexpected, given the fact that the app works on the sim, and on the iPhone when deployed directly from Visual Studio.

所以我的问题是为什么在其他所有部署类型都没有的情况下Ad-Hoc部署会失败,我该如何解决该问题并使应用程序以可运行的方式通过TestFlight实际分发?"

So my question is 'Why does Ad-Hoc deployment fail when all other deployment types do not, and what can I do to overcome this problem and get the app to actually distribute through TestFlight in a runnable fashion?'

推荐答案

我能够通过将命令(global::Xamarin.Forms.Forms.Init();)首先放在iOS平台特定服务的每个类的每个构造函数中来解决此问题.可能只有一个是真正必要的,但似乎并没有导致任何问题过度部署了该特定命令,并且在调用AppDelegate的FinishedLaunching()方法之前调用了多个服务的情况下,这在第一个调用中似乎是必需的,它可能会根据程序流的不同而有所变化,具体取决于环境和可能要检查的其他变量.

I was able to resolve the issue by putting the command (global::Xamarin.Forms.Forms.Init();) first thing in every constructor in every class in the iOS platform-specific services. It's possible that only one was really necessary, but it doesn't seem to have caused any issue to over-deploy that particular command, and in the case that more than one of the services is called before the AppDelegate's FinishedLaunching() method is called, that would seem to be necessary in the first one called, which could potentially vary by program flow, depending on environment and other variables that may be checked.

这篇关于Xamarin Forms错误-'您必须调用Xamarin.Forms.Init();使用之前"-仅适用于TestFlight(iOS)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆