Search code examples
iosiphonecookieswatchkitapple-watch

How apple watch app share cookie session with its companion iPhone app?


I have an server that can fetch json data via posting request to specific url.

  1. The server uses cookie to recognize user.
  2. If user not login,no required cookie exists and no data will return.
  3. The companion app on iPhone do the Login job and keep the login cookie session required for fetching data.

How can apple watch app share that cookie session on iPhone app?


Solution

  • watchOS 1

    To share data like cookie session on iPhone app, you can use App Groups. Because both WatchKit Extension and iOS app are installed on user's iPhone.

    Sharing Data with Your Containing App https://developer.apple.com/library/prerelease/ios/documentation/General/Conceptual/ExtensibilityPG/ExtensionScenarios.html#//apple_ref/doc/uid/TP40014214-CH21-SW1

    watchOS 2

    To share data on iPhone app, you have to use Watch Connectivity. Because watchKit Extension is installed on user's Apple Watch, and iOS App is the only code and view installed on iPhone.

    https://developer.apple.com/library/prerelease/ios/documentation/WatchConnectivity/Reference/WatchConnectivity_framework/index.html