#開発環境
Visual Studio 2017 Community 15.9.4
Xamarin.Forms 3.4.0.1009999
Plugin.Permissions 3.0.0.12
Xam.Plugin.Geolocator 4.5.0.6
#やりたいこと
GPSの起動状態を取得し、起動していない場合にアラートを表示したい。
#コード
XAML
1<?xml version="1.0" encoding="utf-8" ?> 2<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" 3 xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" 4 x:Class="App.Page0" 5 Title="状態確認"> 6 <ContentPage.Content> 7 <AbsoluteLayout> 8 <ActivityIndicator x:Name="Indicator" 9 IsRunning="True" 10 Color="Gray" 11 AbsoluteLayout.LayoutBounds=".5,.5,.5,.5" 12 AbsoluteLayout.LayoutFlags="All"/> 13 </AbsoluteLayout> 14 </ContentPage.Content> 15</ContentPage>
C#
1protected override async void OnAppearing() 2{ 3 base.OnAppearing(); 4 5 var hasPermission = await Utils.CheckPermissions(Permission.Location); 6 if (!hasPermission) 7 { 8 await DisplayAlert(null, "位置情報を許可してください。", "OK"); // Android 5.0.1のため通らないが多分ここも表示されない 9 } 10 if (!CrossGeolocator.Current.IsGeolocationEnabled) 11 { 12 await DisplayAlert(null, "GPSをオンにしてください。", "OK"); // ここが表示されない 13 } 14 15 Application.Current.MainPage = new Page1(); 16}
#試したこと
awaitを外してみましたがif文には入るものの何も表示されずにページ遷移してしまいました。
Console.WriteLineでif文に入ってきているか確認すると問題なく入ってきていたので、DisplayAlertが問題だと思います。
タイトルがnullなのが問題かと思い、文字列を入れてみましたが上手く動きませんでした。
ConfigureAwait(false)をつけてみましたが、こちらも動きませんでした。
Waitをつけようとしましたが、戻り値がvoidなので出来ませんでした。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
退会済みユーザー
2019/01/26 01:58