Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/xamarin/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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/31.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.UITesting中与摄影机卷交互?_Xamarin_Xamarin.ios_Visual Studio App Center_Xamarin.uitest - Fatal编程技术网

如何在Xamarin.UITesting中与摄影机卷交互?

如何在Xamarin.UITesting中与摄影机卷交互?,xamarin,xamarin.ios,visual-studio-app-center,xamarin.uitest,Xamarin,Xamarin.ios,Visual Studio App Center,Xamarin.uitest,我一直在尝试在Xamarin.iOS中点击相机卷,当它在我的应用程序中打开时使用Xamarin.ui进行测试,但由于它是操作系统的一部分,我无法使用点击功能选择相机卷,然后选择图像。使用app.Repl(),它的显示方式如下: [CalabashRootView] [UIWindow > ... > UILayoutContainerView] [U

我一直在尝试在Xamarin.iOS中点击相机卷,当它在我的应用程序中打开时使用Xamarin.ui进行测试,但由于它是操作系统的一部分,我无法使用点击功能选择相机卷,然后选择图像。使用app.Repl(),它的显示方式如下:

[CalabashRootView]                                                              
  [UIWindow > ... > UILayoutContainerView]
    [UINavigationTransitionView > ... > _UISizeTrackingView]
      [_UIRemoteView] id: "RemoteViewBridge"
    [UINavigationBar] id: "Photos"
      [_UIBarBackground]
        [UIImageView]
        [UIVisualEffectView]
          [_UIVisualEffectBackdropView]
          [_UIVisualEffectSubview]
      [_UINavigationBarContentView]
        [_UIButtonBarStackView]
          [_UIButtonBarButton] label: "Cancel"
            [_UIModernBarButton] label: "Cancel"
              [UIButtonLabel] label: "Cancel",  text: "Cancel"
        [UILabel] label: "Photos",  text: "Photos"
      [UILabel] label: "Photos",  text: "Photos"
      [_UIButtonBarButton] label: "Cancel"
        [_UIModernBarButton] label: "Cancel"
          [UIButtonLabel] label: "Cancel",  text: "Cancel"
  [UIWindow > UILayoutContainerView]
    [UINavigationTransitionView > ... > UITableView]
      [WelcomeScreenCustomCell]
        [UITableViewCellContentView]
          [UIView]
我试图通过后门将图像推入照片选择过程,但似乎无法正常工作(这是我的AppDelegate):


有人有过这样的经历吗?有没有办法只选择一张图片?

你可以使用Nuget的插件MediaPlugin

不要忘记在indo.plist中添加NSCameraUsageDescriptionNSPhotoLibraryUsageDescription,以便访问设备的相机和照片/视频库

<key>NSCameraUsageDescription</key>
<string>This app needs access to the camera to take photos.</string>
<key>NSPhotoLibraryUsageDescription</key>
<string>This app needs access to photos.</string>
<key>NSMicrophoneUsageDescription</key>
<string>This app needs access to microphone.</string>
<key>NSPhotoLibraryAddUsageDescription</key>
<string>This app needs access to the photo gallery.</string>
<key>NSCameraUsageDescription</key>
<string>This app needs access to the camera to take photos.</string>
<key>NSPhotoLibraryUsageDescription</key>
<string>This app needs access to photos.</string>
<key>NSMicrophoneUsageDescription</key>
<string>This app needs access to microphone.</string>
<key>NSPhotoLibraryAddUsageDescription</key>
<string>This app needs access to the photo gallery.</string>
async void TakePhoto()
    {
        await CrossMedia.Current.Initialize();

        if (!CrossMedia.Current.IsCameraAvailable || !CrossMedia.Current.IsTakePhotoSupported)
        {
            // No camera available.
            return;
        }

        var file = await CrossMedia.Current.TakePhotoAsync(new StoreCameraMediaOptions
        {
            Directory = "Sample",
            Name = "test.jpg"
        });

        if (file == null)
            return;

        var ImagePath = file.Path;
        //... do something you want
    }