为什么我的 Xamarin Froms iOS 应用程序在物理设备上崩溃?

问题描述 投票:0回答:1

我的 Xamarin.Forms 应用程序在 Android 上完美运行,但当我部署到 iOS(物理 iPhone 8)时,它不断出现故障。我在 AppDelegate 或第一页中设置了断点,但所有内容都因以下信息而中断:

2021-08-27 18:39:24.004 Xamarin.PreBuilt.iOS[4330:1030659] Xamarin.iOS: Successfully received USB connection from the IDE on port 10000, fd: 6

2021-08-27 18:39:24.007 Xamarin.PreBuilt.iOS[4330:1030659] Xamarin.iOS: Processing: 'start profiler: no'
2021-08-27 18:39:24.007 Xamarin.PreBuilt.iOS[4330:1030624] Xamarin.iOS: Profiler not loaded (disabled)

Loaded assembly: /private/var/containers/Bundle/Application/092BCD0C-2FC9-4F1B-A83E-29D87ACD245E/SHAPP.iOS.app/Xamarin.iOS.dll [External]

2021-08-27 18:39:24.334 Xamarin.PreBuilt.iOS[4330:1030624] Xamarin.iOS: Unable to locate assembly 'SHAPP' (culture: '')

2021-08-27 18:39:24.334 Xamarin.PreBuilt.iOS[4330:1030624] Xamarin.iOS: Unable to locate assembly 'SHAPP' (culture: '')


Loaded assembly: /private/var/mobile/Containers/Data/Application/6FE32CF0-AE4D-41A2-BBBA-EAD56133AA7E/Documents/SHAPP.iOS.content/Xamarin.Forms.Core.dll [External]
2021-08-27 18:39:24.404 Xamarin.PreBuilt.iOS[4330:1030624] Xamarin.iOS: Unable to locate assembly 'FFImageLoading' (culture: '')

2021-08-27 18:39:24.404 Xamarin.PreBuilt.iOS[4330:1030624] Xamarin.iOS: Unable to locate assembly 'FFImageLoading' (culture: '')

Loaded assembly: /private/var/mobile/Containers/Data/Application/6FE32CF0-AE4D-41A2-BBBA-EAD56133AA7E/Documents/SHAPP.iOS.content/FFImageLoading.Platform.dll [External]
....
[0:] Failed to force load assembly /var/mobile/Containers/Data/Application/6FE32CF0-AE4D-41A2-BBBA-EAD56133AA7E/Documents/SHAPP.iOS.content/Forms9Patch.dll. Type:Forms9Patch.PopupLayerEffect. Exception: 'You must call Xamarin.Forms.Forms.Init(); prior to using this property.'. Callstack: '  at Xamarin.Forms.Device.get_PlatformServices () [0x00007] in D:\a\1\s\Xamarin.Forms.Core\Device.cs:87
  at Xamarin.Forms.Device.GetAssemblies () [0x00000] in D:\a\1\s\Xamarin.Forms.Core\Device.cs:245
  at Xamarin.Forms.DependencyService.Initialize () [0x00021] in D:\a\1\s\Xamarin.Forms.Core\DependencyService.cs:103
  at Xamarin.Forms.DependencyService.Get[T] (Xamarin.Forms.DependencyFetchTarget fetchTarget) [0x00000] in D:\a\1\s\Xamarin.Forms.Core\DependencyService.cs:28
  at Forms9Patch.Settings.ConfirmInitialization () [0x00008] in C:\Users\ben\Development\Xamarin\Forms9Patch\Forms9Patch\Forms9Patch\Models\Settings.cs:116
  at Forms9Patch.PopupLayerEffect..cctor () [0x00000] in C:\Users\ben\Development\Xamarin\Forms9Patch\Forms9Patch\Forms9Patch\Effects\PopupLayerEffect.cs:19 '
...
[0:] An error occurred: 'Could not create an native instance of the type 'Airbnb.Lottie.LOTAnimationView': the native class hasn't been loaded.
It is possible to ignore this condition by setting ObjCRuntime.Class.ThrowOnInitFailure to false.'. Callstack: '  at Foundation.NSObject.InitializeObject (System.Boolean alloced) [0x0002e] in /Users/builder/azdo/_work/1/s/xamarin-macios/src/Foundation/NSObject2.cs:247
  at Foundation.NSObject..ctor (Foundation.NSObjectFlag x) [0x0000d] in /Users/builder/azdo/_work/1/s/xamarin-macios/src/Foundation/NSObject2.cs:147
  at UIKit.UIResponder..ctor (Foundation.NSObjectFlag t) [0x00000] in /Users/builder/azdo/_work/1/s/xamarin-macios/src/build/ios/native/UIKit/UIResponder.g.cs:74
  at UIKit.UIView..ctor (Foundation.NSObjectFlag t) [0x00000] in

... --- 从先前抛出异常的位置开始的堆栈跟踪结束 ---

  at (wrapper managed-to-native) UIKit.UIApplication.UIApplicationMain(int,string[],intptr,intptr)
  at UIKit.UIApplication.Main (System.String[] args, System.IntPtr principal, System.IntPtr delegate) [0x00005] in /Users/builder/azdo/_work/1/s/xamarin-macios/src/UIKit/UIApplication.cs:86
  at UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) [0x0000e] in /Users/builder/azdo/_work/1/s/xamarin-macios/src/UIKit/UIApplication.cs:65
  at SHAPP.iOS.Application.Main (System.String[] args) [0x00001] in C:\VisualCSharp\MyProjects\SHAPP\SHAPP.iOS\Main.cs:17
  at (wrapper managed-to-native) System.Reflection.RuntimeMethodInfo.InternalInvoke(System.Reflection.RuntimeMethodInfo,object,object[],System.Exception&)
  at System.Reflection.RuntimeMethodInfo.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x0006a] in /Library/Frameworks/Xamarin.iOS.framework/Versions/Current/src/Xamarin.iOS/mcs/class/corlib/System.Reflection/RuntimeMethodInfo.cs:395 '
Die App wurde beendet.

应用程序代理:

using Foundation;
using Lottie.Forms.Platforms.Ios;
using UIKit;

namespace SHAPP.iOS
{
    // The UIApplicationDelegate for the application. This class is responsible for launching the
    // User Interface of the application, as well as listening (and optionally responding) to
    // application events from iOS.
    [Register("AppDelegate")]
    public partial class AppDelegate : global::Xamarin.Forms.Platform.iOS.FormsApplicationDelegate
    {
        //
        // This method is invoked when the application has loaded and is ready to run. In this
        // method you should instantiate the window, load the UI into it and then make the window
        // visible.
        //
        // You have 17 seconds to return from this method, or iOS will terminate your application.
        //
        public override bool FinishedLaunching(UIApplication app, NSDictionary options)
        {
            global::Xamarin.Forms.Forms.Init();
            Xamarin.Forms.Forms.Init();
            Forms9Patch.iOS.Settings.Initialize(this);
            FFImageLoading.Forms.Platform.CachedImageRenderer.Init();
            ZXing.Net.Mobile.Forms.iOS.Platform.Init();
           // ObjCRuntime.Class.ThrowOnInitFailure = false;
            LoadApplication(new App());

            //AnimationViewRenderer.Init();

            return base.FinishedLaunching(app, options);
        }
    }
}

设置旧的 Lottie Init 没有帮助。我取消了 iOS 中的所有 NuGet Lottiefiles 并重新安装了它们,我清理了项目并重新启动了构建,同样的错误。唯一可行的办法就是完全取消 Lottieusage。

Lottie-XAML:

<lottie:AnimationView
   Animation="14525-plumbers.json"
   AutoPlay="True"
   RepeatCount="3"
   RepeatMode="Restart"
   CacheComposition="True"
   HeightRequest="500"
   VerticalOptions="Start"
   HorizontalOptions="Center"
   IsVisible="true"
/>

如果我将其注释掉,一切都会正常。 LottieAnimationfile 位于我的资源文件夹 (BundledResource) 以及主文件夹中。

文件夹 iOS 和 LottieFiles

ios xamarin xamarin.forms
1个回答
0
投票

正如 Jason 提到的,您需要在 AppDelegate 中添加该行,如您在 此示例

中看到的那样

但是您还有另一个错误,因为您可以在共享的 StackTrace 末尾阅读错误消息:

An error occurred: 'Could not create an native instance of the type 'Airbnb.Lottie.LOTAnimationView': the native class hasn't been loaded.
It is possible to ignore this condition by setting ObjCRuntime.Class.ThrowOnInitFailure to false.'. Callstack: '  at Foundation.NSObject.InitializeObject (System.Boolean alloced) [0x0002e] in /Users/builder/azdo/_work/1/s/xamarin-macios/src/Foundation/NSObject2.cs:247 
  at Foundation.NSObject..ctor (Foundation.NSObjectFlag x) [0x0000d] in /Users/builder/azdo/_work/1/s/xamarin-macios/src/Foundation/NSObject2.cs:147 

您使用什么 Lottie 套餐?是这个吗?您使用的是最新版本吗? 您必须确保将 iOS 版本的 Lottie 包添加到 iOS 项目中。

© www.soinside.com 2019 - 2024. All rights reserved.