New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat!: iOS major enhancements BGAppRefreshTask, BGProcessingTask, beginBackgroundTask, printScheduledTasks #511
Conversation
…eal device, added 30sec BGAppRefresh, Updated example fluttercommunity#396
added alert and MaterialApp to workmanager when no iOS permissions activated
fixed BGProcessing fixed inputdata in callback on task clarified timings
Fix workmanager not working on iOS
Update fork from master
Merge iOS BGTaskScheduler enhancements by PresenceApp
* Use logInfo instead of prints and NSLog * Log unnecessary logs only in debug mode * Remove unnecessary logs * Remove isInitalized flag in SwiftWorkmanagerPlugin which was not set to true anywhere
…egisterProcessingTask to be consistent with rest of the plugin and possible future Android implementation * iOS, Rename wrongly named startOnOffTask to startOneOffTask
…e size is reduced and it will make it easy to review * Change new task identifier to be consistent with existing ones e.g. instead of app.workmanager... use be.tramckrijte... * Documentation update * Remove unnecessary logs, comments etc which were added in PRs which were not merged, and cleanup unnecessary code * Revert using a custom log helper OS file to use the plugins existing shared prefs * Bump example flutter sdk to < 4 instead of < 3
…r can define task names instead of using hardcoded names
* Documentation update
…rmission is not assigned. Initialize should return result
* Temporarily commented old iOS background fetch
…sk-scheduler-enh-mer
…cheduled tasks. To be used during development/debugging. Format readme to improve readability
…ead of waiting for App to go to background. Since doing on backgrounding will keep on changing earliest begin date. * Add printScheduledTasks to example app * Format example code
@absar Impressive amount of work. Something initial - the permission check and APIs should be done with Will start reviewing asap, are you planing to add more changes soon? |
I created a feature request in
I am done with it for now. Have left one or two TODOs just for code cleanups which I will do once this PRs direction is finalized |
Just wanna say thank you @absar for finally building these features out. I'm just started planning features in my app that rely on this, and your timing could not be any better :). |
I pulled this in via my pubspec.yaml and am now successfully dispatching one off tasks on iOS. Huge thanks to the author. One note is that to get it to succeed on iOS I had to initialize with isInDebugMode true
If I did not set that flag when the task was dispatched iOS would throw some error about notifications and the app not being run in debug mode and/or on iOS 9 or lower. Small workaround and with that it all works great. |
Tried using real device on iPhone XR using iOS 17.0.3. I can confirm that this update/PR is working well with small piece of example code. Will try to implement in the real project later. |
This looks really promising, any plan on when this will be merged? Our app could really use these features |
Will look at it asap |
Impressive feat! Exactly what was missing for our IOS needs. Will use your branch until it is in the official package. Thanks a lot! |
Do you have any schedule to deploy this PR? Please let us know if you can. Many thanks. |
@absar awesome update |
Yes it's the correct behavior see [https://developer.apple.com/documentation/backgroundtasks/bgprocessingtask](Apple Doc) If the app is killed, the BGProcessing is killed too. |
Hi, another ping asking when this PR will be merged. Very curious to try it! |
Getting an error when trying to build:
On IOS 16.7.5 |
I got this working perfectly now! Needed to use a different ref
|
@absar |
@ened currently am quite occupied, will get back to it, let me know if you have any other reviews for the PR so that I address them in one shot. |
Hi, I was looking at refreshing tokens in the background using work manager. On IOS, is it possible to trigger one of task with same ids multiple times? If I have to permit the ids upfront, then I cant register one off task few mins before the token expiry to refresh it. Any suggestions on how to do this? Also, is it possible to register the one of task (in swift code) with name instead of id? |
Hi, I am trying to run periodic task on ios with below code and settings. Unfortunately, the task isnt getting triggered. Any help would be appreciated. Swift code: import UIKit @UIApplicationMain
} override func userNotificationCenter( extension UIWindow {
} version of the library used workmanager: Target platform an other details: platform :ios, '13.0' Code to trigger period task
|
Merging this, but will require a few iterations before packaging this into a release. |
@ened Can you share the ETA for the new release? |
Trying to run periodic task on ios results in this error [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: PlatformException(unhandledMethod("registerPeriodicTask") error, Unhandled method registerPeriodicTask, null, null) Works fine on Android though, just an isolated iOS issue |
@alfietapping make sure to use the mentioned branch https://github.com/absar/flutter_workmanager/tree/ios-bg-tasks-enh-final instead of using master branch |
Closes #295
Closes #450
Closes #497
Closes #306
Due to iOS side of this plugin falling behind Android it was necessary to do a major overhaul on iOS side. In summary the new changes are:
Workmanager.registerOneOffTask
which now uses iOSbeginBackgroundTask
instead of previousBGAppRefreshTask
solution, migration guide is created for this. The reason to not use BGAppRefreshTask is to make it in line with Android side design and tackle some items discussed in Improved iOS BGTaskScheduler request options and scheduling #295Workmanager.registerPeriodicTask
which uses iOSBGAppRefreshTask
Workmanager.registerProcessingTask
using iOSBGProcessingTask
, which was previously being done byregisterOneOffTask
. If or when Android side feature request Feature request - Support for long-running workers using WorkManager foreground service #236 is done that should be linked toWorkmanager.registerProcessingTask
to have same feature on both platformsWorkmanager.checkBackgroundRefreshPermission
to check Background App Refresh permission. On iOS user can disableBackground App Refresh
permission anytime, hence background tasks can only run if user has granted the permission.With
Workmanager.checkBackgroundRefreshPermission
you can check whether background app refresh is enabledWorkmanager.printScheduledTasks
to print details of scheduled tasks to console. To be used during development/debugging. This will to some extent give developers some confidence that tasks are really scheduled and iOS will trigger at some point in the futureMigration
BREAKING CHANGE: This PR has some breaking changes for iOS:
Workmanager.registerProcessingTask
:Workmanager().registerOneOffTask
withWorkmanager().registerProcessingTask
in your AppWorkmanagerPlugin.registerTask
withWorkmanagerPlugin.registerBGProcessingTask
inAppDelegate.swift
WorkmanagerPlugin.registerTask
call inAppDelegate.swift
hence remove the callI am not a native iOS developer but tried to address my own needs after not finding any solution and waiting for too long, it will help me if you guys test and raise any issues even if this PR doesn't get merged, i will try to maintain my branch https://github.com/absar/flutter_workmanager/tree/ios-bg-tasks-enh-final
Shoutout to Lars Huth/xunreal75 for his attempt in 2022, his work helped a lot during this PR