简体   繁体   English

WP8上的简单http请求被遮盖

[英]Simple http request on WP8 on obscured

So basically I made it so my app runs in the background if the phone is locked using this 所以基本上我做到了,如果手机使用此功能锁定,我的应用程序将在后台运行

PhoneApplicationService.Current.ApplicationIdleDetectionMode = IdleDetectionMode.Disabled;
PhoneApplicationService.Current.UserIdleDetectionMode = IdleDetectionMode.Disabled;

Then I created an event so when the application is obscured(the phone is locked) it would run doing the following. 然后,我创建了一个事件,以便当应用程序被遮盖(电话被锁定)时,它将运行以下操作。

PhoneApplicationFrame phoneAppRootFrame = RootFrame;
App.RootFrame.Obscured += RootFrame_Obscured;

Now here is my request code.. there has to be something wrong with it, though I'm not sure what anymore. 现在这是我的请求代码..一定有问题,尽管我不确定。 I've been trying so many different ways of just doing a simple get request, I don't even need to parse any response. 我一直在尝试许多不同的方式来做一个简单的get请求,我什至不需要解析任何响应。 It just never seems to work, anyways here it is: 它似乎永远都不会起作用,无论如何,它是:

private void RootFrame_Obscured(object sender, ObscuredEventArgs e)
{
  string url = "http://localhost:8080/someserver/javaQuery?request=storeId&id=someId";
  HttpWebRequest webRequest = (HttpWebRequest)HttpWebRequest.CreateHttp(url);
  webRequest.BeginGetResponse(new AsyncCallback(httpComplete), webRequest);
}

private static void httpComplete(IAsyncResult asyncResult){

}

I'm completely positive that the RootFrame_Obscured function is running, but the request code itself is probably wrong. 我完全肯定RootFrame_Obscured函数正在运行,但是请求代码本身可能是错误的。 Any insight would be helpful, thanks. 任何见解都会有所帮助,谢谢。

You are not allowed to perform network calls under the lock screen. 在锁定屏幕下,您无法执行网络呼叫。

Checklist for apps that disable app idle detection 禁用应用程序空闲检测的应用程序清单

If your Windows Phone app disables app idle detection to run under the lock screen, you should perform the following tasks to reduce your app's power consumption while the lock screen is engaged. 如果您的Windows Phone应用程序禁用了在锁定屏幕下运行的应用程序空闲检测, 则应执行以下任务来减少锁定屏幕接合时应用程序的功耗。

  • Signal your app that new network requests and isolated storage operations shouldn't be performed. 通知您的应用,新的网络请求和隔离的存储操作不应执行。

If you need to track this event you can do that in Unobscured event handler. 如果您需要跟踪此事件,可以在Unobscured事件处理程序中进行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM