我在我的应用程序中使用核心位置框架,我在UIBackgroundMode或所需的后台模式(在Xcode 4.2中)设置位置字符串,以便didUpdateToLocation在应用程序在后台运行时从方法获取更新的位置,并通过点击将此更新的位置发送到服务器didUpdateToLocation核心位置框架内部特定链接.
我的问题是,应用程序会在一段时间后在后台运行时终止吗?
core-location uiapplicationdelegate ios ios5 background-task
我有一个 ASP.Net 应用程序,其中一个后台任务使用HostingEnvironment.QueueBackgroundWorkItem运行,如下面的代码所示。
问题:下面代码中调度的后台任务是使用来自 ASP.Net 线程池线程的线程,还是使用来自单独线程池的线程?
public ActionResult SendCustMails()
{
HostingEnvironment.QueueBackgroundWorkItem(ct => SendCustMailsTo(ct, "Customer Notification"));
return View();
}
private void SendCustMailsTo (CancellationToken ct, string msg)
{
//some code is omitted
foreach (var customer in Customers)
{
if (ct.IsCancellationRequested)
{
break;
}
SendMail(customer, msg);
}
return ct;
}
Run Code Online (Sandbox Code Playgroud) 我想向后台应用程序发送静默推送通知,然后获取当前用户位置并将其发送到 Web 服务。
我实现了推送通知方法以及这两个方法:
- (void)application:(UIApplication *)application performFetchWithCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler
{
NSDate *fetchStart = [NSDate date];
[self sendLocationToServerWithCompletionHandler:^(UIBackgroundFetchResult result) {
completionHandler(result);
NSDate *fetchEnd = [NSDate date];
NSTimeInterval timeElapsed = [fetchEnd timeIntervalSinceDate:fetchStart];
NSLog(@"Background Fetch Duration: %f seconds", timeElapsed);
}];
}
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler
{
}
Run Code Online (Sandbox Code Playgroud)
我还创建了一个将位置发送到服务器的方法:
- (void)sendLocationToServerWithCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler
{
NSDictionary *params = @{
@"UserId" : self.userId,
@"Latitude" : self.latitude,
@"Longitude" : self.longitude
}
ServerManager *manager = [ServerManager sharedManager];
[manager sendLocationToServerWithCompletion:^(BOOL success) {
if (success)
{
completionHandler(UIBackgroundFetchResultNewData);
} …Run Code Online (Sandbox Code Playgroud) objective-c push-notification ios background-task background-fetch
我想创建一个在应用程序启动时启动的后台任务。为此,我使用应用程序触发器。
MainPage.xaml.cs
var trigger = new ApplicationTrigger();
BackgroundManagement.RegisterBackgroundTask("InternetBackgroundTask.InternetBackground", "Internet", trigger, null);
await trigger.RequestAsync();
Run Code Online (Sandbox Code Playgroud)
后台管理.cs
public static BackgroundTaskRegistration RegisterBackgroundTask(string taskEntryPoint,string taskName,IBackgroundTrigger trigger,IBackgroundCondition condition)
{
//
// Check for existing registrations of this background task.
//
foreach (var cur in BackgroundTaskRegistration.AllTasks)
{
if (cur.Value.Name == taskName)
{
//
// The task is already registered.
//
return (BackgroundTaskRegistration)(cur.Value);
}
}
//
// Register the background task.
//
var builder = new BackgroundTaskBuilder();
builder.Name = taskName;
builder.TaskEntryPoint = taskEntryPoint;
builder.SetTrigger(trigger);
if (condition != null) …Run Code Online (Sandbox Code Playgroud) 美好的一天。考虑到Android的Socket IO库及其服务,我有一个非常具体的问题。
重要的是要提到我的设备是我正在测试的huawei p8 lite。
它在这里:
我有一个套接字Io库,该库正在我创建的服务中初始化
•我将侦听器设置为用于新消息的套接字io
•如果应用程序没有在用户进程中杀死,则一切工作都像字符。
•服务的目的是即使应用程序被杀死也保持套接字IO连接保持活动状态,以便向用户通知新消息。
•一旦应用程序被杀死,套接字IO连接即被断开
无论我尝试什么,我都会尝试所有可能的方法:隔离Service进程,为Service提供另一个进程,启动粘性,在服务销毁后立即重新创建它而不是粘性等等。
唯一有效的方法是startForeground()方法,但我不想使用它,因为它将遵循设计原则,而且我也不想显示有关正在运行的服务的任何通知。
我的问题是下一个:有人可以帮助我,告诉我即使应用程序被杀死了,我如何仍可以保持Socket IO连接的活动?
这是服务的代码。
package com.github.nkzawa.socketio.androidchat;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.os.IBinder;
import android.support.annotation.Nullable;
import android.support.v4.app.NotificationCompat;
import android.util.Log;
import android.widget.Toast;
import java.net.URISyntaxException;
import io.socket.client.IO;
import io.socket.client.Socket;
import io.socket.emitter.Emitter;
public class SocketService extends Service {
private Socket mSocket;
public static final String TAG = SocketService.class.getSimpleName();
@Override
public IBinder onBind(Intent intent) {
// TODO: Return the communication channel to the service.
throw …Run Code Online (Sandbox Code Playgroud) 假设我们有一个loop.js文件:
longLoop().then(res => console.log('loop result processing started'))
console.log('read file started')
require('fs').readFile(__filename, () => console.log('file processing started'))
setTimeout(() => console.log('timer fires'), 500)
async function longLoop () {
console.log('loop started')
let res = 0
for (let i = 0; i < 1e7; i++) {
res += Math.sin(i) // arbitrary computation heavy operation
if (i % 1e5 === 0) await null /* solution: await new Promise(resolve => setImmediate(resolve)) */
}
console.log('loop finished')
return res
}
Run Code Online (Sandbox Code Playgroud)
如果ran(node loop.js)输出:
loop started …Run Code Online (Sandbox Code Playgroud) 我正在尝试终止在 m sonarqube 中正在进行的后台任务。
此任务是对项目进行扫描。
将iPad更新到iOS 13后,我在应用程序内部使用后台任务,我的应用程序发出以下消息:
无法结束BackgroundTask:不存在标识符> 13(0xd)的后台任务,或者它可能已经结束。中断UIApplicationEndBackgroundTaskError()进行调试。
我使用UIApplicationEndBackgroundTaskError()进行了调试,但是没有得到任何结果,并且我已经在iOS 12和其他以前的版本上对其进行了测试,它运行良好。
在发布模式下,当我运行我的应用程序时,如果我让应用程序在后台运行大约 30 秒并将应用程序带到前台,我会收到错误日志:
2020-07-24 23:12:14.473633+0200 myTest[11229:3284265] Could not signal service com.apple.WebKit.WebContent: 113: Could not find specified service
2020-07-24 23:12:14.608936+0200 myTest[11229:3284265] Could not signal service com.apple.WebKit.Networking: 113: Could not find specified service
2020-07-24 23:13:06.713676+0200 myTest[11229:3284265] dnssd_clientstub read_all(15) DEFUNCT
2020-07-24 23:13:06.713798+0200 myTest[11229:3284265] [VERBOSE-2:FlutterObservatoryPublisher.mm(131)] Could not register as server for FlutterObservatoryPublisher. Check your network settings and relaunch the application.
2020-07-24 23:13:06.733470+0200 myTest[11229:3285031] [] nw_read_request_report [C1] Receive failed with error "Software caused connection abort"
2020-07-24 23:13:06.733962+0200 myTest[11229:3285031] [] nw_read_request_report [C5] Receive failed with error …Run Code Online (Sandbox Code Playgroud) 使用iOS16.1、Swift5.7.1、XCode 14.1、
我的 SwiftUI 应用程序将完成一些后台工作。
第一个问题:定期发生的后台工作只能在应用程序仍在运行时才能完成(即,如果应用程序没有完全关闭而是被其他应用程序覆盖),这是否正确?或者您可以使用完全封闭的应用程序定期执行后台工作吗?如果是,怎么办?
第二个问题:下面的代码有什么问题?
不幸的是,这段代码没有完成任何后台工作,为什么?(我尝试过使用和不使用调试器,而且我也在实际设备上尝试过)
(当然,我已经在info.plist中输入了必要的信息并添加了后台功能)
import SwiftUI
import BackgroundTasks
@main
struct MyApp: App {
@Environment(\.scenePhase) private var phase
@State private var counter = 0;
var body: some Scene {
WindowGroup {
ZStack {
Text("\(counter)")
}
}
.onChange(of: phase) { newPhase in
switch newPhase {
case .background:
scheduleDataRefetch()
default: break
}
}
.backgroundTask(.appRefresh("com.url.myidentifier")) {
await refetch()
scheduleDataRefetch()
}
}
private func refetch() async {
if await refetchData() {
print("refetch done...")
}
}
private func refetchData() async -> …Run Code Online (Sandbox Code Playgroud) background-task ×10
ios ×4
android ×1
asp.net ×1
asynchronous ×1
c# ×1
event-loop ×1
exception ×1
flutter ×1
ios12 ×1
ios13 ×1
ios5 ×1
javascript ×1
node.js ×1
objective-c ×1
service ×1
sockets ×1
sonarqube ×1
swift ×1
swiftui ×1
task ×1
threadpool ×1
uwp ×1