Skip to content

Prepare macos application group setting #265

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions objectbox/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,20 @@ dev_dependencies:

* Install the packages: `flutter pub get`
* XCode/iOS only: increase the deployment target to iOS 11 and, under Architectures, replace `${ARCHS_STANDARD}` with `arm64` (or `$ARCHS_STANDARD_64_BIT`). See [FAQ](#faq) for details.
* If targeting macOS (creating sandboxed macOS apps): you need to specify an application group.
Check all `macos/Runner/*.entitlements` files if they contain a `<dict>` section with correct group ID info.
Change the string value to the `DEVELOPMENT_TEAM` you can find in your Xcode settings, plus an application-specific suffix, for example:

```xml
<key>com.apple.security.application-groups</key>
<array>
<string>FGDTDLOBXDJ.demo</string>
</array>
```

Next, in your app code, pass the same string when opening the Store, for example: `Store(getObjectBoxModel(), directory: ..., macosApplicationGroup: 'FGDTDLOBXDJ.demo')`.
Note: Pick a short group identifier; there's an internal limit in macOS that requires the complete string to be
19 characters or fewer.
* Sync + Android only: in your `android/app/build.gradle` set `minSdkVersion 21` in section `android -> defaultConfig`.

### Dart Native
Expand Down
6 changes: 4 additions & 2 deletions objectbox/example/flutter/objectbox_demo/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,10 @@ class ViewModel {
late final Stream<Query<Note>> _queryStream;

ViewModel(Directory dir)
: _store =
Store(getObjectBoxModel(), directory: dir.path + '/objectbox') {
: _store = Store(getObjectBoxModel(),
directory: dir.path + '/objectbox',
macosApplicationGroup: 'objectbox.demo' // replace with a real name
) {
_box = Box<Note>(_store);
final qBuilder = _box.query()..order(Note_.date, flags: Order.descending);
_queryStream = qBuilder.watch(triggerImmediately: true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,9 @@
<true/>
<key>com.apple.security.network.server</key>
<true/>
<key>com.apple.security.application-groups</key>
<array>
<string>objectbox.demo</string>
</array>
</dict>
</plist>
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,9 @@
<dict>
<key>com.apple.security.app-sandbox</key>
<true/>
<key>com.apple.security.application-groups</key>
<array>
<string>objectbox.demo</string>
</array>
</dict>
</plist>
4 changes: 3 additions & 1 deletion objectbox/example/flutter/objectbox_demo_sync/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ class ViewModel {

ViewModel(Directory dir)
: _store = Store(getObjectBoxModel(),
directory: dir.path + '/objectbox-sync') {
directory: dir.path + '/objectbox',
macosApplicationGroup: 'objectbox.demo' // replace with a real name
) {
_box = Box<Note>(_store);
final qBuilder = _box.query()..order(Note_.date, flags: Order.descending);
_queryStream = qBuilder.watch(triggerImmediately: true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,9 @@
<true/>
<key>com.apple.security.network.server</key>
<true/>
<key>com.apple.security.application-groups</key>
<array>
<string>objectbox.demo</string>
</array>
</dict>
</plist>
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,9 @@
<dict>
<key>com.apple.security.app-sandbox</key>
<true/>
<key>com.apple.security.application-groups</key>
<array>
<string>objectbox.demo</string>
</array>
</dict>
</plist>
18 changes: 17 additions & 1 deletion objectbox/lib/src/native/store.dart
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,30 @@ class Store {
int? maxDBSizeInKB,
int? fileMode,
int? maxReaders,
bool queriesCaseSensitiveDefault = true})
bool queriesCaseSensitiveDefault = true,
String? macosApplicationGroup})
: _weak = false,
_queriesCaseSensitiveDefault = queriesCaseSensitiveDefault,
_dbDir = path.context.canonicalize(
(directory == null || directory.isEmpty)
? 'objectbox'
: directory) {
try {
if (Platform.isMacOS && macosApplicationGroup != null) {
if (!macosApplicationGroup.endsWith('/')) {
macosApplicationGroup += '/';
}
if (macosApplicationGroup.length > 20) {
ArgumentError.value(macosApplicationGroup, 'macosApplicationGroup',
'Must be at most 20 characters long');
}
final cStr = macosApplicationGroup.toNativeUtf8();
try {
C.posix_sem_prefix_set(cStr.cast());
} finally {
malloc.free(cStr);
}
}
if (_openStoreDirectories.contains(_dbDir)) {
throw UnsupportedError(
'Cannot create multiple Store instances for the same directory. '
Expand Down