0

I am trying to use workmanager: ^0.2.0 plugin for the background process inside the flutter project. While running the application in iOS, it throws an error as below, But in Android plugin is working seamlessly

MissingPluginException(No implementation found for method initialize on channel be.tramckrijte.workmanager/foreground_channel_work_manager)
#0      MethodChannel.invokeMethod (package:flutter/src/services/platform_channel.dart:319:7)
<asynchronous suspension>
#1      Workmanager.initialize (package:workmanager/src/workmanager.dart:100:30)
#2      main (package:worksample/main.dart:29:15)

I manually registered the Workmanager plugin inside the AppDelegate.swift code, still it doesn’t autogenerating plugin registration code inside GeneratedPluginRegistrant.m class file.

Below are my code snippets,

import UIKit
import Flutter
import workmanager

@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate {
  override func application(
    _ application: UIApplication,
    didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
  ) -> Bool {
    GeneratedPluginRegistrant.register(with: self)
    UIApplication.shared.setMinimumBackgroundFetchInterval(TimeInterval(60*15))
    UNUserNotificationCenter.current().delegate = self
    
    WorkmanagerPlugin.setPluginRegistrantCallback { registry in
        AppDelegate.registerPlugins(with: registry)
    }
    return super.application(application, didFinishLaunchingWithOptions: launchOptions)
  }
    
    static func registerPlugins(with registry: FlutterPluginRegistry) {
               GeneratedPluginRegistrant.register(with: registry)
          }
       
    override func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
         completionHandler(.alert) 
     }
    
}


WorkManager plugin is missed in the below generated file

//
//  Generated file. Do not edit.
//

#import "GeneratedPluginRegistrant.h"

#if __has_include(<flutter_native_timezone/FlutterNativeTimezonePlugin.h>)
#import <flutter_native_timezone/FlutterNativeTimezonePlugin.h>
#else
@import flutter_native_timezone;
#endif

#if __has_include(<shared_preferences/FLTSharedPreferencesPlugin.h>)
#import <shared_preferences/FLTSharedPreferencesPlugin.h>
#else
@import shared_preferences;
#endif

@implementation GeneratedPluginRegistrant

+ (void)registerWithRegistry:(NSObject<FlutterPluginRegistry>*)registry {
  [FlutterNativeTimezonePlugin registerWithRegistrar:[registry registrarForPlugin:@"FlutterNativeTimezonePlugin"]];
  [FLTSharedPreferencesPlugin registerWithRegistrar:[registry registrarForPlugin:@"FLTSharedPreferencesPlugin"]];
}

@end

How can I resolve this issue?

2 Answers 2

1

The issue is resolved by adding the following changes in AppDelegate.swift class.

import UIKit
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*15))

    
    WorkmanagerPlugin.setPluginRegistrantCallback { registry in
        AppDelegate.registerPlugins(with: registry)
         FLTSharedPreferencesPlugin.register(with: registry.registrar(forPlugin: "io.flutter.plugins.sharedpreferences.SharedPreferencesPlugin"))
        
       
           
    }
    return super.application(application, didFinishLaunchingWithOptions: launchOptions)
  }
    
    static func registerPlugins(with registry: FlutterPluginRegistry) {
               GeneratedPluginRegistrant.register(with: registry)
          }
       
    override func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
         completionHandler(.alert) 
     }
    
}

Sign up to request clarification or add additional context in comments.

1 Comment

I get No such module 'shared_preferences'.
0

In my acse it works just running the following command on ios folder:

pod deintegrate

After that I ran:

pod install --repo-update

The error was gone!

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.