How can I make my flutter app run in background without stopping? - flutter

I want to make a Flutter application which runs in the background and never stops. I tried so many methods for instance background process, foreground process, Notification and so on but I couldn't find any workable solution.
Can anyone help me with this?

Try this package
https://pub.dev/packages/flutter_background
Request permission to run in background
bool hasPermissions = await FlutterBackground.hasPermissions;
Then to run it in background use
bool success = await FlutterBackground.enableBackgroundExecution();
Please note this works only in android

Related

Apple Watch: WKInterfaceDevice.current().play(.success) not working

I try to let the  Watch vibrate from within my code:
WKInterfaceDevice.current().play(.success)
but nothing happens. I also tried to ensure to be on the main thread:
DispatchQueue.main.async {
WKInterfaceDevice.current().play(.success)
}
still nothing. Am I missing something here? I expected it to be an easy task, but I fail completely...
Maybe your watch app is not in the active state? Citing the official documentation:
This method has no effect when called while your shared WKExtension object's applicationState property is either background or inactive. By default, you cannot play haptic feedback in the background. The only exception are apps with an active workout session.
So, unless you have a running HKWorkoutSession, if your app is in background you're not allowed to play haptic.
Alternatively, instead of HKWorkoutSession you could use WKExtendedRuntimeSession to support running the app in the background so sounds and haptics work. This needs to be done using either the Physical therapy or Smart alarm session type.

how to upload image in background in swift using GCD

i used the following code to upload image to server in background
var queue = dispatch_get_global_queue(QOS_CLASS_BACKGROUND, 0)
dispatch_async((queue), {
self.StartUploadProcess()//upload function
})
the above code run perfectly in simulator but when i test the application on my iPad it will stop the background execution when user click home button or open other application
please help me so i can run the application even the user click on home button?
The point of dispatch_sync() is to run the code in another thread synchronously. There is also dispatch_async() which runs asynchronously, that is, in the background.
From your question I assume you already know how to run it when you want to, just need to make it into an async call.

jailbroken iOS: how resume(in foreground) from background

I have problem. I need solve this problem for jailbreak iOS. My application works in background mode. I want that application go to foreground mode from background after some events.
I tried next instruction:
system([[NSString stringWithFormat:#"uiopen \"%#\"", #"appname://"] UTF8String])
But application didn't run from background. App run as new process.
Thank you.
User private API:
int SBSLaunchApplicationWithIdentifier(CFStringRef displayIdentifier, Boolean suspended);
It's defined in SpringboardServices private framework.
You will need to add entitlement "com.apple.springboard.launchapplications" for this to work.

How to Cancel AVExportSession when app goes to background state?

I am having an issue with AVExportSession on exporting large files. App will crash during the export when app is in background state or in locked state. How to fix this?.
Unfortunately you will need to call cancelExport on your exportSession before the app goes into background state or if you're sure it will not take too long, you can register a background task in order to finish the export, which will give your app around a minute to finish before being kicked.
At least for iOS10 or later, the AVExport Session will return a failure with AVError.operationInterrupted when you app resumes. My way of doing it is to just tear everything down and restart the export once that is detected.

iphone sdk: prevent alearts while running process in Background

I'm developing an app where I use performSelectorInBackground to do some sync task in the background. In my code I want to be able to detect whether I'm runing in a background process. This way I can prevent alert messages which might otherwise show up.
Thanks for your help!
Markus
By "background process", I assume you mean "background thread". To check if you're running on the main thread, try this:
// Some error handling code
if ([NSThread isMainThread]) {
// Provide some sort of UI feedback
}
else {
// Send a message to the main thread to provide feedback
}