Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's a good way to handle changes in authentication between a WatchKit extension and the parent application?

In the case where an application requires authentication to view content (say, a social media app, a banking app, or any app with a login) - what's a good way to handle changes to that authentication state while the WatchKit app is open?

Scenario A: Sign In from iOS app while WatchKit is running. Let's say you launch the WatchKit app, and you're not signed in. The WatchKit app would show you some kind of "please sign in" state, and prompt you to open the iOS app to sign in. When that sign in occurs, how do I notify the WatchKit interface controller to refresh its contents?

Scenario B: Sign out from iOS app while WatchKit is running. let's say you launch the WatchKit app, and you ARE signed in. Then you open the iOS app and sign out - how should I notify the WatchKit app that you've now signed out, and that it should display that "please sign in" state again?

Do I use a timer that constantly checks the auth state? Is there a notification system that I can use?

like image 698
bryanjclark Avatar asked Oct 31 '22 09:10

bryanjclark


1 Answers

For both scenarios, you can send a Darwin notification from the iOS app. Have the WatchKit extension register for one notification string that indicates sign in, and one sign out, and you're sorted.

like image 81
Duncan Babbage Avatar answered Nov 15 '22 06:11

Duncan Babbage