|
1
|
// Copyright 2026 Onde Inference (Splitfire AB). All rights reserved. |
|
2
|
// Use of this source code is governed by the MIT license. |
|
3
|
// |
|
4
|
// OndeInferencePlugin.swift |
|
5
|
// |
|
6
|
// Native iOS plugin for onde_inference. |
|
7
|
// |
|
8
|
// Responsibilities: |
|
9
|
// 1. Provides a method channel ("com.ondeinference.onde_inference") so Dart |
|
10
|
// can resolve the App Group shared container path at runtime. |
|
11
|
// 2. Acts as the CocoaPods framework host — the Rust static library |
|
12
|
// (libonde_inference_dart.a) is force-loaded into this framework via |
|
13
|
// OTHER_LDFLAGS in the podspec. |
|
14
|
|
|
15
|
import Flutter |
|
16
|
import UIKit |
|
17
|
|
|
18
|
public class OndeInferencePlugin: NSObject, FlutterPlugin { |
|
19
|
|
|
20
|
/// The App Group identifier shared across all Onde-powered apps. |
|
21
|
/// Must match the value in Runner.entitlements. |
|
22
|
private static let appGroupId = "group.com.ondeinference.apps" |
|
23
|
|
|
24
|
public static func register(with registrar: FlutterPluginRegistrar) { |
|
25
|
let channel = FlutterMethodChannel( |
|
26
|
name: "com.ondeinference.onde_inference", |
|
27
|
binaryMessenger: registrar.messenger() |
|
28
|
) |
|
29
|
let instance = OndeInferencePlugin() |
|
30
|
registrar.addMethodCallDelegate(instance, channel: channel) |
|
31
|
} |
|
32
|
|
|
33
|
public func handle( |
|
34
|
_ call: FlutterMethodCall, |
|
35
|
result: @escaping FlutterResult |
|
36
|
) { |
|
37
|
switch call.method { |
|
38
|
case "getAppGroupContainerPath": |
|
39
|
if let url = FileManager.default.containerURL( |
|
40
|
forSecurityApplicationGroupIdentifier: Self.appGroupId |
|
41
|
) { |
|
42
|
result(url.path) |
|
43
|
} else { |
|
44
|
// App Group not configured or not entitled — fall back to nil |
|
45
|
// so the Dart side can use getApplicationSupportDirectory() instead. |
|
46
|
result(nil) |
|
47
|
} |
|
48
|
default: |
|
49
|
result(FlutterMethodNotImplemented) |
|
50
|
} |
|
51
|
} |
|
52
|
} |