2016-04-24 12 views
0

私のアプリで画像を選択できるようにユーザーフォトアルバム(iOS)を開く画像ピッカーがあります。私はxamarinクロスプラットフォームを使用していますので、このコードの塊につながる依存サービスがあります。それ以降はすべて正しいコードを取得しましたが、画像ピッカーは最初の1,2回は表示されず、ユーザーがアプリ全体を更新した後にのみ動作するようになっています。私はNavigationController.PresentModalViewControllerを試みたが、ちょうどヌルエラーで終了しているImagePickerがXamarinに表示されない

 imagePicker = new UIImagePickerController(); 
     imagePicker.SourceType = UIImagePickerControllerSourceType.PhotoLibrary; 
     imagePicker.MediaTypes = UIImagePickerController.AvailableMediaTypes (UIImagePickerControllerSourceType.PhotoLibrary); 
     imagePicker.FinishedPickingMedia += Handle_FinishedPickingMedia; 
     imagePicker.Canceled += Handle_Canceled; 
     //Show the picker 
     UIApplication.SharedApplication.KeyWindow.RootViewController.PresentModalViewController (imagePicker, true); 

注:ここで私はピッカーを作成するために使用しています次のコードがあります。私もちょうど "PresentViewController"を試してみましたが、そこに助けはありません。また、画像ピッカーを表示する方法がありますか?どんな助けでも大歓迎です!

答えて

2

代わりDependencyServiceを使用しての、Xamarin Mediaプラグインを試してみてください。

var file = await CrossMedia.Current.PickPhotoAsync(); 
+0

どのように私はXamarinメディアプラグインを使用してピッカーが表示されないだろう –

+0

私が示しただけのよう - ?PickPhotoAsync()メソッドは、(任意のプラットフォーム上で)ピッカーを表示してMediaFileがオブジェクトを返します。選択した画像。TakePhotoAsync()を使用してカメラで写真を撮ることもできます。サンプルとソースはhttps://github.com/jamesmontemagno/Xamarin.Plugins/tree/master/Media – Jason

+0

ありがとう多く!それは今働いています:) –

0

PresentModalViewControllerは6.0 https://developer.xamarin.com/api/member/UIKit.UIViewController.PresentModalViewController/p/UIKit.UIViewController/System.Boolean/

で廃止され、この行を変更してみてください:

これに
UIApplication.SharedApplication.KeyWindow.RootViewController.PresentModalViewController (imagePicker, true); 

UIApplication.SharedApplication.KeyWindow.RootViewController.PresentViewController (imagePicker, true, null); 
+0

はまだ運:( –

0

ModalPresentationStyleプロパティを設定していないようです。私は、あなたのPresentModalViewControllerメソッドのアクションハンドラパラメータが不足していることにも気付きました。

imagePicker.ModalPresentationStyle = UIModalPresentationStyle.Popover; 
+0

この行のコードとアクションハンドラパラメータが追加されました。これは奇妙なバグです。 –

関連する問題