我想通过使用带有mailto,主题和邮件正文的开放URL来打开电子邮件 你可以看到下面的代码
string email = "me@example.com";
string subject = "MySubject";
string body = "Myboday";
var idn = new System.Globalization.IdnMapping();
var dotnetURI = new System.Uri("mailto:" + email + "?subject:" + subject + "&body:" + body);
Console.WriteLine(dotnetURI.ToString());
NSUrl nsURL = new NSUrl(dotnetURI.Scheme, idn.GetAscii(dotnetURI.DnsSafeHost), dotnetURI.PathAndQuery);
UIApplication.SharedApplication.OpenUrl(nsURL);
但我收到有关绝对路径的错误
你可以帮我吗? 提前谢谢答案 0 :(得分:1)
您可以使用NSString.CreateStringByAddingPercentEscapes
方法转义字符串:
string email = "me@example.com";
string subject = "Hello StackOverflow";
string body = "Happy Holdays";
using (var encoded = new NSString($"mailto:{email}?subject={subject}&body={body}").CreateStringByAddingPercentEscapes(NSStringEncoding.UTF8))
using (var url = NSUrl.FromString(encoded))
{
UIApplication.SharedApplication.OpenUrl(url);
}
NSWorkspace.SharedWorkspace.OpenUrl(url);
注意:相同的代码用UIApplication.SharedApplication
替换NSWorkspace.SharedWorkspace