728x90
728x170
앱에서 text,uri,file 을 Share 하는 방법입니다.
iOS 에는 아래의 내용이 info.list 에 추가되어야합니다.
<key>NSPhotoLibraryAddUsageDescription</key> <string>This app needs access to the photo gallery to save photos and videos.</string> <key>NSPhotoLibraryUsageDescription</key> <string>This app needs access to the photo gallery to save photos and videos.</string> |
MainPage.xaml
<HorizontalStackLayout>
<Entry x:Name="shareEntry" Text="http://kjun.kr" />
<Button
x:Name="textShareButton"
Margin="5"
Clicked="textShareButton_Clicked"
Text="Test Share" />
<Button
x:Name="uriShareButton"
Margin="5"
Clicked="uriShareButton_Clicked"
Text="Uri Share" />
</HorizontalStackLayout>
MainPage.xaml.cs
private async void textShareButton_Clicked(object sender, EventArgs e)
{
await ShareText(this.shareEntry.Text);
}
private async void uriShareButton_Clicked(object sender, EventArgs e)
{
await ShareUri(this.shareEntry.Text, Share.Default);
}
public async Task ShareText(string text)
{
if (string.IsNullOrEmpty(text)) return;
await Share.Default.RequestAsync(new ShareTextRequest
{
Text = text,
Title = "Share Text"
});
}
public async Task ShareUri(string uri, IShare share)
{
if (string.IsNullOrEmpty(uri)) return;
await share.RequestAsync(new ShareTextRequest
{
Uri = uri,
Title = "Share Web Link"
});
}
public async Task ShareFile()
{
string fn = "Attachment.txt";
string file = Path.Combine(FileSystem.CacheDirectory, fn);
File.WriteAllText(file, "Hello World");
await Share.Default.RequestAsync(new ShareFileRequest
{
Title = "Share text file",
File = new ShareFile(file)
});
}
결과
[Source]
https://github.com/kei-soft/Maui.BasicApp
728x90
그리드형
'C# > Xamarin Maui' 카테고리의 다른 글
[.NET MAUI] Splash screen 이미지 원형으로 잘리는 문제 (0) | 2023.04.14 |
---|---|
[.NET MAUI] Google reCAPTCHA (0) | 2023.04.12 |
[.NET MAUI] Login Sample Page (0) | 2023.04.04 |
[.NET MAUI] NavigationPage Bar color 변경하기 (0) | 2023.03.23 |
figma to maui graphics (0) | 2023.03.22 |