flutter_background_service
flutter_background_service copied to clipboard
iOS background service is not working. Error: Could not schedule app refresh: Error Domain=BGTaskSchedulerErrorDomain Code=3 "(null)"
I have followed everything on ReadMe and running the app on a physical device (iOS 16.0.2) but Im getting following error.
Could not schedule app refresh: Error Domain=BGTaskSchedulerErrorDomain Code=3 "(null)"
AppDelegate.swift
Info.plist
App permissions - iOS
The background service works well in android. Can someone tell me what am I doing wrong?
Thanks. 😊
You have to change “your.custom.task.identifier” that must be match with BGTaskSchedullerPermittedIdentifier in your Info.plist
On 30 Nov 2022, at 10.03, Coding with Day @.***> wrote:
I have followed everything on ReadMe and running the app on a physical device (iOS 16.0.2) but Im getting following error.
Could not schedule app refresh: Error Domain=BGTaskSchedulerErrorDomain Code=3 "(null)"
AppDelegate.swift https://user-images.githubusercontent.com/20990764/204696745-03cb20ac-9a61-480b-a601-1383aac09c05.png Info.plist https://user-images.githubusercontent.com/20990764/204696864-9ab219b0-aa03-4af9-b547-c6760f125f4a.png https://user-images.githubusercontent.com/20990764/204696891-af0bd3d6-3a67-4d51-b3f3-0e9c6a924b50.png App permissions - iOS https://user-images.githubusercontent.com/20990764/204697487-2b2c97de-df6b-47ec-ba2f-60ea45f741c1.png The background service works well in android. Can someone tell me what am I doing wrong?
Thanks. 😊
— Reply to this email directly, view it on GitHub https://github.com/ekasetiawans/flutter_background_service/issues/254, or unsubscribe https://github.com/notifications/unsubscribe-auth/AE54HAAVTRLVWDQQGQD2QQTWK27ZJANCNFSM6AAAAAASPEZ6MM. You are receiving this because you are subscribed to this thread.
@ekasetiawans I did that too and i'm getting this error and app terminates itself
AppDelegate.swift
Error
* thread #1, queue = 'com.apple.main-thread', stop reason = signal SIGKILL frame #0: 0x0000000211c5fb48 libsystem_kernel.dylib
mach_msg2_trap + 8
libsystem_kernel.dylibmach_msg2_trap: -> 0x211c5fb48 <+8>: ret libsystem_kernel.dylib
macx_swapon:
0x211c5fb4c <+0>: mov x16, #-0x30
0x211c5fb50 <+4>: svc #0x80
0x211c5fb54 <+8>: ret
Target 0: (Runner) stopped.
Lost connection to device.`
is it happened for the example project too?
@ekasetiawans I didnt try the example project.
EDIT I can confirm same happens in the example project too..
I am also having the similar issue. My background service is not working on iOS. I am using latest version library version. Please give the solution.
Same issue here, background service is never called. Pressing 'Simulate Background Fetch' results in message 'Background handler is disabled' and nothing else happens. Not sure what to do to fix this, or use a different plugin.
And I also get this: Could not schedule app refresh: Error Domain=BGTaskSchedulerErrorDomain Code=3 "(null)"
and this:
Foreground service is disabled
Yes, Same issue here, Still not working in IOS and onIosBackground()
is never called...
Rest can I start server from service as I am getting error and thinking to restart service after each 30 sec n onStart()
...???
[BackgroundTask] Background Task 1 ("Flutter debug task"), was created over 30 seconds ago. In applications running in the background, this creates a risk of termination. Remember to call UIApplication.endBackgroundTask(_:) for your task in a timely manner to avoid this.
any updates about this topic?, I'm having the same issue
if you finally found the solution, would you main to share it?
any updates about this topic?, I'm having the same issue
if you finally found the solution, would you main to share it?
@jrmanes What is your Main issue? iOS Background is not working completely or stop working after 30 sec?
any updates about this topic?, I'm having the same issue if you finally found the solution, would you main to share it?
@jrmanes What is your Main issue? iOS Background is not working completely or stop working after 30 sec?
it's weird, I could make it work in the simulator (deploying it with vscode and from the xcode, both work), but when I tried to deploy it via testflight in a device (iPhone), it does nothing... does it make sense to you?
Yes, it not working for iOS, need to write Swift code for location tracking
Sent from Outlook for Androidhttps://aka.ms/AAb9ysg
From: Jose Ramon Mañes @.> Sent: Tuesday, September 19, 2023 11:42:01 AM To: ekasetiawans/flutter_background_service @.> Cc: Anaya Joshi @.>; Comment @.> Subject: Re: [ekasetiawans/flutter_background_service] iOS background service is not working. Error: Could not schedule app refresh: Error Domain=BGTaskSchedulerErrorDomain Code=3 "(null)" (Issue #254)
any updates about this topic?, I'm having the same issue if you finally found the solution, would you main to share it?
@jrmaneshttps://github.com/jrmanes What is your Main issue? iOS Background is not working completely or stop working after 30 sec?
it's weird, I could make it work in the simulator (deploying it with vscode and from the xcode, both work), but when I tried to deploy it via testflight in a device (iPhone), it does nothing... does it make sense to you?
— Reply to this email directly, view it on GitHubhttps://github.com/ekasetiawans/flutter_background_service/issues/254#issuecomment-1724885843, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AZMYGYSMYDHDCLT55IDGLJLX3EZTDANCNFSM6AAAAAASPEZ6MM. You are receiving this because you commented.Message ID: @.***>
any updates about this topic?, I'm having the same issue if you finally found the solution, would you main to share it?
@jrmanes What is your Main issue? iOS Background is not working completely or stop working after 30 sec?
it's weird, I could make it work in the simulator (deploying it with vscode and from the xcode, both work), but when I tried to deploy it via testflight in a device (iPhone), it does nothing... does it make sense to you?
Are you using @pragma('vm:entry-point')
?
any updates about this topic?, I'm having the same issue if you finally found the solution, would you main to share it?
@jrmanes What is your Main issue? iOS Background is not working completely or stop working after 30 sec?
it's weird, I could make it work in the simulator (deploying it with vscode and from the xcode, both work), but when I tried to deploy it via testflight in a device (iPhone), it does nothing... does it make sense to you?
Are you using
@pragma('vm:entry-point')
?
thanks for the tip ;)
I was able to make it work adding @pragma('vm:entry-point')
, but only works in the foreground, as soon as I exit from the app (not terminating it), the process stops... this works in the simulators (in debug mode), but I cannot test it if I terminate the app on it.
my code looks like:
// I added also here, just in case
@pragma('vm:entry-point')
initializeApp() async {
final service = FlutterBackgroundService();
await service.configure(
androidConfiguration: AndroidConfiguration(
onStart: onStart,
autoStart: true,
isForegroundMode: true,
),
iosConfiguration: IosConfiguration(
autoStart: true,
onForeground: onStart,
onBackground: onIosBackground,
),
);
service.startService();
}
@pragma('vm:entry-point')
Future<bool> onIosBackground(ServiceInstance serviceInstance) async {
return true;
}
@pragma('vm:entry-point')
onStart(ServiceInstance service) async {
DartPluginRegistrant.ensureInitialized();
// if (service is AndroidServiceInstance) {
// service.on('setAsForeground').listen((event) {
// service.setAsForegroundService();
// });
// service.on('setAsBackground').listen((event) {
// service.setAsBackgroundService();
// });
// }
service.on('stopService').listen((event) {
service.stopSelf();
});
// I setted it to 5" to have a quick feedback
Timer.periodic(const Duration(seconds: 5), (timer) async {
// if (service is AndroidServiceInstance) {
// service.setForegroundNotificationInfo(
// title: "My App Service",
// content: "Updated at ${DateTime.now()}",
// );
// }
print('FLUTTER BACKGROUND SERVICE: ${DateTime.now()}');
await httpReq();
service.invoke(
'update',
{
"current_date": DateTime.now().toIso8601String(),
},
);
});
}
In the Info.plist
I have (among others):
<key>UIBackgroundModes</key>
<array>
<string>fetch</string>
<string>location</string>
<string>processing</string>
<string>remote-notification</string>
</array>
<key>BGTaskSchedulerPermittedIdentifiers</key>
<array>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
</array>
I don't have the custom task identifier, so I consider is not needed to add it to the ios/Runner/AppDelegate.swift
, or is it required?
SwiftFlutterBackgroundServicePlugin.taskIdentifier = "your.custom.task.identifier"
The capabilities in xcode looks like:
Thanks for the update. Good to hear that it is working for you. Well, you are talking about an iOS background service that is terminated after 30 sec by default by iOS itself so this plugin can't control it. Well, only this premium plugin can do the work even in the background continuously after the app closes. https://www.transistorsoft.com/shop/products/flutter-background-geolocation.
Yes, it not working for iOS, need to write Swift code for location tracking
From: Jose Ramon Mañes @.> Sent: Wednesday, September 20, 2023 9:33 PM To: ekasetiawans/flutter_background_service @.> Cc: Anaya Joshi @.>; Comment @.> Subject: Re: [ekasetiawans/flutter_background_service] iOS background service is not working. Error: Could not schedule app refresh: Error Domain=BGTaskSchedulerErrorDomain Code=3 "(null)" (Issue #254)
any updates about this topic?, I'm having the same issue if you finally found the solution, would you main to share it?
@jrmaneshttps://github.com/jrmanes What is your Main issue? iOS Background is not working completely or stop working after 30 sec?
it's weird, I could make it work in the simulator (deploying it with vscode and from the xcode, both work), but when I tried to deploy it via testflight in a device (iPhone), it does nothing... does it make sense to you?
Are you using @pragma('vm:entry-point') ?
thanks for the tip ;)
I was able to make it work adding @pragma('vm:entry-point'), but only works in the fordground, as soon as I exit from the app (not terminating it), the process stops... this works in the simulators (in debug mode), but I cannot test it if I terminate the app on it.
my code looks like:
// I added also here, just in case @pragma('vm:entry-point') initializeApp() async { final service = FlutterBackgroundService();
await service.configure( androidConfiguration: AndroidConfiguration( onStart: onStart, autoStart: true, isForegroundMode: true, ), iosConfiguration: IosConfiguration( autoStart: true, onForeground: onStart, onBackground: onIosBackground, ), ); service.startService(); }
@pragma('vm:entry-point')
Future
@pragma('vm:entry-point') onStart(ServiceInstance service) async { DartPluginRegistrant.ensureInitialized(); // if (service is AndroidServiceInstance) { // service.on('setAsForeground').listen((event) { // service.setAsForegroundService(); // });
// service.on('setAsBackground').listen((event) { // service.setAsBackgroundService(); // }); // }
service.on('stopService').listen((event) { service.stopSelf(); });
// I setted it to 5" to have a quick feedback Timer.periodic(const Duration(seconds: 5), (timer) async { // if (service is AndroidServiceInstance) { // service.setForegroundNotificationInfo( // title: "My App Service", // content: "Updated at ${DateTime.now()}", // ); // }
print('FLUTTER BACKGROUND SERVICE: ${DateTime.now()}');
await httpReq();
service.invoke(
'update',
{
"current_date": DateTime.now().toIso8601String(),
},
);
}); }
In the Info.plist I have (among others):
<key>UIBackgroundModes</key>
<array>
<string>fetch</string>
<string>location</string>
<string>processing</string>
<string>remote-notification</string>
</array>
<key>BGTaskSchedulerPermittedIdentifiers</key>
<array>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
</array>
I don't have the custom task identifier, so I consider is not needed to add it to the ios/Runner/AppDelegate.swift, or is it required?
SwiftFlutterBackgroundServicePlugin.taskIdentifier = "your.custom.task.identifier"
— Reply to this email directly, view it on GitHubhttps://github.com/ekasetiawans/flutter_background_service/issues/254#issuecomment-1728024354, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AZMYGYVUAJE3E5UFPDTAD73X3MHUVANCNFSM6AAAAAASPEZ6MM. You are receiving this because you commented.Message ID: @.***>
hey @EXEIdeas @anaya12345
so, that means that this plugin is not working at all?
my use case is, I need to schedule a task every 1-5h (I don't need to do it in real time), to do so, theo only way is, either I go with the plugin that you mentioned from transistorsoft.com or with swift code?, is not a way to do so with this plugin?
if swift
is the only way, do you have any recommendation/example to follow @anaya12345 ?
hey @EXEIdeas @anaya12345
so, that means that this plugin is not working at all?
my use case is, I need to schedule a task every 1-5h (I don't need to do it in real time), to do so, theo only way is, either I go with the plugin that you mentioned from transistorsoft.com or with swift code?, is not a way to do so with this plugin?
You can use this as by default this will work each after about 15 min for 30 sec only...
hey @EXEIdeas @anaya12345 so, that means that this plugin is not working at all? my use case is, I need to schedule a task every 1-5h (I don't need to do it in real time), to do so, theo only way is, either I go with the plugin that you mentioned from transistorsoft.com or with swift code?, is not a way to do so with this plugin?
You can use this as by default this will work each after about 15 min for 30 sec only...
okay, so technically it should work for iOS in release mode too, max every 15' and for 30", but it should work, have you been able to make it work for iOS?, just to confirm it
This plugin work for Android well. Also works for iOS of user have launched app and device is in unlock state and not in sleep mode.
To work bg service when device is sleep also, I used the swift code to fetch continuous location updates, there is requirement of location tracking in my application.
Sent from Outlook for Androidhttps://aka.ms/AAb9ysg
From: Jose Ramon Mañes @.> Sent: Thursday, September 21, 2023 6:30:41 PM To: ekasetiawans/flutter_background_service @.> Cc: Anaya Joshi @.>; Mention @.> Subject: Re: [ekasetiawans/flutter_background_service] iOS background service is not working. Error: Could not schedule app refresh: Error Domain=BGTaskSchedulerErrorDomain Code=3 "(null)" (Issue #254)
if swift is the only way, do you have any recommendation/example to follow @anaya12345https://github.com/anaya12345 ?
— Reply to this email directly, view it on GitHubhttps://github.com/ekasetiawans/flutter_background_service/issues/254#issuecomment-1729519237, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AZMYGYQM4MJPG7LPZJJ7QSTX3Q27TANCNFSM6AAAAAASPEZ6MM. You are receiving this because you were mentioned.Message ID: @.***>
Yes, To get Continuous Location in BG of iOS, you need to use Swift code and in this process, you can make your application live and active and can do manythings extra too...
[like] Anaya Joshi reacted to your message:
From: Muhammad Hassan @.> Sent: Thursday, September 28, 2023 6:44:41 PM To: ekasetiawans/flutter_background_service @.> Cc: Anaya Joshi @.>; Mention @.> Subject: Re: [ekasetiawans/flutter_background_service] iOS background service is not working. Error: Could not schedule app refresh: Error Domain=BGTaskSchedulerErrorDomain Code=3 "(null)" (Issue #254)
Yes, To get Continuous Location in BG of iOS, you need to use Swift code and in this process, you can make your application live and active and can do manythings extra too...
— Reply to this email directly, view it on GitHubhttps://github.com/ekasetiawans/flutter_background_service/issues/254#issuecomment-1739836331, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AZMYGYQSH7DFVAI24QQAPGLX4XARTANCNFSM6AAAAAASPEZ6MM. You are receiving this because you were mentioned.Message ID: @.***>