flutter_background_service icon indicating copy to clipboard operation
flutter_background_service copied to clipboard

How To Stop Background Service In iOS Only?

Open EXEIdeas opened this issue 1 year ago • 10 comments

Hi; I am using this plugin for my Foreground/Background Service in Android and iOS but due to the limitation of this plugin in iOS Background service to be terminated after 30 sec, I am working on an alternative to keep the service active forever in iOS Background so I need to stop this plugin iOS Background Service only so that I can work in Native iOS for this task. So for this, I did the following confrigration but it is giving me the error as Could not schedule app refresh: Error Domain=BGTaskSchedulerErrorDomain Code=3 "(null)"

 await service.configure(
    androidConfiguration: AndroidConfiguration(
      // This will be executed when app is in foreground or background in separated isolate
      onStart: onStart,
      // Auto start service
      autoStart: true,
      isForegroundMode: true,
    ),
    iosConfiguration: IosConfiguration(
      // auto start service
      autoStart: true,
      // this will be executed when app is in foreground in separated isolate
      onForeground: onStart,
      // you have to enable background fetch capability on xcode project
      // onBackground: onIosBackground,          //COMMENTED THIS LINE TO STOP RUNNING IN IOS BACKGROUND
    ),
  );

So whats the correct way to stop background service in iOS only?

EXEIdeas avatar May 29 '23 09:05 EXEIdeas

in Android i have use this code to stop service also works in IOS

service.on('stopService').listen((event) { 
    try {
      //your function if service is going to stop
      service.stopSelf();
    } catch (ex) {
      log(ex.toString());
    }
  });

but i am facing issue is how to keep running this service after user clear the app from task manager in IOS

jaypathak9460 avatar Aug 17 '23 12:08 jaypathak9460

I don't know how to run the service in background or in foreground in IOS. Please tell me about it.

Sneh-Paghdal avatar Aug 18 '23 05:08 Sneh-Paghdal

in Android i have use this code to stop service also works in IOS

service.on('stopService').listen((event) { 
    try {
      //your function if service is going to stop
      service.stopSelf();
    } catch (ex) {
      log(ex.toString());
    }
  });

but i am facing issue is how to keep running this service after user clear the app from task manager in IOS

HI @jaypathak9460 I am also looking for the same. If you got anything, it will be very help full to share here or if I got something then I will share it here.

EXEIdeas avatar Aug 31 '23 06:08 EXEIdeas

I don't know how to run the service in background or in foreground in IOS. Please tell me about it.

Hi @Sneh-Paghdal Just run your code in main()for foreground service and currently it is not possible to keep continuous background service in iOS.

EXEIdeas avatar Aug 31 '23 06:08 EXEIdeas

It's also not working in foreground in ios. can you tell me more about it? It would be a big help to me.

On Thu, 31 Aug 2023 at 11:51, Muhammad Hassan @.***> wrote:

I don't know how to run the service in background or in foreground in IOS. Please tell me about it.

Hi @Sneh-Paghdal https://github.com/Sneh-Paghdal Just run your code in main()for foreground service and currently it is not possible to keep continuous background service in iOS.

— Reply to this email directly, view it on GitHub https://github.com/ekasetiawans/flutter_background_service/issues/310#issuecomment-1700431569, or unsubscribe https://github.com/notifications/unsubscribe-auth/A5JOB2B2QCHXP5XFOFEMIRLXYAUM5ANCNFSM6AAAAAAYSSTAZ4 . You are receiving this because you were mentioned.Message ID: @.***>

Sneh-Paghdal avatar Sep 01 '23 06:09 Sneh-Paghdal

It's also not working in foreground in ios. can you tell me more about it? It would be a big help to me. On Thu, 31 Aug 2023 at 11:51, Muhammad Hassan @.> wrote: I don't know how to run the service in background or in foreground in IOS. Please tell me about it. Hi @Sneh-Paghdal https://github.com/Sneh-Paghdal Just run your code in main()for foreground service and currently it is not possible to keep continuous background service in iOS. — Reply to this email directly, view it on GitHub <#310 (comment)>, or unsubscribe https://github.com/notifications/unsubscribe-auth/A5JOB2B2QCHXP5XFOFEMIRLXYAUM5ANCNFSM6AAAAAAYSSTAZ4 . You are receiving this because you were mentioned.Message ID: @.>

Sure but this ticket is something different so stick to this here rest ask question directly about anything else.

EXEIdeas avatar Sep 01 '23 06:09 EXEIdeas

i was thinking to create whole thing in swift but the issue is i do not have any idea about swift code and how to create it.so i dropped the plan😅😅

jaypathak9460 avatar Sep 01 '23 11:09 jaypathak9460

It's also not working in foreground in ios. can you tell me more about it? It would be a big help to me. On Thu, 31 Aug 2023 at 11:51, Muhammad Hassan @.> wrote: I don't know how to run the service in background or in foreground in IOS. Please tell me about it. Hi @Sneh-Paghdal https://github.com/Sneh-Paghdal Just run your code in main()for foreground service and currently it is not possible to keep continuous background service in iOS. — Reply to this email directly, view it on GitHub <#310 (comment)>, or unsubscribe https://github.com/notifications/unsubscribe-auth/A5JOB2B2QCHXP5XFOFEMIRLXYAUM5ANCNFSM6AAAAAAYSSTAZ4 . You are receiving this because you were mentioned.Message ID: @.>

You can follow YT Videos for the same and set some permission for IOS and its done but still it will be killed by IOS in background as soon as app was removed from task manager(Recent),

jaypathak9460 avatar Sep 01 '23 11:09 jaypathak9460

@jaypathak9460 Well I am good with keeping the Background Running in the iOS continuously using this plugin and some swift touches thats why I want to stop this plugin iOS background service to stop interruption. ;-*

EXEIdeas avatar Sep 01 '23 12:09 EXEIdeas

@jaypathak9460 Well I am good with keeping the Background Running in the iOS continuously using this plugin and some swift touches thats why I want to stop this plugin iOS background service to stop interruption. ;-*

hi, can you share some of your swift code for running these iOS on background? cause i am facing this issue for quite a moment, thanks.

kenthken avatar May 24 '24 09:05 kenthken