Closed gebsl closed 3 years ago
I have the same issue, I just read over the apple's https://developer.apple.com/documentation/backgroundtasks doc, I think the example missing the "Permitted background task scheduler identifiers" part,will test this tomorrow
As I understood, those identifiers are only needed for the API that was introduced in iOS 13 (Background Task API), which lets you specify tasks similar to Android's WorkManager. But for simple Background Fetch, those identifiers should not be needed. But as I'm not a native iOS developer, my understanding might be wrong.
Indeed, the identifier isnβt necessary because the plug-in uses the older background fetch API, not the iOS 13 task based API.
Iβll look into this next week.
@Kymer This iOS issue is not related to the example app only, I'm facing it in my app after implementation for the whole functionality, and when I tried with the example app I found it happening there also. Worth to mention that in Android it's working perfectly.
Same problem here.
Please just thumb up the initial bug report instead of posting "Same here". This only pollutes the conversation and makes tracing important questions/answers difficult. Thanks!
Finally i have found solution:
Make sure you have the followings in ios/Runner/GeneratedPluginRegistrant.m
@import workmanager;
and inside (void)registerWithRegistry:(NSObject
Keep in mind that ios/Runner/GeneratedPluginRegistrant.m file resets after every clean and build, so make sure that above is present before running app.
Also enable debug mode, when simulating background fetch from xcode.
[WorkmanagerPlugin registerWithRegistrar:[registry registrarForPlugin:@"WorkmanagerPlugin"]];
I can confirm this works in XCode. Thanks! However....If we run it from another IDE such as AS, GeneratedPluginRegistrant.m is automatically rebuilt, even without clean, so the workaround fails. I don't know enough to correct this at the plugin level.
[WorkmanagerPlugin registerWithRegistrar:[registry registrarForPlugin:@"WorkmanagerPlugin"]];
I can confirm this works in XCode. Thanks! However....If we run it from another IDE such as AS, GeneratedPluginRegistrant.m is automatically rebuilt, even without clean, so the workaround fails. I don't know enough to correct this at the plugin level.
You can do it from another IDE as well, after run wait for pod install to finish, then manually edit GeneratedPluginRegistrant.m before build has been finished.
Found better and permanent solution:
add following inside AppDelegate.swift
WorkmanagerPlugin.register(with: self.registrar(forPlugin: "be.tramckrijte.workmanager.WorkmanagerPlugin"))
this is how my ios/Runner/AppDelegate.swift looks like:
import Flutter
import workmanager
import devicelocale
import flutter_local_notifications
import shared_preferences
@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate {
override func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
GeneratedPluginRegistrant.register(with: self)
WorkmanagerPlugin.register(with: self.registrar(forPlugin: "be.tramckrijte.workmanager.WorkmanagerPlugin"))
UNUserNotificationCenter.current().delegate = self
UIApplication.shared.setMinimumBackgroundFetchInterval(TimeInterval(60*15))
WorkmanagerPlugin.setPluginRegistrantCallback { registry in
// registry in this case is the FlutterEngine that is created in Workmanager's performFetchWithCompletionHandler
// This will make other plugins available during a background fetch
//GeneratedPluginRegistrant.register(with: registry)
DevicelocalePlugin.register(with: registry.registrar(forPlugin: "com.example.devicelocale.DevicelocalePlugin"))
FlutterLocalNotificationsPlugin.register(with: registry.registrar(forPlugin: "com.dexterous.flutterlocalnotifications.FlutterLocalNotificationsPlugin"))
FLTSharedPreferencesPlugin.register(with: registry.registrar(forPlugin: "io.flutter.plugins.sharedpreferences.SharedPreferencesPlugin"))
}
return super.application(application, didFinishLaunchingWithOptions: launchOptions)
}
override func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
completionHandler([.alert, .sound, .badge]) // shows banner even if app is in foreground
}
}
Thanks @mamedshahmaliyev. Extending your results to AppDelegate.m (Obj-C), add:
#include "WorkmanagerPlugin.h"
and
[WorkmanagerPlugin registerWithRegistrar:[self registrarForPlugin:@"be.tramckrijte.workmanager.WorkmanagerPlugin"]];
AppDelegate.m ends up like this
#include "AppDelegate.h"
#include "GeneratedPluginRegistrant.h"
#include "WorkmanagerPlugin.h"
@implementation AppDelegate
void registerPlugins(NSObject<FlutterPluginRegistry>* registry) {
[GeneratedPluginRegistrant registerWithRegistry:registry];
}
- (BOOL)application:(UIApplication *)application
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
...
[GeneratedPluginRegistrant registerWithRegistry:self];
[WorkmanagerPlugin registerWithRegistrar:[self registrarForPlugin:@"be.tramckrijte.workmanager.WorkmanagerPlugin"]];
[WorkmanagerPlugin setPluginRegistrantCallback:registerPlugins];
...
return [super application:application didFinishLaunchingWithOptions:launchOptions];
}
@end
All seems to be good so far.
@mamedshahmaliyev's solution for swift works like a charm, thank you a lot!
Found better and permanent solution:
add following inside AppDelegate.swift
WorkmanagerPlugin.register(with: self.registrar(forPlugin: "be.tramckrijte.workmanager.WorkmanagerPlugin"))
this is how my ios/Runner/AppDelegate.swift looks like:
import Flutter import workmanager import devicelocale import flutter_local_notifications import shared_preferences @UIApplicationMain @objc class AppDelegate: FlutterAppDelegate { override func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { GeneratedPluginRegistrant.register(with: self) WorkmanagerPlugin.register(with: self.registrar(forPlugin: "be.tramckrijte.workmanager.WorkmanagerPlugin")) UNUserNotificationCenter.current().delegate = self UIApplication.shared.setMinimumBackgroundFetchInterval(TimeInterval(60*15)) WorkmanagerPlugin.setPluginRegistrantCallback { registry in // registry in this case is the FlutterEngine that is created in Workmanager's performFetchWithCompletionHandler // This will make other plugins available during a background fetch //GeneratedPluginRegistrant.register(with: registry) DevicelocalePlugin.register(with: registry.registrar(forPlugin: "com.example.devicelocale.DevicelocalePlugin")) FlutterLocalNotificationsPlugin.register(with: registry.registrar(forPlugin: "com.dexterous.flutterlocalnotifications.FlutterLocalNotificationsPlugin")) FLTSharedPreferencesPlugin.register(with: registry.registrar(forPlugin: "io.flutter.plugins.sharedpreferences.SharedPreferencesPlugin")) } return super.application(application, didFinishLaunchingWithOptions: launchOptions) } override func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) { completionHandler([.alert, .sound, .badge]) // shows banner even if app is in foreground } }
Based on your solution I get "No such module 'workmanager'. Do you know why? Thanks alot!
Same issue as @gareth-del.
I would like to add that even if platform :ios
is set to 10.0 or 11.0 (as I had first), the pod for workmanager will not install. It is not present under Local Podspecs
folder neither listed in Podfile.lock
.
I already try to delete Podfile.lock
and then pod install
, refreshing flutter packages using flutter pub cache repair
and did a cleaning with flutter clean
; nothing works. I'm running Flutter 1.20.1
@ivanjpg same issue here.Did you get the solution?
@mamedshahmaliyev please give me a solution for no such module
@suhail-zartek , unfortunately i have no such problem, the only thing that comes to my mind is, make sure that there is workmanager folder inside ios/.symlinks/plugins folder, i think import module_name should be the same as in ios/.symlinks/plugins folder. If there is no such ios/.symlinks/plugins/workmanager folder search for similar name otherwise it means pod install does not install the workmanager plugin...
I have the same problem with unavailable workmanager
import in AppDeletage.swift
@suhail-zartek , unfortunately i have no such problem, the only thing that comes to my mind is, make sure that there is workmanager folder inside ios/.symlinks/plugins folder, i think import module_name should be the same as in ios/.symlinks/plugins folder. If there is no such ios/.symlinks/plugins/workmanager folder search for similar name otherwise it means pod install does not install the workmanager plugin...
Try running pod install
from the ios folder in terminal if its not there.
Try running
pod install
from the ios folder in terminal if its not there.
It doesn't work. .symlink/plugins
dir doesn't contain workmanager
dir. I also clean build and repair package cache.
It doesn't work.
.symlink/plugins
dir doesn't containworkmanager
dir. I also clean build and repair package cache.
It's also not contained in Podfile.lock
.
same here, happens after upgraded Flutter from 1.17.5 to 1.20
same here, happens after upgraded Flutter from 1.17.5 to 1.20
Agree. I upgraded to 1.20.x and ended up with so many problems I went back to 1.17.x.
Small fix on my side was to force the register as non optional ! as the plugin expects. It appears on 1.20 this self.registrar returns optional ?
WorkmanagerPlugin.register(with: self.registrar(forPlugin: "be.tramckrijte.workmanager.WorkmanagerPlugin")!)
@2math
But this will not solve the problem of missing .symlink/plugins/workmanager
dir
for some reason after upgrading again to 1.20 I had the plugin. Need to mention that this time didn't call rm ios/Podfile Now when I run the project from android studio it hangs on sync with device for 5-6 min :) , when I run from XCode is OK, but not hot reload there. I'm right before releasing to production and can not afford v1.20+ :(
On Wed, Aug 19, 2020 at 5:18 PM Yaroslav Pronin notifications@github.com wrote:
@2math https://github.com/2math But this will not solve the problem of missing .symlink/plugins/workmanager dir
β You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/fluttercommunity/flutter_workmanager/issues/189#issuecomment-676433192, or unsubscribe https://github.com/notifications/unsubscribe-auth/AG5B7J2YQZHFHJSUA2VNPQDSBPNLBANCNFSM4O3BPGKA .
-- Regards, Galeen
@2math
I ran pod init && pod install
and added workmanager
already at 1.20, that is, without switching from the old version. Maybe this is the problem of Flutter itself
Is this a podfile related issue associated with flutter 1.20.x?. Creating a new podfile (flutter build iOS
) in 1.20.x results in no reference to symlinks in the podfile. Whilst running pod install
seems to set up all my other plugins in the symlinks folder it doesn't set up workmanager. When migrating to 1.20 you might receive an error that your podfile was outdated. Removing and rebuilding has the same effect as creating a new. Restoring to my old podfile even under 1.20.x placed workmanager back into symlinks and then runs fine.
I dont know enough to say how this should be resolved but it seems the new podfile format works fine for most of the plugins I am using just not workmanager so could this be resolved by a plugin fix? For reference I am still using mamedshahmaliyev's fix to make this work also.
@cormalenv: Can described confirm your behaviour. New Podfile breaks compatibility with Workmanager. Using Podfile from Flutter 1.17 resolves the issue. However, Flutter 1.20 also seems to break compatibility with @mamedshahmaliyev fix.
@gebsl Ill run some more tests tomorrow and get back to you. Reading your flutter 1.20 thread, it looks like we are now hitting the same issue. @mamedshahmaliyev's fix is a workaround for the original bug here which still exists so it shouldnt be closed but the thread seems to be migrating now to a 1.20 issue so we probably can move over to there.
If anyone needs old Podfile (before Flutter 1.20 version) you can look to example app's Podfile.
@gebsl the only modification I made to @mamedshahmaliyev 's fix was @2math 's addition to register as non-optional
WorkmanagerPlugin.register(with: self.registrar(forPlugin: "be.tramckrijte.workmanager.WorkmanagerPlugin")!)
Relevant sections of flutter doctor for reference in case.
[β] Flutter (Channel stable, 1.20.2, on Mac OS X 10.15.6 19G73, locale en-AU)
β’ Flutter version 1.20.2 at /.../development/flutter
β’ Framework revision bbfbf1770c (11 days ago), 2020-08-13 08:33:09 -0700
β’ Engine revision 9d5b21729f
β’ Dart version 2.9.1
[β] Xcode - develop for iOS and macOS (Xcode 11.6)
β’ Xcode at /Applications/Xcode.app/Contents/Developer
β’ Xcode 11.6, Build version 11E708
β’ CocoaPods version 1.9.3
I still think everything here might be workarounds given I am not seeing these same issue in other plugins. If I get time I will look further at PR options.
@cormalenv: Thanks for the hint! Build seems to work on my side.
Summing up:
WorkmanagerPlugin.register(with: self.registrar(forPlugin: "be.tramckrijte.workmanager.WorkmanagerPlugin")!)
(thanks to @2math and @mamedshahmaliyev)This seems to do the trick.
But totally agree with you, @cormalenv, this can only be temporary hacks for the plugin.
Unfortunately I'm too unexperienced in iOS development, so I won't be able to assist in finding the underlying problem in this plugin. Really appreciate your efforts!
If anyone needs old Podfile (before Flutter 1.20 version) you can look to example app's Podfile.
This issue is also with the connectivity
package. Looks like 1.20 made changes to the plugin system, now requires action from plugin developers.
When I add
WorkmanagerPlugin.register(with: self.registrar(forPlugin: "be.tramckrijte.workmanager.WorkmanagerPlugin")!)
to AppDelgate.swift i get this error
Xcode build done. 35,8s
Failed to build iOS app
Exited (sigterm)
Could not build the application for the simulator.
Error launching application on iPhone 11 Pro Max.
Anyone has the same issue?
@barrinhos123 You should look at the build log in Xcode, Flutter is not verbose.
@barrinhos123 You should look at the build log in Xcode, Flutter is not verbose.
Problem solved thank you!
For me, the code bellow appeared in GeneratedPluginRegistrant.m
by downgrading the "workmanager" to ^0.1.5
.
#if __has_include(<workmanager/WorkmanagerPlugin.h>)
#import <workmanager/WorkmanagerPlugin.h>
#else
@import workmanager;
#endif
More specifically I executed the next command after changing the dependencies inside pubspec.yaml
to workmanager: ^0.1.5
.
$ rm -rf ios/Podfile.lock
$ rm -rf ios/Pods
$ rm -rf pubspec.lock
$ flutter clean
$ flutter pub get
$ flutter build ios --release
=====
[My Environments]
$ flutter --version
Flutter 1.20.4 β’ channel stable β’ https://github.com/flutter/flutter.git
Framework β’ revision fba99f6cf9 (33 hours ago) β’ 2020-09-14 15:32:52 -0700
Engine β’ revision d1bc06f032
Tools β’ Dart 2.9.2
In addition, I will share my AppDelegate.swift
script too.
(Thanks to @mamedshahmaliyev.)
I add the !
after registrar
like this.
WorkmanagerPlugin.register(with: self.registrar(forPlugin: "be.tramckrijte.workmanager.WorkmanagerPlugin")!)
import Flutter
import workmanager
import shared_preferences
@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate {
override func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
GeneratedPluginRegistrant.register(with: self)
WorkmanagerPlugin.register(with: self.registrar(forPlugin: "be.tramckrijte.workmanager.WorkmanagerPlugin")!)
UNUserNotificationCenter.current().delegate = self
UIApplication.shared.setMinimumBackgroundFetchInterval(TimeInterval(60*10))
WorkmanagerPlugin.setPluginRegistrantCallback { registry in
FLTSharedPreferencesPlugin.register(with: registry.registrar(forPlugin: "io.flutter.plugins.sharedpreferences.SharedPreferencesPlugin")!)
}
return super.application(application, didFinishLaunchingWithOptions: launchOptions)
}
}
I've tried all suggestions above to no avail.
I tried this PR and it works for me. https://github.com/fluttercommunity/flutter_workmanager/pull/218
That PR does not work for me.. Same "no such module.... " error on xcode..
May I ask how you're using it @ngothanhtai ?
I've done the following
on pubspec.yaml:
workmanager:
git:
url: git@github.com:ened/flutter_workmanager.git
Then remove pods and pod install
and it still does not appear on Podfile.lock.
@MiguelSOliveira I specified the commit ref in the pubspec
workmanager:
git:
url: git@github.com:ened/flutter_workmanager.git
ref: 1c4e162ea4e71855856fb9e55a1545b3dae9a25d
I am getting a permission error when trying to get this PR:
`pub get failed (server unavailable) -- attempting retry 6 in 32 seconds...
Git error. Command: git clone --mirror git@github.com:ened/flutter_workmanager.git /Users/ux/work/flutter/.pub-cache/git/cache/flutter_workmanager-b145eb908d4135eaccf9e2d27cfe2100402b3876
stdout:
stderr: Cloning into bare repository '/Users/ux/work/flutter/.pub-cache/git/cache/flutter_workmanager-b145eb908d4135eaccf9e2d27cfe2100402b3876'...
git@github.com: Permission denied (publickey).
fatal: Could not read from remote repository.`
Hi @ujnamss:
You can avoid that error if you change the url
from git@github.com:ened/flutter_workmanager.git
to https://github.com/fluttercommunity/flutter_workmanager
.
I hope this helps.
Hi @ujnamss:
You can avoid that error if you change the
url
fromgit@github.com:ened/flutter_workmanager.git
tohttps://github.com/fluttercommunity/flutter_workmanager
.I hope this helps.
Doesn't seem to work @ivanjpg - i still get Exception Unhandled Exception: PlatformException(unhandledMethod("registerOneOffTask") error, Unhandled method registerOneOffTask, null, null)
Hi @ujnamss: You can avoid that error if you change the
url
fromgit@github.com:ened/flutter_workmanager.git
tohttps://github.com/fluttercommunity/flutter_workmanager
. I hope this helps.Doesn't seem to work @ivanjpg - i still get Exception Unhandled Exception: PlatformException(unhandledMethod("registerOneOffTask") error, Unhandled method registerOneOffTask, null, null)
0 StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:582:7)
1 MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:159:18)
2 MethodChannel.invokeMethod (package:flutter/src/services/platform_channel.dart:332:12)
3 Workmanager.registerOneOffTask (package:workmanager/src/workmanager.dart:124:32)
4 registerPoppinsRefreshTask (package:poppins/main.dart:49:15)
5 main (package:poppins/main.dart:66:3)
"One Off Tasks" and "Periodic Tasks" only works on Android. See https://github.com/fluttercommunity/flutter_workmanager/blob/master/IOS_SETUP.md
As @ngothanhtai said, this is the fix for now:
workmanager:
git:
url: git@github.com:ened/flutter_workmanager.git
ref: 1c4e162ea4e71855856fb9e55a1545b3dae9a25d
I was pushed to migrate into new iOS build system and confirm this is the only solution for now to have workmanager in the symlink
#currently ^0.2.3 not working with new build system
workmanager:
git:
url: https://github.com/fluttercommunity/flutter_workmanager
ref: 1c4e162ea4e71855856fb9e55a1545b3dae9a25d
Finally i have found solution:
Make sure you have the followings in ios/Runner/GeneratedPluginRegistrant.m
if __has_include(<workmanager/WorkmanagerPlugin.h>)
import <workmanager/WorkmanagerPlugin.h>
else
@import workmanager;
endif
and inside (void)registerWithRegistry:(NSObject*) function: [WorkmanagerPlugin registerWithRegistrar:[registry registrarForPlugin:@"WorkmanagerPlugin"]];
Keep in mind that ios/Runner/GeneratedPluginRegistrant.m file resets after every clean and build, so make sure that above is present before running app.
Also enable debug mode, when simulating background fetch from xcode.
GeneratedPluginRegistrant
Can you please share the GeneratedPluginRegistrant.m file.
Since the WorkManager is described in this way: "Flutter WorkManager is a wrapper around Android's WorkManager and iOS' performFetchWithCompletionHandler" and performFetchWithCompletionHandler is deprecated for apps supporting iOS 13 and higher (replaced by BGAppRefreshTask), am I correct that there is no way for implementing WorkManager on iOS 13 and higher, because it uses the wrong/outdated API?
Version
Describe the error
When running the example app on a real iOS device through XCode (by pressing the "Run" icon), the app throws an exception when pressing the "Start the Flutter background service" button. Subsequently, background fetch won't work and the dispatch method is never called.
The exception in XCode's console is:
Unfortunately I can not provide any debug information, when starting the app through
flutter run
, as there seems to be a bug with iOS hiding important exceptions from frameworks like flutter (see https://github.com/flutter/flutter/issues/41133), so the only way to fetch information (at least the one I know about) is through XCode.Except from running
flutter pub get
andflutter build ios
(to resolve initial build error in XCode) I didn't changed anything in the example app.Though, there is one thing I noticed that's different from the iOS setup guide: After unchecking and re-checking the capability "Background fetch" in XCode, following block is not added to file
project.pbxproj
(which, as I understood, should be added automatically by XCode):Unfortunately, adding it manually does not seem to have any effect.
Output of
flutter doctor -v