@jskit-ai/agent-docs 0.1.397 → 0.1.398
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/guide/agent/app-extras/assistant-conversation.md +1 -2
- package/guide/agent/app-extras/assistant.md +171 -20
- package/guide/agent/app-extras/mobile-capacitor.md +110 -4
- package/guide/agent/app-extras/push-notifications.md +149 -0
- package/guide/agent/app-extras/realtime.md +11 -0
- package/guide/agent/app-setup/authentication.md +93 -1
- package/guide/agent/framework/client-features.md +65 -0
- package/guide/agent/framework/test-pass.md +3 -1
- package/guide/agent/framework/typed-features.md +12 -0
- package/guide/agent/index.md +1 -0
- package/guide/agent/recipes/file-uploads-and-images.md +24 -1
- package/guide/agent/recipes/installable-app.md +76 -82
- package/guide/agent/recipes/payments-and-subscriptions.md +30 -1
- package/package.json +1 -1
- package/patterns/feature-package/example/booking-engine/package.json +1 -1
- package/patterns/minimal-foundation/example/config/public.js +9 -1
- package/patterns/minimal-foundation/example/package.json +3 -3
- package/patterns/shell-foundation/example/config/public.js +9 -1
- package/patterns/shell-foundation/example/package.json +4 -4
- package/patterns/shell-foundation/example/packages/main/package.json +1 -1
- package/reference/autogen/PATTERN_INDEX.md +106 -40
- package/reference/autogen/README.md +4 -0
- package/reference/autogen/packages/assistant-core.md +4 -2
- package/reference/autogen/packages/assistant-runtime.md +14 -3
- package/reference/autogen/packages/auth-core.md +33 -0
- package/reference/autogen/packages/auth-provider-local-core.md +35 -2
- package/reference/autogen/packages/auth-provider-local-db-core.md +4 -0
- package/reference/autogen/packages/auth-web.md +42 -5
- package/reference/autogen/packages/http-runtime.md +9 -1
- package/reference/autogen/packages/http-web.md +36 -0
- package/reference/autogen/packages/mobile-capacitor.md +121 -5
- package/reference/autogen/packages/payments-core.md +2 -0
- package/reference/autogen/packages/push-core.md +128 -0
- package/reference/autogen/packages/push-web.md +99 -0
- package/reference/autogen/packages/realtime.md +6 -3
- package/reference/autogen/packages/store-purchases-core.md +113 -0
- package/reference/autogen/packages/store-purchases-web.md +55 -0
- package/reference/autogen/packages/uploads-image-web.md +2 -1
- package/reference/autogen/packages/uploads-runtime.md +21 -1
- package/reference/autogen/tooling/jskit-catalog.md +23 -1
- package/reference/autogen/tooling/jskit-release.md +4 -1
- package/skills/jskit/references/client-features.md +65 -0
- package/skills/jskit/references/pattern-index.md +106 -40
- package/skills/jskit/references/patterns/app/minimal-foundation/example/config/public.js +9 -1
- package/skills/jskit/references/patterns/app/minimal-foundation/example/package.json +3 -3
- package/skills/jskit/references/patterns/app/shell-foundation/example/config/public.js +9 -1
- package/skills/jskit/references/patterns/app/shell-foundation/example/package.json +4 -4
- package/skills/jskit/references/patterns/app/shell-foundation/example/packages/main/package.json +1 -1
- package/skills/jskit/references/patterns/auth/accounts-hub/example/package.json +3 -3
- package/skills/jskit/references/patterns/auth/oidc-sign-in/example/package.json +2 -2
- package/skills/jskit/references/patterns/auth/supabase-auth/example/package.json +1 -1
- package/skills/jskit/references/patterns/connectors/calendar-cli/example/package.json +5 -5
- package/skills/jskit/references/patterns/crud/crud-feature-package/example/packages/books/package.json +3 -3
- package/skills/jskit/references/patterns/database/mysql-application/example/package.json +2 -2
- package/skills/jskit/references/patterns/database/postgres-application/example/package.json +2 -2
- package/skills/jskit/references/patterns/mobile/android-app-actions/PATTERN.md +78 -0
- package/skills/jskit/references/patterns/mobile/android-app-actions/example/android/app/src/main/java/com/example/app/SummaryWidget.kt +33 -0
- package/skills/jskit/references/patterns/mobile/android-app-actions/example/android/app/src/main/res/layout/summary_widget.xml +17 -0
- package/skills/jskit/references/patterns/mobile/android-app-actions/example/android/app/src/main/res/xml/shortcuts.xml +16 -0
- package/skills/jskit/references/patterns/mobile/android-app-actions/example/android/app/src/main/res/xml/summary_widget_info.xml +8 -0
- package/skills/jskit/references/patterns/mobile/android-application/PATTERN.md +45 -2
- package/skills/jskit/references/patterns/mobile/android-application/example/android/app/src/main/AndroidManifest.xml +65 -0
- package/skills/jskit/references/patterns/mobile/android-application/example/src/placement.js +19 -0
- package/skills/jskit/references/patterns/mobile/ios-app-intents/PATTERN.md +55 -0
- package/skills/jskit/references/patterns/mobile/ios-app-intents/example/ios/App/App/Intents/ExampleShortcuts.swift +9 -0
- package/skills/jskit/references/patterns/mobile/ios-app-intents/example/ios/App/App/Intents/UnreadCountIntent.swift +33 -0
- package/skills/jskit/references/patterns/mobile/ios-application/PATTERN.md +169 -0
- package/skills/jskit/references/patterns/mobile/ios-application/example/capacitor.config.json +10 -0
- package/skills/jskit/references/patterns/mobile/ios-application/example/ios/App/App/App.entitlements +12 -0
- package/skills/jskit/references/patterns/mobile/ios-application/example/ios/App/App/App.swift +20 -0
- package/skills/jskit/references/patterns/mobile/ios-application/example/ios/App/App/Info.plist +63 -0
- package/skills/jskit/references/patterns/mobile/ios-application/example/package.json +15 -0
- package/skills/jskit/references/patterns/mobile/ios-application/example/src/placement.js +19 -0
- package/skills/jskit/references/patterns/mobile/ios-live-activity/PATTERN.md +73 -0
- package/skills/jskit/references/patterns/mobile/ios-live-activity/example/ios/App/LiveActivities/LiveActivitiesBundle.swift +13 -0
- package/skills/jskit/references/patterns/mobile/ios-live-activity/example/src/deliveryActivity.js +33 -0
- package/skills/jskit/references/patterns/mobile/ios-share-extension/PATTERN.md +83 -0
- package/skills/jskit/references/patterns/mobile/ios-share-extension/example/ios/App/ShareExtension/Info.plist +31 -0
- package/skills/jskit/references/patterns/mobile/ios-share-extension/example/ios/App/ShareExtension/ShareExtension.entitlements +10 -0
- package/skills/jskit/references/patterns/mobile/ios-share-extension/example/ios/App/ShareExtension/ShareViewController.swift +94 -0
- package/skills/jskit/references/patterns/mobile/ios-widget/PATTERN.md +66 -0
- package/skills/jskit/references/patterns/mobile/ios-widget/example/ios/App/SummaryWidget/SummaryWidget.swift +64 -0
- package/skills/jskit/references/patterns/mobile/ios-widget/example/src/widgetSummary.js +10 -0
- package/skills/jskit/references/patterns/realtime/realtime-application/example/package.json +2 -2
- package/skills/jskit/references/patterns/server/feature-package/example/booking-engine/package.json +1 -1
- package/skills/jskit/references/patterns/users/user-administration-server/example/packages/users/package.json +3 -3
- package/skills/jskit/references/patterns/users/user-administration-server/example/packages/users-workspace/package.json +6 -6
- package/skills/jskit/references/test-pass.md +3 -1
- package/skills/jskit/references/typed-features.md +12 -0
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
---
|
|
2
|
+
id: mobile/android-app-actions
|
|
3
|
+
title: Android app shortcuts and widget
|
|
4
|
+
summary: App icon shortcuts (static and from the screens) and a Home Screen widget fed by the shared store.
|
|
5
|
+
keywords: android, app actions, app shortcuts, appwidget, home screen, mobile, quick actions, shortcuts, widget
|
|
6
|
+
requires: @jskit-ai/mobile-capacitor, @capawesome/capacitor-app-shortcuts, capacitor-widget-bridge, @capacitor/android
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
# Android app shortcuts and widget
|
|
10
|
+
|
|
11
|
+
## Use when
|
|
12
|
+
|
|
13
|
+
Use this pattern for actions on the app's icon (a long press, Google Assistant's app actions) and a Home Screen widget
|
|
14
|
+
showing something from the app.
|
|
15
|
+
|
|
16
|
+
## Do not use when
|
|
17
|
+
|
|
18
|
+
Do not use it for actions that need the server without opening the app.
|
|
19
|
+
|
|
20
|
+
## Product decisions
|
|
21
|
+
|
|
22
|
+
Choose the static shortcuts, the dynamic ones the screens set, the widget's content and the pages taps open.
|
|
23
|
+
|
|
24
|
+
## Framework APIs
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
npm install @capawesome/capacitor-app-shortcuts@^8.0.3 capacitor-widget-bridge@^9.0.0
|
|
28
|
+
npx cap sync android
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
Static shortcuts: `res/xml/shortcuts.xml`, and in `AndroidManifest.xml` inside the main activity
|
|
32
|
+
`<meta-data android:name="android.app.shortcuts" android:resource="@xml/shortcuts" />`. Each opens the app's own scheme,
|
|
33
|
+
which launch routing turns into a route. Dynamic shortcuts come from the screens through `mobile.appShortcuts.set([{
|
|
34
|
+
id, title, path }])` (the `client.mobile` capability); tapping one opens its `path`, an app path only. The same call
|
|
35
|
+
sets iOS's Home Screen quick actions.
|
|
36
|
+
|
|
37
|
+
The widget: `SummaryWidget.kt`, its `res/xml/summary_widget_info.xml` and `res/layout/summary_widget.xml`, declared in
|
|
38
|
+
the manifest:
|
|
39
|
+
|
|
40
|
+
```xml
|
|
41
|
+
<receiver android:name=".SummaryWidget" android:exported="false">
|
|
42
|
+
<intent-filter><action android:name="android.appwidget.action.APPWIDGET_UPDATE" /></intent-filter>
|
|
43
|
+
<meta-data android:name="android.appwidget.provider" android:resource="@xml/summary_widget_info" />
|
|
44
|
+
</receiver>
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
and named in `config/public.js` so writes reload it:
|
|
48
|
+
|
|
49
|
+
```js
|
|
50
|
+
config.mobile = { ...config.mobile, sharedStore: { group: "group.com.example.app", androidWidgets: ["com.example.app.SummaryWidget"] } };
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
The screens write with `mobile.sharedStore.set("summary", { title, unread })`, as on iOS.
|
|
54
|
+
|
|
55
|
+
## Example files
|
|
56
|
+
|
|
57
|
+
`example/android/app/src/main/res/xml/shortcuts.xml`, `res/xml/summary_widget_info.xml`,
|
|
58
|
+
`res/layout/summary_widget.xml` and `java/com/example/app/SummaryWidget.kt`. Replace `com.example.app`,
|
|
59
|
+
`group.com.example.app` and `exampleapp`; add `shortcut_new_message` to `res/values/strings.xml`.
|
|
60
|
+
|
|
61
|
+
## Variation points
|
|
62
|
+
|
|
63
|
+
Shortcuts, the widget's layout and content, and the pages taps open.
|
|
64
|
+
|
|
65
|
+
## Invariants
|
|
66
|
+
|
|
67
|
+
- Shortcuts and the widget open only the app's own pages, through its scheme or `path`.
|
|
68
|
+
- The widget reads only the shared store; it never calls the server.
|
|
69
|
+
|
|
70
|
+
## Verification
|
|
71
|
+
|
|
72
|
+
On an Android phone: long-press the icon for each shortcut, add the widget, change its content in the app and see it
|
|
73
|
+
reload, tap it.
|
|
74
|
+
|
|
75
|
+
## Avoid
|
|
76
|
+
|
|
77
|
+
- a shortcut that opens another site or app
|
|
78
|
+
- network requests from the widget
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
package com.example.app
|
|
2
|
+
|
|
3
|
+
import android.app.PendingIntent
|
|
4
|
+
import android.appwidget.AppWidgetManager
|
|
5
|
+
import android.appwidget.AppWidgetProvider
|
|
6
|
+
import android.content.Context
|
|
7
|
+
import android.content.Intent
|
|
8
|
+
import android.net.Uri
|
|
9
|
+
import android.widget.RemoteViews
|
|
10
|
+
import org.json.JSONObject
|
|
11
|
+
|
|
12
|
+
// A Home Screen widget showing what the app's screens wrote with mobile.sharedStore.set("summary", { title, unread }):
|
|
13
|
+
// JSON in the SharedPreferences named like the iOS App Group (config.mobile.sharedStore.group). The app reloads it
|
|
14
|
+
// after each write; a tap opens the app's inbox through its own scheme.
|
|
15
|
+
class SummaryWidget : AppWidgetProvider() {
|
|
16
|
+
override fun onUpdate(context: Context, manager: AppWidgetManager, widgetIds: IntArray) {
|
|
17
|
+
val text = context.getSharedPreferences("group.com.example.app", Context.MODE_PRIVATE).getString("summary", null)
|
|
18
|
+
val summary = text?.let { runCatching { JSONObject(it) }.getOrNull() }
|
|
19
|
+
val open = PendingIntent.getActivity(
|
|
20
|
+
context,
|
|
21
|
+
0,
|
|
22
|
+
Intent(Intent.ACTION_VIEW, Uri.parse("exampleapp://inbox")).setPackage(context.packageName),
|
|
23
|
+
PendingIntent.FLAG_IMMUTABLE
|
|
24
|
+
)
|
|
25
|
+
for (widgetId in widgetIds) {
|
|
26
|
+
val views = RemoteViews(context.packageName, R.layout.summary_widget)
|
|
27
|
+
views.setTextViewText(R.id.summary_title, summary?.optString("title") ?: "Example")
|
|
28
|
+
views.setTextViewText(R.id.summary_unread, summary?.let { "${it.optInt("unread")} unread" } ?: "Open the app to start")
|
|
29
|
+
views.setOnClickPendingIntent(R.id.summary_widget, open)
|
|
30
|
+
manager.updateAppWidget(widgetId, views)
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="utf-8"?>
|
|
2
|
+
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
|
3
|
+
android:id="@+id/summary_widget"
|
|
4
|
+
android:layout_width="match_parent"
|
|
5
|
+
android:layout_height="match_parent"
|
|
6
|
+
android:orientation="vertical"
|
|
7
|
+
android:padding="12dp">
|
|
8
|
+
<TextView
|
|
9
|
+
android:id="@+id/summary_title"
|
|
10
|
+
android:layout_width="wrap_content"
|
|
11
|
+
android:layout_height="wrap_content"
|
|
12
|
+
android:textStyle="bold" />
|
|
13
|
+
<TextView
|
|
14
|
+
android:id="@+id/summary_unread"
|
|
15
|
+
android:layout_width="wrap_content"
|
|
16
|
+
android:layout_height="wrap_content" />
|
|
17
|
+
</LinearLayout>
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="utf-8"?>
|
|
2
|
+
<!-- The app icon's static shortcuts. Each opens one of the app's pages through its own scheme, which the app's launch
|
|
3
|
+
routing turns into a route. Dynamic shortcuts come from the screens, through mobile.appShortcuts. -->
|
|
4
|
+
<shortcuts xmlns:android="http://schemas.android.com/apk/res/android">
|
|
5
|
+
<shortcut
|
|
6
|
+
android:shortcutId="new-message"
|
|
7
|
+
android:enabled="true"
|
|
8
|
+
android:icon="@mipmap/ic_launcher"
|
|
9
|
+
android:shortcutShortLabel="@string/shortcut_new_message">
|
|
10
|
+
<intent
|
|
11
|
+
android:action="android.intent.action.VIEW"
|
|
12
|
+
android:data="exampleapp://messages/new"
|
|
13
|
+
android:targetPackage="com.example.app"
|
|
14
|
+
android:targetClass="com.example.app.MainActivity" />
|
|
15
|
+
</shortcut>
|
|
16
|
+
</shortcuts>
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="utf-8"?>
|
|
2
|
+
<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android"
|
|
3
|
+
android:initialLayout="@layout/summary_widget"
|
|
4
|
+
android:minWidth="110dp"
|
|
5
|
+
android:minHeight="40dp"
|
|
6
|
+
android:resizeMode="horizontal|vertical"
|
|
7
|
+
android:updatePeriodMillis="0"
|
|
8
|
+
android:widgetCategory="home_screen" />
|
|
@@ -61,6 +61,44 @@ the Android Gradle Plugin 9.4.1 (which bundles Kotlin), an edge-to-edge
|
|
|
61
61
|
8 wrote moves with `npx cap migrate` first: `npm run jskit:check` names what is
|
|
62
62
|
left (`capacitor/*`), and `npm run jskit:update` refuses until then.
|
|
63
63
|
|
|
64
|
+
### Building the screens for the app
|
|
65
|
+
|
|
66
|
+
`npm run build` stays the web build. The app's bundled screens come from
|
|
67
|
+
`jskit build --mobile`, which runs Vite with a relative base and the `mobile`
|
|
68
|
+
mode (`import.meta.env.MODE`) into `capacitor.config.json`'s `webDir`, calling
|
|
69
|
+
the server at `config.mobile.apiBaseUrl`. It fails when a service worker lands
|
|
70
|
+
in the output. Then `npx cap sync` copies the screens into the native project.
|
|
71
|
+
|
|
72
|
+
### Device plugins through JSKIT
|
|
73
|
+
|
|
74
|
+
JSKIT reaches each device plugin through Capacitor's bridge and its own
|
|
75
|
+
interface, so the app installs a plugin and never imports it: `jskit check`
|
|
76
|
+
recommends moving a plugin that is outside the line JSKIT supports
|
|
77
|
+
(`capacitor/plugins`). The `mobile` capability's `appShell` covers the app's
|
|
78
|
+
lifecycle, the back button, the keyboard, haptics, the share sheet, the splash
|
|
79
|
+
screen and the system bars; install `@capacitor/keyboard`, `@capacitor/haptics`,
|
|
80
|
+
`@capacitor/share` and `@capacitor/splash-screen` (^9) for the parts the app
|
|
81
|
+
uses. With `@capacitor/splash-screen`, set `launchAutoHide` to `false`: JSKIT
|
|
82
|
+
hides the splash once the first screen's route is in place.
|
|
83
|
+
|
|
84
|
+
### Please update
|
|
85
|
+
|
|
86
|
+
Each request from the app carries its version (`config.mobile.ios.version` or
|
|
87
|
+
`config.mobile.android.versionName`) and platform. The server's
|
|
88
|
+
`APP_MIN_VERSION_IOS` and `APP_MIN_VERSION_ANDROID` set the oldest version it
|
|
89
|
+
serves; an older app is answered 426 and shows a full-screen "please update"
|
|
90
|
+
screen, which the app places with `example/src/placement.js`. Its button
|
|
91
|
+
opens Google Play's in-app update or the store page through
|
|
92
|
+
`@capawesome/capacitor-app-update` (^8.1.1), or, without it, the store page
|
|
93
|
+
through `@capacitor/app-launcher` (^9.0.2). On iOS it needs
|
|
94
|
+
`config.mobile.ios.appStoreId`, the app's numeric App Store id.
|
|
95
|
+
|
|
96
|
+
Release builds sign with the upload key the build service keeps in its
|
|
97
|
+
secrets, by name: the keystore file, its password, the key alias and the key's
|
|
98
|
+
password. `android/app/build.gradle` reads them from the environment in a
|
|
99
|
+
`signingConfigs.release` block, and `./gradlew bundleRelease` writes the
|
|
100
|
+
`.aab` Google Play takes. The keystore is never committed.
|
|
101
|
+
|
|
64
102
|
Use `adb devices`, `adb reverse`, Android Studio, and Gradle directly for device
|
|
65
103
|
selection, tunnelling, diagnostics, and release builds. JSKIT does not wrap
|
|
66
104
|
those tools in another command language.
|
|
@@ -68,7 +106,12 @@ those tools in another command language.
|
|
|
68
106
|
## Example files
|
|
69
107
|
|
|
70
108
|
`example/capacitor.config.json` shows the small Capacitor configuration shape.
|
|
71
|
-
|
|
109
|
+
`example/android/app/src/main/AndroidManifest.xml` is Capacitor 9's file with
|
|
110
|
+
an App Links intent filter (`autoVerify`, each domain in
|
|
111
|
+
`config.mobile.auth.appLinkDomains`) and the custom scheme
|
|
112
|
+
(`config.mobile.auth.customScheme`) added, so sign-in callbacks and links open
|
|
113
|
+
the app. `example/src/placement.js` places the "please update" screen. Replace
|
|
114
|
+
their obvious values directly; they are not interpolation templates.
|
|
72
115
|
|
|
73
116
|
## Variation points
|
|
74
117
|
|
|
@@ -94,6 +137,6 @@ external links, then build the native release variant.
|
|
|
94
137
|
## Avoid
|
|
95
138
|
|
|
96
139
|
- hidden device selection
|
|
97
|
-
- checking secrets or signing keys into source
|
|
140
|
+
- checking secrets, keystores or signing keys into source
|
|
98
141
|
- a JSKIT-specific wrapper around Capacitor, adb, or Gradle
|
|
99
142
|
- generated-operation receipts
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="utf-8"?>
|
|
2
|
+
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
|
|
3
|
+
|
|
4
|
+
<application
|
|
5
|
+
android:allowBackup="true"
|
|
6
|
+
android:icon="@mipmap/ic_launcher"
|
|
7
|
+
android:label="@string/app_name"
|
|
8
|
+
android:roundIcon="@mipmap/ic_launcher_round"
|
|
9
|
+
android:supportsRtl="true"
|
|
10
|
+
android:theme="@style/AppTheme">
|
|
11
|
+
|
|
12
|
+
<activity
|
|
13
|
+
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|smallestScreenSize|screenLayout|uiMode|navigation|density"
|
|
14
|
+
android:name=".MainActivity"
|
|
15
|
+
android:label="@string/title_activity_main"
|
|
16
|
+
android:theme="@style/AppTheme.NoActionBarLaunch"
|
|
17
|
+
android:launchMode="singleTask"
|
|
18
|
+
android:exported="true">
|
|
19
|
+
|
|
20
|
+
<intent-filter>
|
|
21
|
+
<action android:name="android.intent.action.MAIN" />
|
|
22
|
+
<category android:name="android.intent.category.LAUNCHER" />
|
|
23
|
+
</intent-filter>
|
|
24
|
+
|
|
25
|
+
<intent-filter android:autoVerify="true">
|
|
26
|
+
<action android:name="android.intent.action.VIEW" />
|
|
27
|
+
<category android:name="android.intent.category.DEFAULT" />
|
|
28
|
+
<category android:name="android.intent.category.BROWSABLE" />
|
|
29
|
+
<data android:scheme="https" android:host="app.example.com" />
|
|
30
|
+
</intent-filter>
|
|
31
|
+
|
|
32
|
+
<intent-filter>
|
|
33
|
+
<action android:name="android.intent.action.VIEW" />
|
|
34
|
+
<category android:name="android.intent.category.DEFAULT" />
|
|
35
|
+
<category android:name="android.intent.category.BROWSABLE" />
|
|
36
|
+
<data android:scheme="exampleapp" />
|
|
37
|
+
</intent-filter>
|
|
38
|
+
|
|
39
|
+
<!-- Sharing into the app (@capgo/capacitor-share-target): text, links, images and files from the share sheet. -->
|
|
40
|
+
<intent-filter>
|
|
41
|
+
<action android:name="android.intent.action.SEND" />
|
|
42
|
+
<action android:name="android.intent.action.SEND_MULTIPLE" />
|
|
43
|
+
<category android:name="android.intent.category.DEFAULT" />
|
|
44
|
+
<data android:mimeType="text/*" />
|
|
45
|
+
<data android:mimeType="image/*" />
|
|
46
|
+
<data android:mimeType="application/pdf" />
|
|
47
|
+
</intent-filter>
|
|
48
|
+
|
|
49
|
+
</activity>
|
|
50
|
+
|
|
51
|
+
<provider
|
|
52
|
+
android:name="androidx.core.content.FileProvider"
|
|
53
|
+
android:authorities="${applicationId}.fileprovider"
|
|
54
|
+
android:exported="false"
|
|
55
|
+
android:grantUriPermissions="true">
|
|
56
|
+
<meta-data
|
|
57
|
+
android:name="android.support.FILE_PROVIDER_PATHS"
|
|
58
|
+
android:resource="@xml/file_paths"></meta-data>
|
|
59
|
+
</provider>
|
|
60
|
+
</application>
|
|
61
|
+
|
|
62
|
+
<!-- Permissions -->
|
|
63
|
+
|
|
64
|
+
<uses-permission android:name="android.permission.INTERNET" />
|
|
65
|
+
</manifest>
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { createPlacementRegistry } from "@jskit-ai/shell-web/client/placement";
|
|
2
|
+
|
|
3
|
+
const registry = createPlacementRegistry();
|
|
4
|
+
const { addPlacement } = registry;
|
|
5
|
+
|
|
6
|
+
// The "please update" screen. It renders nothing until the server refuses this app version (426); then its
|
|
7
|
+
// full-screen dialog covers the app, wherever the shell's status outlet is.
|
|
8
|
+
addPlacement({
|
|
9
|
+
id: "mobile.update-required",
|
|
10
|
+
target: "shell.status",
|
|
11
|
+
kind: "component",
|
|
12
|
+
surfaces: ["*"],
|
|
13
|
+
order: 1000,
|
|
14
|
+
componentToken: "mobile.web.update-required"
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
export default function getPlacements() {
|
|
18
|
+
return registry.build();
|
|
19
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
---
|
|
2
|
+
id: mobile/ios-app-intents
|
|
3
|
+
title: iOS App Intents and Shortcuts
|
|
4
|
+
summary: App Intents that Siri, Shortcuts and Spotlight run, answered from the shared store or opening one of the app's pages.
|
|
5
|
+
keywords: app intents, ios, iphone, mobile, shortcuts, siri, spotlight
|
|
6
|
+
requires: @jskit-ai/mobile-capacitor, capacitor-widget-bridge, @capacitor/ios
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
# iOS App Intents and Shortcuts
|
|
10
|
+
|
|
11
|
+
## Use when
|
|
12
|
+
|
|
13
|
+
Use this pattern when people should reach a few of the app's actions by voice, from the Shortcuts app or from
|
|
14
|
+
Spotlight: a quick answer ("how many unread?") or opening a page ("new message").
|
|
15
|
+
|
|
16
|
+
## Do not use when
|
|
17
|
+
|
|
18
|
+
Do not use it for actions that need the server and the person's session from outside the app; an intent here answers
|
|
19
|
+
from the shared store or opens the app.
|
|
20
|
+
|
|
21
|
+
## Product decisions
|
|
22
|
+
|
|
23
|
+
Choose the few intents, their phrases, and for each whether it answers from the shared store or opens a page.
|
|
24
|
+
|
|
25
|
+
## Framework APIs
|
|
26
|
+
|
|
27
|
+
App Intents are Swift in the app's own target, in the committed `ios/App` project; no plugin is involved. An intent
|
|
28
|
+
that answers reads the same App Group the widget pattern uses (`config.mobile.sharedStore.group`, written by
|
|
29
|
+
`mobile.sharedStore.set`), so give the app target the App Groups capability. An intent that opens a page opens the
|
|
30
|
+
app's own scheme (`config.mobile.auth.customScheme`), which `@jskit-ai/mobile-capacitor`'s launch routing turns into an
|
|
31
|
+
ordinary route.
|
|
32
|
+
|
|
33
|
+
## Example files
|
|
34
|
+
|
|
35
|
+
`example/ios/App/App/Intents/UnreadCountIntent.swift` (an answering intent and an opening one) and
|
|
36
|
+
`ExampleShortcuts.swift` (the `AppShortcutsProvider` with their phrases). Replace `group.com.example.app` and
|
|
37
|
+
`exampleapp`.
|
|
38
|
+
|
|
39
|
+
## Variation points
|
|
40
|
+
|
|
41
|
+
The intents, their phrases and titles, and the pages they open.
|
|
42
|
+
|
|
43
|
+
## Invariants
|
|
44
|
+
|
|
45
|
+
- An intent reads only the shared store, or opens one of the app's own pages.
|
|
46
|
+
- Opened pages arrive through launch routing, like any link.
|
|
47
|
+
|
|
48
|
+
## Verification
|
|
49
|
+
|
|
50
|
+
On an iPhone: ask Siri each phrase, run each from the Shortcuts app, find them in Spotlight.
|
|
51
|
+
|
|
52
|
+
## Avoid
|
|
53
|
+
|
|
54
|
+
- server calls from an intent without the app
|
|
55
|
+
- an intent that opens another site or scheme
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import AppIntents
|
|
2
|
+
|
|
3
|
+
// The phrases Siri and Spotlight offer without setup.
|
|
4
|
+
struct ExampleShortcuts: AppShortcutsProvider {
|
|
5
|
+
static var appShortcuts: [AppShortcut] {
|
|
6
|
+
AppShortcut(intent: UnreadCountIntent(), phrases: ["How many unread in \(.applicationName)"], shortTitle: "Unread", systemImageName: "tray")
|
|
7
|
+
AppShortcut(intent: NewMessageIntent(), phrases: ["New message in \(.applicationName)"], shortTitle: "New message", systemImageName: "square.and.pencil")
|
|
8
|
+
}
|
|
9
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import AppIntents
|
|
2
|
+
import Foundation
|
|
3
|
+
import UIKit
|
|
4
|
+
|
|
5
|
+
// "How many unread?" for Siri, Shortcuts and Spotlight: answered from the summary the app's screens keep in the shared
|
|
6
|
+
// store (mobile.sharedStore.set("summary", { title, unread })), without opening the app.
|
|
7
|
+
private let APP_GROUP_ID = "group.com.example.app"
|
|
8
|
+
|
|
9
|
+
struct UnreadCountIntent: AppIntent {
|
|
10
|
+
static var title: LocalizedStringResource = "Unread messages"
|
|
11
|
+
static var description = IntentDescription("Tells you how many messages are waiting.")
|
|
12
|
+
|
|
13
|
+
func perform() async throws -> some IntentResult & ProvidesDialog {
|
|
14
|
+
let text = UserDefaults(suiteName: APP_GROUP_ID)?.string(forKey: "summary") ?? ""
|
|
15
|
+
let summary = text.data(using: .utf8).flatMap { try? JSONSerialization.jsonObject(with: $0) as? [String: Any] }
|
|
16
|
+
let unread = summary?["unread"] as? Int ?? 0
|
|
17
|
+
return .result(dialog: "You have \(unread) unread messages.")
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// Opens the app on its compose page, through the app's own scheme, which its launch routing turns into a route.
|
|
22
|
+
struct NewMessageIntent: AppIntent {
|
|
23
|
+
static var title: LocalizedStringResource = "New message"
|
|
24
|
+
static var openAppWhenRun = true
|
|
25
|
+
|
|
26
|
+
@MainActor
|
|
27
|
+
func perform() async throws -> some IntentResult {
|
|
28
|
+
if let url = URL(string: "exampleapp://messages/new") {
|
|
29
|
+
await UIApplication.shared.open(url)
|
|
30
|
+
}
|
|
31
|
+
return .result()
|
|
32
|
+
}
|
|
33
|
+
}
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
---
|
|
2
|
+
id: mobile/ios-application
|
|
3
|
+
title: Capacitor iOS application
|
|
4
|
+
summary: Wrap a JSKIT web application in a Capacitor iOS shell using native Capacitor and Xcode commands.
|
|
5
|
+
keywords: apple, capacitor, device, ios, iphone, mobile, native, shell, webview
|
|
6
|
+
requires: @jskit-ai/mobile-capacitor, @capacitor/ios, @capacitor/app, @capacitor/browser, @capacitor/cli
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
# Capacitor iOS application
|
|
10
|
+
|
|
11
|
+
## Use when
|
|
12
|
+
|
|
13
|
+
Use this pattern when the same JSKIT application should run inside a Capacitor
|
|
14
|
+
iOS shell, with its web screens bundled in the app, and the product accepts a
|
|
15
|
+
WebView-based native application.
|
|
16
|
+
|
|
17
|
+
## Do not use when
|
|
18
|
+
|
|
19
|
+
Do not use this pattern for a browser-only app, for a native UI product, or when
|
|
20
|
+
the target platform is not supported by the selected Capacitor packages.
|
|
21
|
+
|
|
22
|
+
## Product decisions
|
|
23
|
+
|
|
24
|
+
Choose the stable bundle id, display name, built web directory, the custom URL
|
|
25
|
+
scheme and the Universal Link domains for sign-in callbacks, the development
|
|
26
|
+
server policy, and the capabilities the app asks for (notifications,
|
|
27
|
+
associated domains) before creating the iOS project.
|
|
28
|
+
|
|
29
|
+
## Framework APIs
|
|
30
|
+
|
|
31
|
+
The package runs on Capacitor 9, and every Capacitor package of the app is on
|
|
32
|
+
that major. Install them by range, so that a later Capacitor major never joins
|
|
33
|
+
them unasked:
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
npm install @jskit-ai/mobile-capacitor \
|
|
37
|
+
@capacitor/ios@^9.0.0 @capacitor/app@^9.0.2 @capacitor/browser@^9.0.2 \
|
|
38
|
+
@capacitor/cli@^9.0.0
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
`@capacitor/browser` is a dependency of `@jskit-ai/mobile-capacitor`, which
|
|
42
|
+
opens sign-in with it, but `npx cap sync` builds only the native plugins the
|
|
43
|
+
app's own `package.json` lists, so the app installs it too.
|
|
44
|
+
|
|
45
|
+
Capacitor 9's CLI needs Node.js 24 or newer. Building and running the iOS app
|
|
46
|
+
needs a Mac with the Xcode that
|
|
47
|
+
[Capacitor 9's update guide](https://capacitorjs.com/docs/updating/9-0) names.
|
|
48
|
+
`npx cap add ios` itself runs anywhere, so the project can be made and committed
|
|
49
|
+
before a Mac is involved. Adapt `example/capacitor.config.json` into valid
|
|
50
|
+
JSON, then use Capacitor directly:
|
|
51
|
+
|
|
52
|
+
```text
|
|
53
|
+
npm run build
|
|
54
|
+
npx cap add ios
|
|
55
|
+
npx cap sync ios
|
|
56
|
+
npx cap doctor ios
|
|
57
|
+
npx cap open ios
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
`npx cap add ios` writes Capacitor 9's project: deployment target iOS 16.0, the
|
|
61
|
+
Swift Package Manager (`ios/App/CapApp-SPM/Package.swift`, no CocoaPods), and
|
|
62
|
+
the SwiftUI entry point Capacitor 9 requires, `ios/App/App/App.swift`, whose
|
|
63
|
+
`@main` `App` hands opened URLs and Universal Links to Capacitor. Keep that file
|
|
64
|
+
as Capacitor wrote it: `npm run jskit:check` names an app target without a
|
|
65
|
+
SwiftUI `@main` entry. Live reload is `npx cap run ios --url <dev server URL>`.
|
|
66
|
+
|
|
67
|
+
Add to the project what the example shows:
|
|
68
|
+
|
|
69
|
+
- `ios/App/App/Info.plist`: `CFBundleURLTypes` with the app's custom scheme
|
|
70
|
+
(`config.mobile.auth.customScheme`), so sign-in callbacks can return to the
|
|
71
|
+
app.
|
|
72
|
+
- `ios/App/App/App.entitlements`: Associated Domains
|
|
73
|
+
(`applinks:` each domain in `config.mobile.auth.appLinkDomains`) for
|
|
74
|
+
Universal Links, and `aps-environment` when the app receives notifications.
|
|
75
|
+
Turn on the same capabilities for the App ID in the Apple Developer account.
|
|
76
|
+
|
|
77
|
+
### Building the screens for the app
|
|
78
|
+
|
|
79
|
+
`npm run build` stays the web build. The app's bundled screens come from
|
|
80
|
+
`jskit build --mobile`, which runs Vite with a relative base and the `mobile`
|
|
81
|
+
mode (`import.meta.env.MODE`) into `capacitor.config.json`'s `webDir`, calling
|
|
82
|
+
the server at `config.mobile.apiBaseUrl`. It fails when a service worker lands
|
|
83
|
+
in the output. Then `npx cap sync` copies the screens into the native project.
|
|
84
|
+
|
|
85
|
+
### Device plugins through JSKIT
|
|
86
|
+
|
|
87
|
+
JSKIT reaches each device plugin through Capacitor's bridge and its own
|
|
88
|
+
interface, so the app installs a plugin and never imports it: `jskit check`
|
|
89
|
+
recommends moving a plugin that is outside the line JSKIT supports
|
|
90
|
+
(`capacitor/plugins`). The `mobile` capability's `appShell` covers the app's
|
|
91
|
+
lifecycle, the back button, the keyboard, haptics, the share sheet, the splash
|
|
92
|
+
screen and the system bars; install `@capacitor/keyboard`, `@capacitor/haptics`,
|
|
93
|
+
`@capacitor/share` and `@capacitor/splash-screen` (^9) for the parts the app
|
|
94
|
+
uses. With `@capacitor/splash-screen`, set `launchAutoHide` to `false`: JSKIT
|
|
95
|
+
hides the splash once the first screen's route is in place.
|
|
96
|
+
|
|
97
|
+
### Please update
|
|
98
|
+
|
|
99
|
+
Each request from the app carries its version (`config.mobile.ios.version` or
|
|
100
|
+
`config.mobile.android.versionName`) and platform. The server's
|
|
101
|
+
`APP_MIN_VERSION_IOS` and `APP_MIN_VERSION_ANDROID` set the oldest version it
|
|
102
|
+
serves; an older app is answered 426 and shows a full-screen "please update"
|
|
103
|
+
screen, which the app places with `example/src/placement.js`. Its button
|
|
104
|
+
opens Google Play's in-app update or the store page through
|
|
105
|
+
`@capawesome/capacitor-app-update` (^8.1.1), or, without it, the store page
|
|
106
|
+
through `@capacitor/app-launcher` (^9.0.2). On iOS it needs
|
|
107
|
+
`config.mobile.ios.appStoreId`, the app's numeric App Store id.
|
|
108
|
+
|
|
109
|
+
Release builds run on a Mac, a cloud Mac build service's included. Archive and
|
|
110
|
+
export with Xcode's own commands:
|
|
111
|
+
|
|
112
|
+
```text
|
|
113
|
+
xcodebuild -project ios/App/App.xcodeproj -scheme App -configuration Release \
|
|
114
|
+
-archivePath build/App.xcarchive archive
|
|
115
|
+
xcodebuild -exportArchive -archivePath build/App.xcarchive \
|
|
116
|
+
-exportOptionsPlist ExportOptions.plist -exportPath build/export
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
The build reads its signing material from the build service's secrets, by
|
|
120
|
+
name: the distribution certificate (`.p12`) and its password, the provisioning
|
|
121
|
+
profile, and an App Store Connect API key (issuer id, key id and its `.p8`) for
|
|
122
|
+
uploading. None of them is ever committed. JSKIT does not wrap Capacitor,
|
|
123
|
+
Xcode or `xcodebuild` in another command language.
|
|
124
|
+
|
|
125
|
+
## Example files
|
|
126
|
+
|
|
127
|
+
`example/capacitor.config.json` and `example/package.json` show the small
|
|
128
|
+
Capacitor configuration and the packages. `example/ios/App/App/App.swift` is
|
|
129
|
+
Capacitor 9's own entry point, unchanged. `example/ios/App/App/Info.plist` is
|
|
130
|
+
Capacitor 9's file with the custom scheme added, and
|
|
131
|
+
`example/ios/App/App/App.entitlements` adds Associated Domains and
|
|
132
|
+
notifications. `example/src/placement.js` places the "please update" screen. Replace their obvious values (`com.example.app`, `exampleapp`,
|
|
133
|
+
`app.example.com`) directly; they are not interpolation templates.
|
|
134
|
+
|
|
135
|
+
`CapacitorHttp` is off in the example, so the app's requests leave from the
|
|
136
|
+
WebView as the web's do. Whether it stays off is settled by the mobile
|
|
137
|
+
prototype on real phones.
|
|
138
|
+
|
|
139
|
+
## Variation points
|
|
140
|
+
|
|
141
|
+
Change bundle id and name, build directory, development server, custom scheme,
|
|
142
|
+
Universal Link domains, plugins, capabilities and entitlements, and the release
|
|
143
|
+
signing the build service holds.
|
|
144
|
+
|
|
145
|
+
## Invariants
|
|
146
|
+
|
|
147
|
+
- `webDir` is the actual output of the application's production build; the
|
|
148
|
+
release app never loads its screens from `server.url`.
|
|
149
|
+
- Development origins are explicit and never leak into release configuration.
|
|
150
|
+
- Browser navigation that leaves the app uses the package's public mobile
|
|
151
|
+
routing capability.
|
|
152
|
+
- Native projects are ordinary app-owned source, committed with the app; signing
|
|
153
|
+
material stays in the build service's secrets.
|
|
154
|
+
- Every `@capacitor/*` package of the app is on Capacitor 9, with one
|
|
155
|
+
`@capacitor/core`.
|
|
156
|
+
|
|
157
|
+
## Verification
|
|
158
|
+
|
|
159
|
+
Build the web application, sync iOS, run `npx cap doctor ios` and
|
|
160
|
+
`npm run jskit:check`, launch on an explicit simulator or device, test callback
|
|
161
|
+
routing, Universal Links and external links, then archive and export the
|
|
162
|
+
release build on the Mac that signs it.
|
|
163
|
+
|
|
164
|
+
## Avoid
|
|
165
|
+
|
|
166
|
+
- loading the release app's screens from a server (`server.url`)
|
|
167
|
+
- checking certificates, provisioning profiles or API keys into source
|
|
168
|
+
- editing `App.swift` away from Capacitor's SwiftUI entry
|
|
169
|
+
- a JSKIT-specific wrapper around Capacitor, Xcode, or `xcodebuild`
|
package/skills/jskit/references/patterns/mobile/ios-application/example/ios/App/App/App.entitlements
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
|
3
|
+
<plist version="1.0">
|
|
4
|
+
<dict>
|
|
5
|
+
<key>com.apple.developer.associated-domains</key>
|
|
6
|
+
<array>
|
|
7
|
+
<string>applinks:app.example.com</string>
|
|
8
|
+
</array>
|
|
9
|
+
<key>aps-environment</key>
|
|
10
|
+
<string>development</string>
|
|
11
|
+
</dict>
|
|
12
|
+
</plist>
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import SwiftUI
|
|
2
|
+
import Capacitor
|
|
3
|
+
|
|
4
|
+
@main
|
|
5
|
+
struct CapacitorApp: App {
|
|
6
|
+
@UIApplicationDelegateAdaptor(AppDelegate.self) var appDelegate
|
|
7
|
+
|
|
8
|
+
var body: some Scene {
|
|
9
|
+
WindowGroup {
|
|
10
|
+
CapacitorView()
|
|
11
|
+
.ignoresSafeArea()
|
|
12
|
+
.onOpenURL { url in
|
|
13
|
+
SceneDelegateProxy.shared.handle(openURL: url)
|
|
14
|
+
}
|
|
15
|
+
.onContinueUserActivity(NSUserActivityTypeBrowsingWeb) { activity in
|
|
16
|
+
SceneDelegateProxy.shared.handle(userActivity: activity)
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|