Skip to content
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

Add support for calling into other plugins from a background context on iOS #7843

Merged
merged 1 commit into from
Feb 15, 2019

Conversation

bkonyi
Copy link
Contributor

@bkonyi bkonyi commented Feb 15, 2019

Added FlutterPluginRegistrantCallback typedef and optional setPluginRegistrantCallback static method in FlutterPlugin. setPluginRegistrantCallback is used to set a callback defined in AppDelegate.m which registers some subset of plugins with a FlutterPluginRegistry (for example, a headless FlutterEngine). This allows for plugins which utilize background execution functionality to enable the use of other plugins on the background isolate. This puts iOS on par with Android for background execution.

Along with updated examples and Medium posts, this fixes flutter/flutter#21925.

@dnfield
Copy link
Contributor

dnfield commented Feb 15, 2019

Won't this still involve potentially creating multiple instances of a plugin?

E.g. this seems like it would fail if I wanted to use sqflite (the single most popular storage related plugin after shared preferences) on both the foreground and background isolate.

@bkonyi
Copy link
Contributor Author

bkonyi commented Feb 15, 2019

Won't this still involve potentially creating multiple instances of a plugin?

E.g. this seems like it would fail if I wanted to use sqflite (the single most popular storage related plugin after shared preferences) on both the foreground and background isolate.

Yes and no. Basically, it really depends on what's included in the callback. In most cases, applications can just do something like this with no problems:

void registrationCallback(NSObject<FlutterPluginRegistry>* registry) {
  [GeneratedPluginRegistrant registerWith: registry];
}

However, in the case of a plugin like sqlite, the implementation can pick and choose which plugins to register:

void registrationCallback(NSObject<FlutterPluginRegistry>* registry) {
  [GeofencingPlugin registerWith: registry];
  [FlutterLocalNotificationsPlugin registerWith:registry];
  // etc
}

The above is basically the content of GeneratedPluginRegistrant's registerWith, minus the [SqlitePlugin registerWith:registry].

This change isn't meant to solve all of the problems with background execution, but will bring iOS up to par with Android for now.

@dnfield
Copy link
Contributor

dnfield commented Feb 15, 2019

Thanks for the explanation!

You need to rebase against master to get this to build properly on CI.

iOS

Added `FlutterPluginRegistrantCallback` typedef and optional
`setPluginRegistrantCallback` static method in `FlutterPlugin`.
`setPluginRegistrantCallback` is used to set a callback defined in
AppDelegate.m which registers some subset of plugins with a
`FlutterPluginRegistry` (for example, a headless FlutterEngine). This
allows for plugins which utilize background execution functionality to
enable the use of other plugins on the background isolate. This puts
iOS on par with Android for background execution.
@bkonyi bkonyi force-pushed the ios_background_execution_plugins branch from ca6ee18 to f8f7cb1 Compare February 15, 2019 19:01
@bkonyi
Copy link
Contributor Author

bkonyi commented Feb 15, 2019

Thanks for the explanation!

You need to rebase against master to get this to build properly on CI.

No problem! Thanks for the heads up about the CI. I did this work on a recent revision, but I guess something was broken there.

Copy link
Contributor

@dnfield dnfield left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, with the caveat that we know this approach has some potential issues that we're still working towards fixing.

@bkonyi bkonyi merged commit 1ba3295 into master Feb 15, 2019
@bkonyi bkonyi deleted the ios_background_execution_plugins branch February 15, 2019 19:19
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Feb 16, 2019
engine-flutter-autoroll added a commit to flutter/flutter that referenced this pull request Feb 16, 2019
flutter/engine@033f207...163a2fd

git log 033f207..163a2fd --no-merges --oneline
163a2fd Revert &#34;Android embedding refactor pr3 add remaining systemchannels (#7738)&#34; (flutter/engine#7849)
0d6ff16 Shut down and restart the Dart VM as needed. (flutter/engine#7832)
256db4b Android embedding refactor pr3 add remaining systemchannels (flutter/engine#7738)
02d7ca3 Don&#39;t call static method from instance variable (flutter/engine#7841)
10cee61 Delete GL textures when they are released from the texture registry. (flutter/engine#7836)
69e4606 Fix NullPointerException in SurfaceTextureRegistryEntry (flutter/engine#7837)
9a965bc Fix NullPointerException in ResourceCleaner (flutter/engine#7838)
2acd794 Add fml::FileExists implementation for Windows (flutter/engine#7845)
fa38a98 Update buildroot to 7f64ff4928e to unblock Mac builds. (flutter/engine#7846)
1ba3295 Add support for calling into other plugins from a background context on iOS (flutter/engine#7843)
df2fc97 Roll src/third_party/skia 154acd7a1374..be9aff25bddc (13 commits) (flutter/engine#7842)
0ca1d1f Remove the Dart JIT snapshot data from AOT builds of the embedder library (flutter/engine#7806)
c51ea41 Roll src/third_party/skia 7a74c7cb6da0..154acd7a1374 (1 commits) (flutter/engine#7840)
ecbaea1 Ensure to pass dill file after VM options for gen_snapshot (flutter/engine#7839)
5d3f714 Roll src/third_party/skia b00f7b34751b..7a74c7cb6da0 (1 commits) (flutter/engine#7835)
7337399 Roll src/third_party/skia 9a88bee122f1..b00f7b34751b (24 commits) (flutter/engine#7831)
6f318ef Move up ndk version that is being downloaded(old one no longer available) (flutter/engine#7830)
a8aa1ee Track flow id (flutter/engine#7826)
b1ce6b7 Roll src/third_party/skia a0dcd29f536b..9a88bee122f1 (4 commits) (flutter/engine#7825)
dbc1663 Roll src/third_party/skia 6152470dc69e..a0dcd29f536b (2 commits) (flutter/engine#7824)
9426776 Roll src/third_party/skia 4037f7f5d8b4..6152470dc69e (1 commits) (flutter/engine#7823)
e2394ad Add flow events connecting pointer events to frames (flutter/engine#7807)
0a5a7c5 Roll src/third_party/skia 09c01e9df260..4037f7f5d8b4 (3 commits) (flutter/engine#7821)
b867f48 Roll src/third_party/skia 186669c4128b..09c01e9df260 (5 commits) (flutter/engine#7820)
af39e22 Fix tests that were committed after cirrus ran (flutter/engine#7819)
1f2cbf7 Roll src/third_party/dart 0a7dcf17eb..c92d5ca288 (64 commits)

The AutoRoll server is located here: https://autoroll.skia.org/r/flutter-engine-flutter-autoroll

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+/master/autoroll/README.md

If the roll is causing failures, please contact the current sheriff (liyuqian@google.com), and stop
the roller if necessary.
@3than7
Copy link

3than7 commented Jul 24, 2020

Hi everyone

Can anyone please give us an example of how to use the plugin in another isolate or background.

How we can register plugin to use in the background.

Thank you so much.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Plugins do not work for iOS background execution
4 participants