我正在尝试将我的C#WP 8.1背景音频任务带到UWP并且一切正常,除了尝试使用Windows获取UVC.Media.Playback.SystemMediaTransportControls.GetForCurrentView()在桌面设备上抛出当前异常:"找不到与此MediaPlaybackControl实例关联的适当视图.请确保已初始化视图".它只是一种尚未融合的行为,还是我需要通过桌面类设备上的应用程序来控制和更新UVC?
我想用iPhone在后台更新我的手表应用程序状态 session.updateApplicationContext(applicationContext).
在手表上的应用程序处于活动状态时发送应用程序联系人可以正常工作.
当我激活手表上的主页按钮时,手表应用程序会进入后台,handle(_ backgroundTasks: Set<WKRefreshBackgroundTask>)被呼叫并WKSnapshotRefreshBackgroundTask提供一个.
所以我不明白为什么a WKSnapshotRefreshBackgroundTask被正确触发,但不是a WKWatchConnectivityRefreshBackgroundTask.
Apple的文档说:" 当您从配对的iPhone接收后台数据时,系统会在后台启动您的应用程序,实例化一个WKWatchConnectivityRefreshBackgroundTask对象,并将任务对象传递给您的扩展委托的handleBackgroundTasks:方法.".
但这不会发生在设备上,也不会发生在模拟器上.可能有什么不对?
编辑:
为了检查可能出错的地方,我下载了Apple的演示项目"QuickSwitch",可在此处下载.以下是应该处理后台任务的代码:
func handle(_ backgroundTasks: Set<WKRefreshBackgroundTask>) {
for backgroundTask in backgroundTasks {
if let wcBackgroundTask = backgroundTask as? WKWatchConnectivityRefreshBackgroundTask {
// store a reference to the task objects as we might have to wait to complete them
self.wcBackgroundTasks.append(wcBackgroundTask)
} else {
// immediately complete all other task types as we have not added support for them …Run Code Online (Sandbox Code Playgroud) 我正在编写一个可以在后台任务中显示Toast通知的应用程序 (我使用BackgroundTaskBuilder).在通知中我使用了两个按钮,它应该执行两个不同的功能,但我无法获得通知的响应.
我在网上看到我应该为此开始另一个后台任务,但是我无法在后台任务中启动另一个后台任务.
所以我的问题是:如何让用户在通知中点击哪个按钮?
谢谢您的帮助.
toast win-universal-app background-task uwp windows-10-universal
我有一个基本的 django 项目,用作(Condor)计算集群的前端接口来生成模拟。用户可以从 django 应用程序开始模拟(在 Condor 中)。与仿真相关的元数据和仿真状态保存在数据库中。
我需要添加一个新功能:(某些)模拟完成时发出通知。
因为我想要一个简单的解决方案(并且我已经使用后台任务),所以我正在考虑使用重复任务,以固定的时间间隔查询 Condor 有关任务的信息,更新数据库,并在必要时发送通知。
因此,如果我想每 10 分钟更新一次状态,我将得到如下内容:
@background(schedule=1)
def check_simulations(repeat=600):
# lookup simulation statuses
simulation_list = get_Simulations()
for sim in simulations_list:
if sim.status == Simulation.DONE:
user.email_user('Simulation Complete', 'You have been notified')
def initialize():
check_simulations()
Run Code Online (Sandbox Code Playgroud)
然而,这个任务(或者更好地说是initialize()方法)必须启动(调用一次)来创建和调度check_simulations()任务(这实际上会序列化调用并将其保存在数据库中);之后后台任务线程将读取它并执行并重新安排它(如果有错误)
我的问题:
例如,一个这样的地方可能是 urls.py,但这是一个极其丑陋的解决方案。有没有更好的办法 ?
我正在使用警报管理器 (setInexactRepeating),但它会在 1 分钟的间隔后触发事件。我可以将这个间隔设置为 5 秒吗?
alarmIntent = new Intent(this, AlarmReceiver.class);
pendingIntent = PendingIntent.getBroadcast(c, 0, alarmIntent, PendingIntent.FLAG_UPDATE_CURRENT);
manager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
//Alarm Interval
int interval = 5000;
//Firing alarm after an interval of 5 seconds
manager.setInexactRepeating(AlarmManager.RTC_WAKEUP,System.currentTimeMillis(), interval, pendingIntent);
Run Code Online (Sandbox Code Playgroud) 我的应用程序中有飞行搜索功能,这需要很长时间才能获得数据(超过25秒).如果应用程序进入后台或进入睡眠模式,则互联网连接断开连接.
我已经使用苹果示例编写了下面的逻辑来使api请求继续进行,即使应用程序转到后台但它不起作用.
self.session = [self backgroundSession];
self.mutableData = [NSMutableData data];
NSURL *downloadURL = [NSURL URLWithString:@"http://jsonplaceholder.typicode.com/photos"];
NSURLRequest *request = [NSURLRequest requestWithURL:downloadURL];
self.dataTask = [self.session dataTaskWithRequest:request];
[self.dataTask resume];
- (NSURLSession *)backgroundSession
{
static NSURLSession *session = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration backgroundSessionConfigurationWithIdentifier:@"com.example.apple-samplecode.SimpleBackgroundTransfer.BackgroundSession"];
session = [NSURLSession sessionWithConfiguration:configuration delegate:self delegateQueue:nil];
});
return session;
}
Run Code Online (Sandbox Code Playgroud)
以下是委托方法
- (void)URLSession:(NSURLSession *)session dataTask:(NSURLSessionDataTask *)dataTask
didReceiveResponse:(NSURLResponse *)response
completionHandler:(void (^)(NSURLSessionResponseDisposition disposition))completionHandler {
NSLog(@"response: %@", response.debugDescription);
NSURLSessionResponseDisposition disposition = NSURLSessionResponseAllow;
if (completionHandler) {
completionHandler(disposition);
}
} …Run Code Online (Sandbox Code Playgroud) 我不能在MSDN文档中找到是否只能将一个触发器(使用SetTrigger()方法)设置为一个或多个后台任务。如果我想在计时器上以及通过编程方式触发任务,因此需要TimerTrigger和ApplicationTrigger怎么办?还可以使用AddCondition()设置多个条件吗?
有没有办法安排每天在特定时间调用 Web 服务的函数?
根据我的研究,我将不得不使用本地通知或NSTimer在特定时间安排或调用该功能。但是,无论我的应用程序是在计划时间处于后台(并且不运行任何后台任务)还是在前台,我都需要它来工作。
有两种情况: 1. 我的应用程序在后台运行位置服务 2. 没有位置或后台服务正在运行,或者应用程序处于挂起状态(如果用户禁用了位置更新)
但是我必须每天在预定时间向我的服务器发送一些状态。
旧版本的 iOS 似乎允许您的应用在后台运行 10 分钟。现在看来 iOS 只允许你的应用最多运行 3 分钟。我没有找到任何文档提及此更改何时或在哪个版本中进行了更改,也没有找到 Apple 提供的有关您的应用程序可以在后台运行多长时间的估计。
我需要能够在后台运行,因为我的应用程序通过 TCP 连接到外部设备。我已经知道您可以使用 VOIP 和播放无声音频进行黑客攻击(两者都会导致您的应用程序被拒绝)。
我可以做些什么来让我的应用程序在后台运行超过 3 分钟吗?
抓住我的头.
我的UWP应用程序中有一个后台任务,每15分钟(使用一次TimeTrigger)和互联网可用时(使用a SystemTrigger)注册.我知道这些事实是正确注册的,因为在使用visual studio进行调试时,它们都出现在"Lifecycle Events"中.不过,我的注册代码如下:
bool registered1 = false;
bool registered2 = false;
foreach (var task in BackgroundTaskRegistration.AllTasks)
{
if (task.Value.Name == "BackgroundGPS")
{
registered1 = true;
}
if (task.Value.Name == "InternetAvailGPS")
{
registered2 = true;
}
}
await BackgroundExecutionManager.RequestAccessAsync();
if (!registered1)
{
var builder1 = new BackgroundTaskBuilder();
builder1.Name = "BackgroundGPS";
builder1.TaskEntryPoint = "BackgroundTasks.BackgroundGPSTask";
var triggerTime = new TimeTrigger(15, false);
builder1.SetTrigger(triggerTime);
BackgroundTaskRegistration task1 = builder1.Register();
}
if (!registered2)
{
var builder2 = new BackgroundTaskBuilder();
builder2.Name = "InternetAvailGPS"; …Run Code Online (Sandbox Code Playgroud) c# win-universal-app background-task visual-studio-2015 windows-10-universal
我注册了一个后台任务,当我停用某个设置时,我会尝试再次注销它.但我只找到有关注册和调度任务的信息.有没有办法吗?
background-task ×11
c# ×3
ios ×3
uwp ×3
windows-10 ×2
.net ×1
alarmmanager ×1
android ×1
cocoa-touch ×1
django ×1
python ×1
toast ×1
watchos-3 ×1