NativeScript / nativescript-cli

Command-line interface for building NativeScript apps
https://www.npmjs.com/package/nativescript
Apache License 2.0
1.04k stars 195 forks source link

[Tracking][Beta] Embedding Apple Watch App inside NativeScript App #4589

Open KristianDD opened 5 years ago

KristianDD commented 5 years ago

Overview

Apple Watch App Beta feature enables embedding a watch app in NativeScript application by adding watchapp and watchextension folders inside App_Resources/iOS/.

The watch app should be created and developed inside Xcode. Once the user is happy with the result, the folder containing the watch app and the watch app extension should be copied inside App_Resources/iOS/watchapp and App_Resources/iOS/watchextension respectively. Optionally you can add watchapp.json and extension.json which support multiple configurations for the build of the watch app and watch app extension. Example JSON file:

{
    "assetcatalogCompilerAppiconName": "AppIcon",
    "targetBuildConfigurationProperties": {
        "WATCHOS_DEPLOYMENT_TARGET": 4.1
    }
}

In the example above you should have an .xcassets catalog with AppIcon.appiconset inside the watchapp folder.

More information can be found in the feature issue here.

Workflow:

  1. Create Single Page App from Xcode.
  2. Add watch app target - File>New>Target>WatchKit App
  3. Add a name to your watch app, for example MyFirstWatchApp
  4. Copy the generated "MyFirstWatchApp" and MyFirstWatchApp Extension to .../apps/MyApp/app/App_Resources/iOS/watchapp/MyFirstWatchApp and .../apps/MyApp/app/App_Resources/iOS/watchextension/MyFirstWatchApp Extension respectively.
  5. Inside the Info.plist of the Watch App replace the value of WKCompanionAppBundleIdentifier with $(WK_APP_BUNDLE_IDENTIFIER). 6 Inside the Info.plist of the Watch Extension replace the value of WKAppBundleIdentifier with $(WK_APP_BUNDLE_IDENTIFIER).
  6. You can populate the Assets.xcassets of the Watch App and the Watch Extension and add the name of the appiconset to the .../apps/MyApp/app/App_Resources/iOS/watchapp/MyFirstWatchApp/watchapp.json and .../apps/MyApp/app/App_Resources/iOS/watchextension/MyFirstWatchApp Extension/extension.json respectively:
    {
    "assetcatalogCompilerAppiconName": "AppIcon"
    }
  7. You can modify the WATCHOS_DEPLOYMENT_TARGET of the Watch App by adding the value inside the watchapp.json like this:
    {
    "assetcatalogCompilerAppiconName": "AppIcon",
    "targetBuildConfigurationProperties": {
        "WATCHOS_DEPLOYMENT_TARGET": 4.1
    }
    }
  8. Run the NativeScript application

Known issues

Discussion

Please, don't report problems here. Instead, open a new issue and link it to this one. Let's use this discussion for suggestions and improvement ideas. We would love to hear from you!

gabrielbiga commented 6 months ago

The build just broke in favor of xrOS. Details here: https://github.com/NativeScript/ios/issues/249