patrick-fu / flutter_replay_kit_launcher

A flutter plugin of the launcher used to open RPSystemBroadcastPickerView for iOS
MIT License
13 stars 6 forks source link

Shared preference with app group #3

Closed ndthinh1810 closed 3 years ago

ndthinh1810 commented 3 years ago

Hello its me again, I have a question. So in my replaykit laucher project, the stream, the state and the configuration of it was all in the broadcast extension sample handler file, I can not access or modify it from flutter view. So can your 'Shared preference with app group' plugin do that. And if it can, how can I do that? Thank you Patrick. Here is the samplehandler.swift Screen Shot 2021-02-26 at 16 36 59

patrick-fu commented 3 years ago

For how to use shared_preference_app_group plugin, you can refer to this Flutter App project https://github.com/zegoim/zego-express-example-screen-capture-flutter, it demonstrates how to implement screen capture and live broadcast on Flutter (Android/iOS).

The shared_preference_app_group plugin related code is here:

iOS side: https://github.com/zegoim/zego-express-example-screen-capture-flutter/blob/552996e9e45fce6f771835fe9ccf40c1efb0ba99/ios/BroadcastExtensionFlutter/ZGScreenCaptureManager.m#L187

Dart side: https://github.com/zegoim/zego-express-example-screen-capture-flutter/blob/552996e9e45fce6f771835fe9ccf40c1efb0ba99/lib/manager/internal/screen_capture_manager_impl_ios.dart#L48

ndthinh1810 commented 3 years ago

I have read your code, but I want to handle stream state while streaming, store the stream state into appgroup user default and then get the stream state in the flutter side was not look like a call back. How do I know when the value of that key change in order to change the stream_state Text in the flutter side. It seem like this shared_preference_app_group did not support observing. Thank you!

patrick-fu commented 3 years ago

You can use the cross-process notification feature of iOS, which I used it in the finishReplayKitBroadcast method.

So you can post a notification in the broadcast extension process (the sample handler side) and listen in the main app process (the flutter side)

Further ref: https://stackoverflow.com/a/48558837/7027076

ndthinh1810 commented 3 years ago

And how do I add observe in the flutter side without CFNotificationCenterAddObserver

patrick-fu commented 3 years ago

Simply search for a CFNotificationCenter dart warpper plug-in on pub.dev, if not, write one yourself and distribute it to pub/github ^_^

ndthinh1810 commented 3 years ago

Thank you!