使用
时出现异常BackgroundTaskRegistration taskRegistration = taskBuilder.Register();
例外:
访问被拒绝。 (来自HRESULT的异常:0x80070005(E_ACCESSDENIED))在Windows.ApplicationModel.Background.BackgroundTaskBuilder.Register()
我的代码段
BackgroundTaskBuilder taskBuilder = new BackgroundTaskBuilder();
SmsMessageReceivedTrigger trigger = new SmsMessageReceivedTrigger(filterRules);
taskBuilder.SetTrigger(trigger);
taskBuilder.TaskEntryPoint = "SmsBackgroundTask.SampleSmsBackgroundTask";
taskBuilder.Name = "SampleSmsBackgroundTask";
BackgroundTaskRegistration taskRegistration = taskBuilder.Register();
appxmanifest:
<Package xmlns="http://schemas.microsoft.com/appx/manifest/foundation/windows10"
xmlns:mp="http://schemas.microsoft.com/appx/2014/phone/manifest"
xmlns:uap="http://schemas.microsoft.com/appx/manifest/uap/windows10"
xmlns:rescap="http://schemas.microsoft.com/appx/manifest/foundation/windows10/restrictedcapabilities"
IgnorableNamespaces="uap mp rescap">`
<Capabilities>
<Capability Name="internetClient" />
<rescap:Capability Name="cellularMessaging" />
</Capabilities>
</Package>
<rescap:Capability Name="cellularMessaging" />
警告:
命名空间“http://schemas.microsoft.com/appx/manifest/foundation/windows10”中的“功能”元素在命名空间“http://schemas.microsoft.com/appx/manifest/foundation/windows10/restrictedcapabilities”中具有无效的子元素“功能”
推荐this链接,用于创建后台任务。