Xamarin.Forms 네트워크에 연결할 수 있는지 확인
5548 단어 XamarinXamarin.Forms
하고 싶은 일
Xamarin.Forms에서 네트워크에 연결할 수 있는지 결정 (물론 크로스 플랫폼에서)
※2017/01/31 현재 Android는 동작하지 않았습니다(정보 제공 부탁드립니다...)
라이브러리 도입
NuGet을 사용하여 Connectivity Plugin for Xamarin and Windows
를 추가합니다.

코드
CheckNetworkConnectionPage.csusing System;
using System.Collections.Generic;
using Plugin.Connectivity;
using Xamarin.Forms;
namespace XamarinSamples
{
public partial class CheckNetworkConnectionPage : ContentPage
{
public CheckNetworkConnectionPage()
{
InitializeComponent();
CrossConnectivity.Current.ConnectivityTypeChanged += Current_ConnectivityTypeChanged;
}
private async void Current_ConnectivityTypeChanged(object sender, Plugin.Connectivity.Abstractions.ConnectivityTypeChangedEventArgs e)
{
if (!e.IsConnected)
{
await DisplayAlert("Error", "Check for your connection.", "OK");
}
else {
await DisplayAlert("Success", "Network is Available.", "OK");
}
}
protected async override void OnAppearing()
{
base.OnAppearing();
if (!CrossConnectivity.Current.IsConnected)
{
System.Diagnostics.Debug.WriteLine("connected");
await DisplayAlert("Error", "Check for your connection", "OK");
}
else {
await DisplayAlert("Success", "Network is Available.", "OK");
}
}
}
}
동작 확인
iOS

안드로이드

초본
Reference
이 문제에 관하여(Xamarin.Forms 네트워크에 연결할 수 있는지 확인), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다
https://qiita.com/harhogefoo/items/7588cdbeecd22f02769c
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)
NuGet을 사용하여
Connectivity Plugin for Xamarin and Windows
를 추가합니다.
코드
CheckNetworkConnectionPage.csusing System;
using System.Collections.Generic;
using Plugin.Connectivity;
using Xamarin.Forms;
namespace XamarinSamples
{
public partial class CheckNetworkConnectionPage : ContentPage
{
public CheckNetworkConnectionPage()
{
InitializeComponent();
CrossConnectivity.Current.ConnectivityTypeChanged += Current_ConnectivityTypeChanged;
}
private async void Current_ConnectivityTypeChanged(object sender, Plugin.Connectivity.Abstractions.ConnectivityTypeChangedEventArgs e)
{
if (!e.IsConnected)
{
await DisplayAlert("Error", "Check for your connection.", "OK");
}
else {
await DisplayAlert("Success", "Network is Available.", "OK");
}
}
protected async override void OnAppearing()
{
base.OnAppearing();
if (!CrossConnectivity.Current.IsConnected)
{
System.Diagnostics.Debug.WriteLine("connected");
await DisplayAlert("Error", "Check for your connection", "OK");
}
else {
await DisplayAlert("Success", "Network is Available.", "OK");
}
}
}
}
동작 확인
iOS

안드로이드

초본
Reference
이 문제에 관하여(Xamarin.Forms 네트워크에 연결할 수 있는지 확인), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다
https://qiita.com/harhogefoo/items/7588cdbeecd22f02769c
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)
using System;
using System.Collections.Generic;
using Plugin.Connectivity;
using Xamarin.Forms;
namespace XamarinSamples
{
public partial class CheckNetworkConnectionPage : ContentPage
{
public CheckNetworkConnectionPage()
{
InitializeComponent();
CrossConnectivity.Current.ConnectivityTypeChanged += Current_ConnectivityTypeChanged;
}
private async void Current_ConnectivityTypeChanged(object sender, Plugin.Connectivity.Abstractions.ConnectivityTypeChangedEventArgs e)
{
if (!e.IsConnected)
{
await DisplayAlert("Error", "Check for your connection.", "OK");
}
else {
await DisplayAlert("Success", "Network is Available.", "OK");
}
}
protected async override void OnAppearing()
{
base.OnAppearing();
if (!CrossConnectivity.Current.IsConnected)
{
System.Diagnostics.Debug.WriteLine("connected");
await DisplayAlert("Error", "Check for your connection", "OK");
}
else {
await DisplayAlert("Success", "Network is Available.", "OK");
}
}
}
}
iOS

안드로이드

초본
Reference
이 문제에 관하여(Xamarin.Forms 네트워크에 연결할 수 있는지 확인), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://qiita.com/harhogefoo/items/7588cdbeecd22f02769c텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)