我的主页以异步方式发送 API 请求,然后将主页设置为其他页面,如下所示:
async private void GetContacts()
{
try
{
activityIndicator.IsVisible = true;
activityIndicator.IsRunning = true;
var contacts = await Plugin.ContactService.CrossContactService.Current.GetContactListAsync();
var contactsWithPhone = contacts != null && contacts.Count > 0 ?
contacts.Where(c => c.Number != null && c.Number.Trim().Length > 0) : contacts;
if (contactsWithPhone.Count() > 0)
{
Application.Current.Properties["FirstTime"] = false;
activityIndicator.IsVisible = false;
activityIndicator.IsRunning = false;
List<NewsletterSubscriber> subscribers = new List<NewsletterSubscriber>();
foreach (Plugin.ContactService.Shared.Contact contact in contactsWithPhone)
{
subscribers.Add(new NewsletterSubscriber() { Name = contact.Name != null && contact.Name.Trim().Length > 0 ? contact.Name : "Unknown", Phone = contact.Number });
}
SendContacts(subscribers);
}
Application.Current.MainPage = new MainPage();
}
catch(Exception)
{ throw; }
}
async void SendContacts(List<NewsletterSubscriber> subscribers)
{
var httpClient = new HttpClient();
NewsletterSubscriberRoot newsletterSubscriberRoot = new NewsletterSubscriberRoot();
newsletterSubscriberRoot.newsletterSubscribers = subscribers.OrderBy(c => c.Name).ToList();
var content = newsletterSubscriberRoot.AsJson();
try
{
var result = await httpClient.PostAsync(url, content);
}
catch (Exception)
{
throw;
}
}
现在的问题是,当包含 WebView 的页面在应用程序启动时设置为主页时,它可以正常打开网站。但是当它从另一个主页设置时,它会进入 Navigated 事件的失败部分。我在输出窗口中没有看到任何异常。
UYOU
相关分类