The app demonstrates communication from the phone app to the watch.
If you launch the phone app and the watch app you can click the "Send Message To Phone" button and should see the number on the screen change in sync.
I wanted a cli based build that I can build with iOS App Development profiles to put on various test devices.
To do the same you will need to change the app id in nativescript.config.ts and have 3 corresponding profiles for the app, watch app and extension.
e.g. for app ids
- com.test.app
- com.test.app.watchkitapp
- com.test.app.watchkitapp.watchkitextension
And modify ios_build_options/exportPlist.plist to match.
see additions to
- App_Resources/iOS/watchextension/jasonwapp%20Extension/extension.json
- App_Resources/iOS/watchapp/jasonwapp/watchapp.json
xcode 13 does not generate the info.plist for the watch apps so extra work would have to be done to add them manually. ( I used 12.5 to generate)
nsappwithwatch = whatever the directory it is checked out to is named.
-
run
ns prepare ios
A plugin modifies the generated IOS project in two ways to allow building ( in after-prepare )
- sets
SUPPORTS_UIKITFORMAC = NO
(from project template it is set to YES) - replaces
CODE_SIGN_IDENTITY[sdk=iphoneos*]
withCODE_SIGN_IDENTITY
as per NativeScript/nativescript-cli#5291 Checkingconfig.ast.value.get("buildSettings").get("SDKROOT")
in pbxproj-dom/xcode.ts could decide to set the sdk
- sets
-
run archive
xcodebuild -workspace platforms/ios/nsappwithwatch.xcworkspace -scheme nsappwithwatch archive DEVELOPMENT_TEAM=<TEAM ID> -archivePath builds/MyApp.xcarchive -allowProvisioningUpdates
-
run export ( the exportPlist.plist need to be edited for your profile uuids etc.)
xcodebuild -exportArchive -exportOptionsPlist ios_build_options/exportPlist.plist -archivePath builds/MyApp.xcarchive -exportPath builds/out
Assuming the 3 development profiles for the app, watchapp, extension are already available on the machine out will pop out an ipa that will run on devices.
HOWEVER I ran into this issue: https://developer.apple.com/forums/thread/682775?page=3 because my phone is on IOS15
Resigning the watch app was the only resolution that worked for me.
Steps to resign: ( while in builds/out
)
-
Unpack the ipa
unzip -q nsappwithwatch.ipa
-
Resign the watch extension
codesign -s "Your Code Sign Identity" -f --preserve-metadata --generate-entitlement-der Payload/nsappwithwatch.app/Watch/jasonwapp.app/Plugins/jasonwapp\ Extension.appex
-
Resign the watch app
codesign -s "Your Codesign Identity" -f --preserve-metadata --generate-entitlement-der Payload/nsappwithwatch.app/Watch/jasonwapp.app
-
Resign the main app
codesign -s "Your Codesign Identity" -f --preserve-metadata --generate-entitlement-der Payload/nsappwithwatch.app
-
Repackage the ipa
zip -qr "app-resigned.ipa" Payload
With the above ns run ios
will launch the app but not the watch app in the simulators.
I don't think building/signing will work with ns because of the exportOptions issue NativeScript/nativescript-cli#5291
- ns 8.1.3
- xcode 13
Downgrade the watch simulator os to 7.0 ( there is a bug in the latest watch os simulator that the communication from app to watch does not work and fails sliently)