BackgroundTaskBuilder Register()问题 [英] BackgroundTaskBuilder Register() issue

查看:86
本文介绍了BackgroundTaskBuilder Register()问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我遇到问题时,我正在使用Geofencing开发应用程序:

I was developing application with Geofencing, when stuck at issue:

ArgumentException(值不在预期范围内)当我尝试注册地理围栏的后台任务时.

ArgumentException (Value does not fall within the expected range) when I am trying to register background task for geofencing.

来自MSDN的示例具有相同的问题.为了清楚起见,我将显示示例代码(链接到示例: http://code.msdn.microsoft.com/windowsapps/Geolocation-2483de66#content 使用场景5 http://msdn.microsoft.com/en-us/library/windows/apps/dn440583.aspx -有关如何测试的说明).

Sample from MSDN has the same problem. I will show code from sample for clarity (link to sample: http://code.msdn.microsoft.com/windowsapps/Geolocation-2483de66#content use scenario 5, http://msdn.microsoft.com/en-us/library/windows/apps/dn440583.aspx - instruction how to test).

我所做的所有事情:

  1. 在Visual Studio中构建我的应用.
  2. 首先在本地部署应用程序,然后将其添加到设置"中的锁定屏幕.
  3. 关闭在本地运行的应用.
  4. 在Visual Studio模拟器中启动您的应用程序.
  5. 调用RegisterBackgroundTask(..)(在方案5中只需按一下按钮即可注册)

我已评论了MSDN示例中的代码,以便在Simulator中成功部署应用程序-标记为//////[我的更改]////////

There is code from MSDN sample that I have commented for successful app deploying in Simulator - tagged with ////// [my changes] ////////

    async private void RegisterBackgroundTask(object sender, RoutedEventArgs e)
    {
        try
        {

            // Get permission for a background task from the user. If the user has already answered once,
            // this does nothing and the user must manually update their preference via PC Settings.
            //BackgroundAccessStatus backgroundAccessStatus = await BackgroundExecutionManager.RequestAccessAsync();  ////// [my changes] ////////

            // Regardless of the answer, register the background task. If the user later adds this application
            // to the lock screen, the background task will be ready to run.
            // Create a new background task builder
            BackgroundTaskBuilder geofenceTaskBuilder = new BackgroundTaskBuilder();

            geofenceTaskBuilder.Name = SampleBackgroundTaskName;
            geofenceTaskBuilder.TaskEntryPoint = SampleBackgroundTaskEntryPoint;

            // Create a new location trigger
            var trigger = new LocationTrigger(LocationTriggerType.Geofence);

            // Associate the locationi trigger with the background task builder
            geofenceTaskBuilder.SetTrigger(trigger);

            // If it is important that there is user presence and/or
            // internet connection when OnCompleted is called
            // the following could be called before calling Register()
            // SystemCondition condition = new SystemCondition(SystemConditionType.UserPresent | SystemConditionType.InternetAvailable);
            // geofenceTaskBuilder.AddCondition(condition);

            // Register the background task
            geofenceTask = geofenceTaskBuilder.Register();

            // Associate an event handler with the new background task
            geofenceTask.Completed += new BackgroundTaskCompletedEventHandler(OnCompleted);

            UpdateButtonStates(/*registered:*/ true);

            ////// [my changes] ////////
            //switch (backgroundAccessStatus)
            //{
            //    case BackgroundAccessStatus.Unspecified:
            //    case BackgroundAccessStatus.Denied:
            //        rootPage.NotifyUser("This application must be added to the lock screen before the background task will run.", NotifyType.ErrorMessage);
            //        break;

            //    default:
            //        // Ensure we have presented the location consent prompt (by asynchronously getting the current
            //        // position). This must be done here because the background task cannot display UI.
            //        GetGeopositionAsync();
            //        break;
            //}
            ////// [my changes] ////////
        }
        catch (Exception ex)
        {
            // HRESULT_FROM_WIN32(ERROR_NOT_SUPPORTED) == 0x80070032
            const int RequestNotSupportedHResult = unchecked((int)0x80070032);

            if (ex.HResult == RequestNotSupportedHResult)
            {
                rootPage.NotifyUser("Location Simulator not supported.  Could not get permission to add application to the lock screen, this application must be added to the lock screen before the background task will run.", NotifyType.StatusMessage);
            }
            else
            {
                rootPage.NotifyUser(ex.ToString(), NotifyType.ErrorMessage);
            }

            UpdateButtonStates(/*registered:*/ false);
        }
    }

异常落在字符串上: geofenceTask = geofenceTaskBuilder.Register();

有人可以帮助我吗?

P.S.msdn上的相同问题线程-

P.S. Same question thread on msdn - http://social.msdn.microsoft.com/Forums/en-US/3d69f2f9-93e0-401b-8a13-598dc671fa4f/backgroundtask-register?forum=winappswithcsharp

推荐答案

这是一个已知的错误",请参见

This is a known "bug" see Windows Store 8.1 Location background tasks do not work in simulator. I have yet to get an answer other than

您的问题已发送给相应的VS开发团队进行调查

Your issue has been routed to the appropriate VS development team for investigation

请投票!

这篇关于BackgroundTaskBuilder Register()问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆