Forum Xamarin.Forms

Using Camera and Location Cause iOS 10 app to crash

PhilMcVeighPhilMcVeigh NZMember ✭✭
edited November 2016 in Xamarin.Forms

I have been using the Xamarin.Plugins (Plugin.Geolocator & Plugin.Media) for several months now. I think they are great, and they work perfectly on Android & UWP.

Only recently, I have been able to test them on an iPhone (10.1.1), but for some reason, they keep causing the app to crash.

The media plugin takes the photo, but once the camera attempts to return to the page it was called from, the app crashes.

The geolocator causes the app to crash when setting the following properties:
IGeolocator locator = CrossGeolocator.Current; locator.PausesLocationUpdatesAutomatically = false; locator.AllowsBackgroundUpdates = true; locator.DesiredAccuracy = 5;

I have followed the plugin guidelines here:
and the permissions guidelines :

Everything relevant is up to date (Xamarin on Windows 10 & Mac, Xamarin.Forms, Plugins, Xcode etc.).

Maybe I have missed something in the permissions sections?

I have these in my 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>

In addition the app asks the user for camera & photo library permission when it starts (before the take photo button page gets displayed). It does not ask the user for any location persmissions.

Asking user for Camera permission:
bool isAuthorised = await AVCaptureDevice.RequestAccessForMediaTypeAsync(AVMediaType.Video);

Asking user for Photo Library permissions:
PHPhotoLibrary.RequestAuthorization(status => { switch (status) { case PHAuthorizationStatus.Authorized: break; case PHAuthorizationStatus.Denied: break; case PHAuthorizationStatus.Restricted: break; default: break; } });

After trying to take a photo I keep getting a null reference exception in Main.cs containing the following:
...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...

Not sure if this is related, but if I try to use my own code for taking a photo, I keep getting:
UIKit Consistency error: you are calling a UIKit method that can only be invoked from the UI thread.

I'm not sure what I'm doing wrong, but any help or info on the matter would be greatly appreciated


  • advitiiyaadvitiiya Member ✭✭
    Hey I m using Plugin media for my Android application, followed all the instructions, but gives exception unable to get file location when camera is accused. If u have working code, please share
Sign In or Register to comment.