Skip to content

Commit 36c7e2d

Browse files
committed
Call addApplicationDelegate using performSelector
1 parent e7d9831 commit 36c7e2d

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

ios/Classes/SwiftHomeWidgetPlugin.swift

+14-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@ public class SwiftHomeWidgetPlugin: NSObject, FlutterPlugin, FlutterStreamHandle
2020
private let notInitializedError = FlutterError(
2121
code: "-7", message: "AppGroupId not set. Call setAppGroupId first", details: nil)
2222

23+
private static func isRunningInAppExtension() -> Bool {
24+
let bundleURL = Bundle.main.bundleURL
25+
let bundlePathExtension = bundleURL.pathExtension
26+
return bundlePathExtension == "appex"
27+
}
28+
2329
public static func register(with registrar: FlutterPluginRegistrar) {
2430
let instance = SwiftHomeWidgetPlugin()
2531

@@ -30,7 +36,14 @@ public class SwiftHomeWidgetPlugin: NSObject, FlutterPlugin, FlutterStreamHandle
3036
name: "home_widget/updates", binaryMessenger: registrar.messenger())
3137
eventChannel.setStreamHandler(instance)
3238

33-
registrar.addApplicationDelegate(instance)
39+
guard isRunningInAppExtension() == false else {
40+
return
41+
}
42+
43+
let selector = NSSelectorFromString("addApplicationDelegate:")
44+
if registrar.responds(to: selector) {
45+
registrar.perform(selector, with: instance)
46+
}
3447
}
3548

3649
public func handle(_ call: FlutterMethodCall, result: @escaping FlutterResult) {

0 commit comments

Comments
 (0)