Xamarin.Plugins导致iOS 10应用程序崩溃

时间:2016-11-18 03:46:39

标签: c# ios iphone xamarin.ios

我已经使用Xamarin.Plugins(Xam.Plugin.Geolocator& Xam.Plugin.Media)几个月了,它们在Android& amp; UWP。

直到最近,我才能在iPhone(10.1.1)上测试它们,但由于某种原因,它们会导致应用程序崩溃。

媒体插件拍摄照片,但是一旦相机尝试返回到调用它的页面,应用程序就会崩溃。

设置以下属性时,地理定位器会导致应用崩溃:

IGeolocator locator = CrossGeolocator.Current;
                locator.PausesLocationUpdatesAutomatically = false;
                locator.AllowsBackgroundUpdates = true;
                locator.DesiredAccuracy = 5;

我在此处遵循了插件指南:https://github.com/jamesmontemagno/MediaPlugin 和权限指南:https://blog.xamarin.com/new-ios-10-privacy-permission-settings/

所有相关内容都是最新的(Xamarin在Windows 10和Mac,Xamarin.Forms,插件,Xcode等)。

也许我错过了权限部分的内容? 我在Info.plist中有这些

<key>NSLocationAlwaysUsageDescription</key>
        <string>This will be called if location is used behind the scenes</string>
        <key>NSLocationWhenInUseUsageDescription</key>
        <string>You are about to use location!</string>
        <key>NSCameraUsageDescription</key>
        <string>This app needs access to the camera to take photos.</string>
        <key>NSLocationUsageDescription</key>
        <string>This app needs access to the location.</string>
        <key>NSPhotoLibraryUsageDescription</key>
        <string>This app requires access to the photo library.</string>

此外,该应用程序要求用户提供相机和相机;照片库启动时的权限(在拍摄照片按钮页面显示之前)。它不会要求用户提供任何位置信息。

向用户询问相机权限:

bool isAuthorised = await AVCaptureDevice.RequestAccessForMediaTypeAsync(AVMediaType.Video);

要求用户提供照片库权限:

  PHPhotoLibrary.RequestAuthorization(status =>
                                 {
                                     switch (status)
                                     {
                                         case PHAuthorizationStatus.Authorized:
                                             break;
                                         case PHAuthorizationStatus.Denied:
                                             break;
                                         case PHAuthorizationStatus.Restricted:
                                             break;
                                         default:
                                             break;
                                     }
                                 });

尝试拍摄照片后,我在Main.cs中继续获得包含以下内容的空引用异常:

...System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in /Users/builder/data/lanes/3969/44931ae8/source/xamarin-macios/_ios-build/Library/Frameworks/Xamarin.iOS.framework/Versions/git/src/mono/mcs/class/referencesource/mscorlib/system/runtime/exceptionservices/exceptionservicescommon.cs:143 \n  at System.Runtime.CompilerServices.AsyncMethodBuilderCore.<ThrowAsync>m__0 (System.Object state) [0x00000] in /Users/builder/data/lanes/3969/44931ae8/source/xamarin-macios/_ios-build/Library/Frameworks/Xamarin.iOS.framework/Versions/git/src/mono/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/AsyncMethodBuilder.cs:1018 \n  at UIKit.UIKitSynchronizationContext+<Post>c__AnonStorey0.<>m__0 () [0x00000] in /Users/builder/data/lanes/3969/44931ae8/source/xamarin-macios/src/UIKit/UIKitSynchronizationContext.cs:24 \n  at Foundation.NSAsyncActionDispatcher.Apply () [0x00000] in /Users/builder/data/lanes/3969/44931ae8/source/xamarin-macios/src/Foundation/NSAction.cs:163 \n  at (wrapper managed-to-native) UIKit.UIApplication:UIApplicationMain (int,string[],intptr,intptr)\n  at UIKit.UIApplication.Main (System.String[] args, System.IntPtr principal, System.IntPtr delegate) [0x00005] in /Users/builder/data/lanes/3969/44931ae8/source/xamarin-macios/src/UIKit/UIApplication.cs:79 \n  at UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) [0x00038] in /Users/builder/data/lanes/3969/44931ae8/source/xamarin-macios/src/UIKit/UIApplication.cs:63 \n...

不确定这是否相关,但如果我尝试使用自己的代码拍照,我会继续说:

UIKit Consistency error: you are calling a UIKit method that can only be invoked from the UI thread.

我不确定我做错了什么,但对此事的任何帮助或信息都将不胜感激

0 个答案:

没有答案