Skip to content

Commit fa3c0fb

Browse files
Copilotfarfromrefug
andcommitted
Add examples and refactor linker flags logic per code review
Co-authored-by: farfromrefug <655344+farfromrefug@users.noreply.github.com>
1 parent 96b8b7a commit fa3c0fb

2 files changed

Lines changed: 181 additions & 13 deletions

File tree

Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
# Example WatchOS Integration Configuration
2+
3+
This directory contains example configurations demonstrating the enhanced watchOS integration features.
4+
5+
## Directory Structure
6+
7+
```
8+
examples/
9+
watchos-integration/
10+
App_Resources/
11+
iOS/
12+
watchapp/
13+
MyWatchApp/
14+
watchapp.json # Watch app configuration
15+
Assets.xcassets/
16+
Info.plist
17+
ContentView.swift
18+
watchextension/
19+
MyWatchExtension/
20+
extension.json # Extension configuration
21+
Info.plist
22+
InterfaceController.swift
23+
Frameworks/
24+
Data.xcframework/ # Example shared framework
25+
nativescript.config.ts # Main project configuration
26+
README.md
27+
```
28+
29+
## Configuration Files
30+
31+
### 1. nativescript.config.ts
32+
33+
```typescript
34+
import { NativeScriptConfig } from '@nativescript/core';
35+
36+
const config: NativeScriptConfig = {
37+
id: 'com.example.watchapp',
38+
appPath: 'app',
39+
appResourcesPath: 'App_Resources',
40+
ios: {
41+
// Main app SPM packages
42+
SPMPackages: [
43+
{
44+
name: 'Alamofire',
45+
repositoryURL: 'https://github.com/Alamofire/Alamofire.git',
46+
version: '5.6.4',
47+
libs: ['Alamofire']
48+
}
49+
],
50+
51+
// Watch-specific configuration
52+
watchApp: {
53+
// SPM packages for watch targets
54+
SPMPackages: [
55+
{
56+
name: 'SwiftUICharts',
57+
repositoryURL: 'https://github.com/AppPear/ChartView.git',
58+
version: '1.5.5',
59+
libs: ['SwiftUICharts'],
60+
// These will be applied to both watch app and extension targets
61+
},
62+
{
63+
name: 'LocalWatchPackage',
64+
path: './WatchPackages/MyLocalPackage',
65+
libs: ['MyLocalPackage']
66+
}
67+
]
68+
}
69+
}
70+
};
71+
72+
export default config;
73+
```
74+
75+
### 2. watchapp.json
76+
77+
Configuration for the watch app target:
78+
79+
```json
80+
{
81+
"frameworks": [
82+
"WatchKit.framework",
83+
"UserNotifications.framework"
84+
],
85+
"assetcatalogCompilerAppiconName": "AppIcon",
86+
"targetBuildConfigurationProperties": {
87+
"ENABLE_BITCODE": "NO",
88+
"SWIFT_VERSION": "5.0",
89+
"WATCHOS_DEPLOYMENT_TARGET": "7.0"
90+
},
91+
"modules": [
92+
{
93+
"name": "Data",
94+
"path": "Frameworks/Data.xcframework",
95+
"embed": true,
96+
"headerSearchPaths": [
97+
"Frameworks/Data.xcframework/watchos-arm64_arm64_32",
98+
"Frameworks/Data.xcframework/watchos-arm64_arm64_32/Headers"
99+
]
100+
},
101+
{
102+
"name": "SharedModels",
103+
"path": "Frameworks/SharedModels.xcframework",
104+
"embed": true,
105+
"linkerFlags": ["-ObjC"]
106+
}
107+
]
108+
}
109+
```
110+
111+
### 3. extension.json
112+
113+
Configuration for the watch extension target:
114+
115+
```json
116+
{
117+
"frameworks": [
118+
"WatchKit.framework",
119+
"ClockKit.framework",
120+
"WatchConnectivity.framework"
121+
],
122+
"targetBuildConfigurationProperties": {
123+
"ENABLE_BITCODE": "NO",
124+
"SWIFT_VERSION": "5.0",
125+
"WATCHOS_DEPLOYMENT_TARGET": "7.0"
126+
},
127+
"modules": [
128+
{
129+
"name": "Data",
130+
"path": "Frameworks/Data.xcframework",
131+
"embed": false,
132+
"headerSearchPaths": [
133+
"Frameworks/Data.xcframework/watchos-arm64_arm64_32"
134+
]
135+
}
136+
],
137+
"workspaceTarget": "SharedUtilities"
138+
}
139+
```
140+
141+
## Usage Scenarios
142+
143+
See the main [watchOS Integration Guide](../watchos-integration.md) for detailed usage scenarios, troubleshooting, and best practices.
144+
145+
## Quick Start
146+
147+
1. Copy the configuration files to your project
148+
2. Adjust paths and package names to match your setup
149+
3. Build your project:
150+
```bash
151+
ns build ios --for-device
152+
```
153+
154+
## Additional Resources
155+
156+
- [Main watchOS Integration Documentation](../watchos-integration.md)
157+
- [Apple Watch Programming Guide](https://developer.apple.com/documentation/watchkit)
158+
- [Swift Package Manager](https://swift.org/package-manager/)

lib/services/ios-watch-app-service.ts

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -300,20 +300,30 @@ export class IOSWatchAppService implements IIOSWatchAppService {
300300

301301
// Add other linker flags if specified
302302
if (moduleDef.linkerFlags && Array.isArray(moduleDef.linkerFlags)) {
303-
for (const flag of moduleDef.linkerFlags) {
304-
// Use addBuildProperty with target name (productName) to set OTHER_LDFLAGS
305-
const currentFlags = this.getBuildProperty("OTHER_LDFLAGS", targetName, project);
306-
const flagsArray = currentFlags
307-
? (Array.isArray(currentFlags) ? currentFlags : [currentFlags])
308-
: ['"$(inherited)"'];
309-
310-
if (!flagsArray.includes(flag)) {
311-
flagsArray.push(flag);
312-
}
313-
314-
project.addBuildProperty("OTHER_LDFLAGS", flagsArray, null, targetName);
315-
this.$logger.trace(`Added linker flag: ${flag}`);
303+
this.addLinkerFlags(moduleDef.linkerFlags, targetName, project);
304+
}
305+
}
306+
307+
/**
308+
* Add linker flags to a target's build settings
309+
*/
310+
private addLinkerFlags(
311+
flags: string[],
312+
targetName: string,
313+
project: IXcode.project
314+
): void {
315+
for (const flag of flags) {
316+
const currentFlags = this.getBuildProperty("OTHER_LDFLAGS", targetName, project);
317+
const flagsArray = currentFlags
318+
? (Array.isArray(currentFlags) ? currentFlags : [currentFlags])
319+
: ['"$(inherited)"'];
320+
321+
if (!flagsArray.includes(flag)) {
322+
flagsArray.push(flag);
316323
}
324+
325+
project.addBuildProperty("OTHER_LDFLAGS", flagsArray, null, targetName);
326+
this.$logger.trace(`Added linker flag: ${flag}`);
317327
}
318328
}
319329

0 commit comments

Comments
 (0)