tjarvstrand / flutter_timezone

A fork of https://github.com/pinkfish/flutter_native_timezone
Apache License 2.0
42 stars 29 forks source link

MissingPluginException when run in ios #25

Closed March-mitsuki closed 6 months ago

March-mitsuki commented 6 months ago

Hello, thank you for maintaining this package. I encountered this error while using it on iOS, but everything is fine on macOS. I'm using this package together with flutter_local_notifications and timezone. All I did was install the package and use the code from the example. Do I need to set up anything extra?


platform: ios (iphone 14 simulator)

error: MissingPluginException (MissingPluginException(No implementation found for method getLocalTimezone on channel flutter_timezone))

my code:

String? osTimezoneName;

Future<void> configureLocalTimeZone() async {
  if (Platform.isWindows) {
    throw UnimplementedError('Windows not supported');
  }
  tz.initializeTimeZones();
  osTimezoneName = await FlutterTimezone.getLocalTimezone();
  tz.setLocalLocation(tz.getLocation(osTimezoneName!));
}

AppDelegate.swift

import UIKit
import Flutter
import flutter_local_notifications

@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate {
  override func application(
    _ application: UIApplication,
    didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
  ) -> Bool {
    if #available(iOS 10.0, *) {
      UNUserNotificationCenter.current().delegate = self as? UNUserNotificationCenterDelegate
    }

    FlutterLocalNotificationsPlugin.setPluginRegistrantCallback { (registry) in
      GeneratedPluginRegistrant.register(with: registry)
    }

    return super.application(application, didFinishLaunchingWithOptions: launchOptions)
  }
}
March-mitsuki commented 6 months ago

I found out that I simply forgot to add GeneratedPluginRegistrant.register(with: self) to AppDelegate.swift, my mistake.