Skip to content

Commit dcb3718

Browse files
committed
Sync flutter_libs - add iOS support
1 parent ba96ccf commit dcb3718

8 files changed

+105
-0
lines changed

sync_flutter_libs/ios/.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# NOTE: comment out before publishing - the binaries need to be uploaded
2+
Carthage
3+
*.zip
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#import <Flutter/Flutter.h>
2+
3+
@interface ObjectBoxFlutterPlugin : NSObject<FlutterPlugin>
4+
@end
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#import "ObjectBoxFlutterPlugin.h"
2+
#if __has_include(<objectbox_sync_flutter_libs/objectbox_sync_flutter_libs-Swift.h>)
3+
#import <objectbox_sync_flutter_libs/objectbox_sync_flutter_libs-Swift.h>
4+
#else
5+
// Support project import fallback if the generated compatibility header
6+
// is not copied when this plugin is created as a library.
7+
// https://forums.swift.org/t/swift-static-libraries-dont-copy-generated-objective-c-header/19816
8+
#import "objectbox_sync_flutter_libs-Swift.h"
9+
#endif
10+
11+
@implementation ObjectBoxFlutterPlugin
12+
+ (void)registerWithRegistrar:(NSObject<FlutterPluginRegistrar>*)registrar {
13+
[SwiftObjectBoxFlutterPlugin registerWithRegistrar:registrar];
14+
}
15+
@end
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import Flutter
2+
import UIKit
3+
4+
public class SwiftObjectBoxFlutterPlugin: NSObject, FlutterPlugin {
5+
public static func register(with registrar: FlutterPluginRegistrar) {
6+
let channel = FlutterMethodChannel(name: "objectbox_sync_flutter_libs", binaryMessenger: registrar.messenger())
7+
let instance = SwiftObjectBoxFlutterPlugin()
8+
registrar.addMethodCallDelegate(instance, channel: channel)
9+
}
10+
11+
public func handle(_ call: FlutterMethodCall, result: @escaping FlutterResult) {
12+
result("iOS " + UIDevice.current.systemVersion)
13+
}
14+
}

sync_flutter_libs/ios/README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
Contents of this folder is based on `flutter create --template=plugin`.
2+
It was reduced to the minimum that works for library inclusion by client apps.
3+
4+
Notably, the package depends on `ObjectBox.framework` from ObjectBox Swift distribution, downloading
5+
a released `ObjectBox-framework-X.Y.Z.zip` archive.
6+
7+
## Current limitations/TODOs
8+
There's currently an [issue](https://github.com/flutter/flutter/issues/45778) with Flutter tooling and/or its integration
9+
with Cocoapods. In short, an "http" source in the podspec doesn't work - the file has to be available locally.
10+
11+
To circumvent this, we're currently including the extracted `ObjectBox.framework` for iOS in the package when publishing
12+
to pub.dev. Therefore, you need to run ./ios/download-framework.sh before publishing the package.
13+
This has the benefit of a "no-setup" iOS support for the ObjectBox users - it works out of the box.
14+
Also notably, we're only including the bare minimum from the ObjectBox Swift release which means smaller final app size.
15+
16+
Note for contributors: you need to run the above-mentioned script as well to be able to test ObjectBox on iOS.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
# NOTE: run this script before publishing
5+
6+
# https://github.com/objectbox/objectbox-swift/releases/
7+
obxSwiftVersion="1.4.0"
8+
9+
dir=$(dirname "$0")
10+
11+
url="https://github.com/objectbox/objectbox-swift/releases/download/v${obxSwiftVersion}/ObjectBox-framework-${obxSwiftVersion}.zip"
12+
zip="${dir}/fw.zip"
13+
14+
curl --location --fail --output "${zip}" "${url}"
15+
16+
rm -rf "${dir}/Carthage"
17+
unzip "${zip}" -d "${dir}" \
18+
"Carthage/Build/iOS/ObjectBox.framework/Headers/*" \
19+
"Carthage/Build/iOS/ObjectBox.framework/ObjectBox" \
20+
"Carthage/Build/iOS/ObjectBox.framework/Info.plist"
21+
22+
rm "${zip}"
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Provides the compiled framework as released in objectbox-swift. No dart-related sources.
2+
# Run `pod lib lint objectbox_sync_flutter_libs.podspec' to validate before publishing.
3+
# This package is not distributed as a CocoaPod, rather it's automatically used by Flutter when creating
4+
# ios/{app}.podspec in client applications using objectbox-dart as a dependency.
5+
# Some of the lines from the original podspec are commented out but left for future reference, in case it stops working.
6+
Pod::Spec.new do |s|
7+
s.name = 'objectbox_sync_flutter_libs'
8+
s.version = '0.0.1' # not used anywhere - official flutter plugins use the same
9+
s.summary = 'ObjectBox is a super-fast NoSQL ACID compliant object database.'
10+
s.homepage = 'https://objectbox.io'
11+
s.license = 'Apache 2.0, ObjectBox Binary License'
12+
s.author = 'ObjectBox'
13+
s.platform = :ios, '8.0'
14+
15+
s.source = { :path => '.' }
16+
s.source_files = 'Classes/**/*'
17+
18+
s.dependency 'Flutter'
19+
20+
# Flutter.framework does not contain a i386 slice. Only x86_64 simulators are supported.
21+
s.pod_target_xcconfig = { 'DEFINES_MODULE' => 'YES', 'VALID_ARCHS[sdk=iphonesimulator*]' => 'x86_64' }
22+
s.swift_version = '5.0'
23+
24+
# Get the ObjectBoxC.framework from the objectbox-swift release (see README.md)
25+
s.ios.vendored_frameworks = 'Carthage/Build/iOS/ObjectBox.framework'
26+
27+
# Fail early during build instead of not finding the library during runtime
28+
s.xcconfig = { 'OTHER_LDFLAGS' => '-framework ObjectBox' }
29+
end

sync_flutter_libs/pubspec.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,5 @@ flutter:
1919
android:
2020
package: io.objectbox.flutter
2121
pluginClass: ObjectBoxFlutterPlugin
22+
ios:
23+
pluginClass: ObjectBoxFlutterPlugin

0 commit comments

Comments
 (0)