首页 文章

uwp相机正在关闭认证的应用程序

提问于
浏览
0

在我的uwp应用程序中,我对Windows手机的相机有一个非常奇怪的问题 . 如果我在发布或调试模式下执行我的代码,一切都进展顺利,但如果我填充appxupload文件并将其提交到商店,如果我执行代码,应用程序将关闭 .

public async void startcamera()
    {
        CameraCaptureUI dialog = new CameraCaptureUI();
        Size aspectRatio = new Size(16, 9);
        dialog.PhotoSettings.CroppedAspectRatio = aspectRatio;
        dialog.PhotoSettings.Format = CameraCaptureUIPhotoFormat.Jpeg;
        dialog.PhotoSettings.MaxResolution = CameraCaptureUIMaxPhotoResolution.SmallVga;
        StorageFile file = await dialog.CaptureFileAsync(CameraCaptureUIMode.Photo);
        if (file != null)
        {
           //do stuff
        }

    }

问题只出现在Windows手机上(我试过不同的设备),如果我在带有网络摄像头的x86设备上安装应用程序,它可以正常工作 .

我读到了一些关于不支持的解决方案的内容,但正如我所说,在发布或调试模式下,它甚至可以在Windows Phone上运行,没有任何问题 .

有任何想法吗?

1 回答

  • 0

    让您的应用程序通过认证的快速简便方法是将代码包装在 try-catch 中,这样可以防止您的应用崩溃 .

    在解决方案方面,您可以修改代码,如:

    internal async void PickFromCamera()
    {
       RestartZone:
       try
       {
          CameraCaptureUI captureUI = new CameraCaptureUI();
          captureUI.PhotoSettings.Format = CameraCaptureUIPhotoFormat.Jpeg;
          captureUI.PhotoSettings.CroppedSizeInPixels = new Size(300, 150);
    
          StorageFile photo = await captureUI.CaptureFileAsync(CameraCaptureUIMode.Photo);
          await HandleFileOperationsAndStorage(photo);
        }
        catch (Exception ex)
        {
           var promptResponse = await MessageDialogHelper.ShowTwoActionsMessageBox($"Somehting went wrong while decoding the image from the camera. Please make sure no other operation is being carried out. \nMore Information: {ex.Message}", "Operation Failed", "Try Again", "Cancel");
           if (promptResponse)
               goto RestartZone;
         }
    }
    

    它应该工作得很好 .

    消息对话框助手是我处理所有消息框弹出窗口的类,您可以在那里进行自己的错误处理 .

相关问题