Rexios80 / watch_connectivity

Wrapper for WatchConnectivity on iOS and Wearable APIs on Android
https://pub.dev/packages/watch_connectivity
BSD 3-Clause "New" or "Revised" License
28 stars 17 forks source link

[iOS] Background messages? #6

Closed rodydavis closed 1 year ago

rodydavis commented 1 year ago

Currently have it working great, but requires the app to be in the foreground to work.

Do i need to use a background plugin to run the logic for the apple watch to communicate?

Rexios80 commented 1 year ago

The app shouldn't need to be in the foreground to work

Rexios80 commented 1 year ago

Unless the phone app is dead then yeah that doesn't work right now

rodydavis commented 1 year ago

Well the watch app opens, but maybe I need to move the logic to main instead of initState on my home widget

On Wed, Feb 22, 2023 at 10:08 AM Rexios @.***> wrote:

The app shouldn't need to be in the foreground to work

— Reply to this email directly, view it on GitHub https://github.com/Rexios80/watch_connectivity/issues/6#issuecomment-1440530068, or unsubscribe https://github.com/notifications/unsubscribe-auth/AHOOFX5GTVG5YHNJDZMLWYDWYZI2HANCNFSM6AAAAAAVEUXMLA . You are receiving this because you authored the thread.Message ID: @.***>

-- Rody Davis Jr

Rexios80 commented 1 year ago

I'm going to need more details on exactly what you're trying to do

rodydavis commented 1 year ago

What would be the recommendation here? I added a sync screen in my app to send the state manually

On Wed, Feb 22, 2023 at 10:10 AM Rody Davis @.***> wrote:

Well the watch app opens, but maybe I need to move the logic to main instead of initState on my home widget

On Wed, Feb 22, 2023 at 10:08 AM Rexios @.***> wrote:

The app shouldn't need to be in the foreground to work

— Reply to this email directly, view it on GitHub https://github.com/Rexios80/watch_connectivity/issues/6#issuecomment-1440530068, or unsubscribe https://github.com/notifications/unsubscribe-auth/AHOOFX5GTVG5YHNJDZMLWYDWYZI2HANCNFSM6AAAAAAVEUXMLA . You are receiving this because you authored the thread.Message ID: @.***>

-- Rody Davis Jr

-- Rody Davis Jr

Rexios80 commented 1 year ago

If you need to send data to a dead companion app, then you should probably be using context and not messaging

rodydavis commented 1 year ago

So there is a SQLite database my iOS app controls and a subset small list I send to the watch.

There is a menu that a user can choose a list item on the watch and the iOS app will return a new state for the watch to render.

Imagine top level menu (playlists, songs, albums) and when they click on “songs” it returns a list of songs from the database on the phone, and when the click a song the the song details are returned from the database.

The watch never has any data other than the json passing.

I made a simple go back button that goes up a menu on the watch. Kinda doing remote driven UI

On Wed, Feb 22, 2023 at 10:11 AM Rexios @.***> wrote:

I'm going to need more details on exactly what you're trying to do

— Reply to this email directly, view it on GitHub https://github.com/Rexios80/watch_connectivity/issues/6#issuecomment-1440537071, or unsubscribe https://github.com/notifications/unsubscribe-auth/AHOOFXYAPQNLBFFSU3T543DWYZJF7ANCNFSM6AAAAAAVEUXMLA . You are receiving this because you authored the thread.Message ID: @.***>

-- Rody Davis Jr

rodydavis commented 1 year ago

Also all this is context passing, message is secondary for confirmation of receiving context

On Wed, Feb 22, 2023 at 10:15 AM Rody Davis @.***> wrote:

So there is a SQLite database my iOS app controls and a subset small list I send to the watch.

There is a menu that a user can choose a list item on the watch and the iOS app will return a new state for the watch to render.

Imagine top level menu (playlists, songs, albums) and when they click on “songs” it returns a list of songs from the database on the phone, and when the click a song the the song details are returned from the database.

The watch never has any data other than the json passing.

I made a simple go back button that goes up a menu on the watch. Kinda doing remote driven UI

On Wed, Feb 22, 2023 at 10:11 AM Rexios @.***> wrote:

I'm going to need more details on exactly what you're trying to do

— Reply to this email directly, view it on GitHub https://github.com/Rexios80/watch_connectivity/issues/6#issuecomment-1440537071, or unsubscribe https://github.com/notifications/unsubscribe-auth/AHOOFXYAPQNLBFFSU3T543DWYZJF7ANCNFSM6AAAAAAVEUXMLA . You are receiving this because you authored the thread.Message ID: @.***>

-- Rody Davis Jr

-- Rody Davis Jr

Rexios80 commented 1 year ago

If you're using context what's the issue? You can read the most recent context with receivedApplicationContext

rodydavis commented 1 year ago

The issue is the context can only be so big so when a new state is requested and the iOS app is dead it won’t receive a new state

On Wed, Feb 22, 2023 at 10:17 AM Rexios @.***> wrote:

If you're using context what's the issue? You can read the most recent context with receivedApplicationContext

— Reply to this email directly, view it on GitHub https://github.com/Rexios80/watch_connectivity/issues/6#issuecomment-1440552828, or unsubscribe https://github.com/notifications/unsubscribe-auth/AHOOFXY7YCSBXGTKYLRDKJTWYZJ3BANCNFSM6AAAAAAVEUXMLA . You are receiving this because you authored the thread.Message ID: @.***>

-- Rody Davis Jr

Rexios80 commented 1 year ago

I see. This would require the implementation of the following: https://developer.apple.com/documentation/watchkit/wkwatchconnectivityrefreshbackgroundtask https://developers.google.com/android/reference/com/google/android/gms/wearable/WearableListenerService

Rexios80 commented 1 year ago

I've been meaning to implement those for a while, but I haven't gotten around to it

rodydavis commented 1 year ago

Ok cool! Might make a PR

Rexios80 commented 1 year ago

@rodydavis I'm working on a separate plugin to facilitate the calling of flutter code from native code, so if you put any of that logic in the PR for this just know it will most definitely change in the future

rodydavis commented 1 year ago

Ok I solved my problem a different way! I had a big json file to send and just chunked it over and saved it with FileManager.

Then I am using the navigation view in swift ui.

something I think that could be useful is docs on how to add the iOS and android watch targets.

Rexios80 commented 1 year ago

There is a way to send "data" as well that isn't implemented maybe that would do what you need?

rodydavis commented 1 year ago

Send file might work! The file is a single JSON file and is about 1.4 MB which exceeds the context limit.

The json file is created from a minimal amount of data from the SQLite DB in the iOS app, but now I only need to sync once and the watch doesnt require the link

Screenshot 2023-02-23 at 9 24 27 PM Screenshot 2023-02-23 at 9 24 34 PM
Rexios80 commented 1 year ago

Maybe protobuf could reduce the size of the message

Rexios80 commented 1 year ago

So it turns out receiving messages from the watch when the phone app is dead doesn't require anything special. It just works. @rodydavis if you listen to the message stream early enough in your app startup, you should be able to get the messages just fine.

Rexios80 commented 1 year ago

For iOS, Android still requires a lot of work

rodydavis commented 1 year ago

Ok sounds good! Thinking about building wear OS directly

Rexios80 commented 1 year ago

Closing since this was about iOS and that works. We can make a new issue for Android.