iOS 计划完成:流式发送 / 后台续传 / APNs / Share Extension / 控制中心控件 + 真机分发预备

- 发送端流式(R-iOS-4):新增 FileSource 抽象(web/src/features/transfer/source.ts),iOS 经 HTTP Range 惰性拉取(原生 WKURLSchemeHandler 认 Range 头 seek 回 206),整文件不进 WebView 内存;web/桌面经 fileSource 包装字节不变。p2p/relay/transfer 改吃 FileSource
- 后台续传:iOS 26 BGContinuedProcessingTask(BackgroundTaskManager + AppDelegate 注册 + BGTaskSchedulerPermittedIdentifiers),引擎传输进度驱动系统进度 UI
- APNs:后端 internal/apns(ES256 .p8 JWT + HTTP/2,仿 internal/push)+ push_subscriptions.platform 列 + POST /api/push/apns/register + transfer/message 未投递分支分流;原生 PushRegistry 授权 + 设备令牌经引擎桥 registerPush 上报;aps-environment + remote-notification 后台模式
- Share Extension:CDropShare appex 抓文件 → App Group 收件箱 → cdrop://share 深链唤主程序选设备发送(只交接、不跑引擎)
- 控制中心剪贴板两控件:CDropWidgets widgetkit appex(ControlWidget + AppIntent + 纯原生 ClipboardClient REST);用专用 broker 设备会话(主程序经引擎 provisionWidgetSession 代铸独立 device_id 会话存 App Group,控件自刷不与引擎抢 refresh 轮换)
- 真机分发预备:committed 签名改 ad-hoc 使模拟器 entitlement 生效;真机手动签名 scaffold(Signing.xcconfig 仅 device SDK 套 Manual + gitignore 的 Local.xcconfig 填 Team/profile)+ just ios-device / ios-devices 全 CLI 装机;包名改 net.commilitia.Commilitia-Drop(含 .share/.widgets,BG task 前缀同改);REALDEVICE.md 重写为门户 + CLI 装机手册
- I18n.swift 移 Shared/ 供三 target 共用;i18n 加 ios.bg/share/control.* 键
- ultracode 多 agent 审查修复(0 HIGH,2 MED + 7 LOW):分享 send 后留收件箱致重发→move 私有暂存;WidgetSession 锁屏文件保护→UntilFirstUserAuthentication;outgoing/安全作用域登出释放;控件 device_id 登出清理;并发控件 refresh CAS-before-clear;APNs 读 reason + prune bad token + bust 过期 JWT;APNSEnv 大小写归一;Share-ext completeRequest 挪进 open 回调
This commit is contained in:
2026-06-27 00:27:55 +08:00
parent 10cf36ecee
commit 44096069a7
59 changed files with 2585 additions and 144 deletions
+3
View File
@@ -6,3 +6,6 @@ build/
DerivedData/
*.xcuserstate
.DS_Store
# 真机签名的账号特定值(Team ID + profile 名)——公开仓库不留账号标识,见 REALDEVICE.md。
Local.xcconfig
+16
View File
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<!-- APNs 推送:注册远程通知需此 entitlement。模拟器(iOS 16+ / Apple Silicon)下 development
即可取令牌、走 sandbox;真机须付费 ADP 开 Push 能力配 profile(账号门控)。 -->
<key>aps-environment</key>
<string>development</string>
<!-- App Group:与 Share Extension 共享待发文件收件箱(见 AppGroup.swift / PLAN §I5)。
模拟器无需签名即生效;真机须付费 ADP 注册该 group(账号门控)。 -->
<key>com.apple.security.application-groups</key>
<array>
<string>group.net.commilitia.cdrop</string>
</array>
</dict>
</plist>
+79 -31
View File
@@ -1,40 +1,88 @@
# cdrop iOS 真机自测手册
# cdrop iOS 真机分发手册
账号到位即可照做。模拟器构建不需签名,已全程 compile + 跑通;**真机**要付费 ADP + 签名 + 实体 iPhone,下面是 turnkey 步骤 + 只能真机验的清单
把 cdrop 装到你自己的 iPhone(开发签名,1 年 profile)。代码侧全部就绪并经模拟器验证;真机只差**账号 + 门户 + 签名**这一层。本手册走**手动签名 + 全 CLI**路线——门户你手动建(一次),构建装机一条命令,**全程不碰 Xcode GUI**
## 包名与标识(门户里要用的)
| 项 | 值 |
|---|---|
| 主 app Bundle ID | `net.commilitia.Commilitia-Drop` |
| Share Extension | `net.commilitia.Commilitia-Drop.share` |
| 控件扩展 | `net.commilitia.Commilitia-Drop.widgets` |
| App Group | `group.net.commilitia.cdrop`(与包名相互独立,刻意不同名) |
| APNs topic(服务端 `CDROP_APNS_TOPIC` | `net.commilitia.Commilitia-Drop` |
## 前置
- 付费 Apple Developer Program$99/年)。
- 一台 iPhoneiOS 26MacXcode 26。
- 已登录的 cdrop(网页 / 桌面)一个——用来扫码批准本机登录。
- 一台 iPhoneiOS 26+ MacXcode 26 命令行工具)
- 一个已登录的 cdrop(网页 / 桌面)——用来扫码批准本机登录。
## 出工程 + 签名
1. `cd ios/CDrop && xcodegen generate`(从 `project.yml` 生成 `CDrop.xcodeproj`)。
2. Xcode 打开 `CDrop.xcodeproj` → 选 `CDrop` target → Signing & Capabilities
- **Team** 选你的 ADP 团队;**Bundle Identifier** 用你账号下可注册的(默认 `net.commilitia.cdrop`,前缀按你的改)。
- 让 Xcode 自动管理签名(Automatically manage signing)。
3. 连 iPhone、信任、选作运行目标 → Run。
- `project.yml``CODE_SIGNING_ALLOWED: NO` 是给模拟器的;Xcode 真机自动签名会覆盖它,无需手改。
---
## 引擎可达性(让传输真能连
- 真机上引擎 WebView 默认加载 `https://drop.commilitia.net/engine.html`——**该文件要先随 web 部署到 prod**(`vite build` 已产出 `dist/engine.html`,随正常 web 发布上线)。
- 或本机联调:设环境变量 `CDROP_ENGINE_URL` 指向可达引擎、`CDROP_API_BASE` 指向后端。
## A. 门户操作(developer.apple.com/account,一次性
## 后续功能要补的 capability(按需,各自要在 Developer Portal 配 App ID
- **App Groups**`group.net.commilitia.cdrop`):Share Extension / 控制中心控件与主 app 共享数据。
- **Push Notifications** + APNs `.p8`:传输事件推送。
- **Keychain Sharing**:跨 app / 扩展共享登录态。
- **Associated Domains**:若改用 OIDC Universal Link 回调(扫码登录则不需要)。
> 入口:登录后左侧 **Certificates, Identifiers & Profiles**(证书 / 标识符 / 描述文件总枢纽)——A1–A5 都在这里面;A6 在 **Keys**Team ID 在 **Membership details**10 位,记下)。
## 只能真机验的清单
- [ ] 液态玻璃在真机渲染(含陀螺仪高光 / 动效)。
- [ ] 扫码登录:本机显码 → 用已登录 cdrop 扫码批准 → app 进入主界面。
- [ ] **本地网络权限**:首次同内网传输弹 `NSLocalNetworkUsageDescription` 提示;授予后 ICE 收到 host 候选(R-iOS-6);拒绝则回退中继仍可传。
- [ ] 发送:选文件 → 选设备 → 对端收到。
- [ ] 接收:对端发来 → 落到 Files(沙盒 Documents)。
- [ ] 后台:传输中切后台 → `BGContinuedProcessingTask` 续传行为(R-iOS-1 / R-iOS-3)。
- [ ] 大文件:发送侧内存(当前整文件入内存,大文件需转分块流式 = R-iOS-4)
1. **证书**Apple Development):本机「钥匙串访问」可能已有(「我的证书」分类里看)。没有就:钥匙串访问菜单 → 证书助理 → 从证书颁发机构请求证书 → 存到磁盘 → 门户 **Certificates** → Apple Development → 传 CSR → 下载 `.cer` 双击安装。
2. **App IDs ×3****Identifiers** → → App IDs → AppBundle ID 选 **Explicit**):
- `net.commilitia.Commilitia-Drop` — 勾 **App Groups** + **Push Notifications**
- `net.commilitia.Commilitia-Drop.share` — 勾 **App Groups**
- `net.commilitia.Commilitia-Drop.widgets` — 勾 **App Groups**
3. **App Group****Identifiers** 页类型筛选切到 **App Groups**`group.net.commilitia.cdrop`。再回上面 3 个 App ID 各自的 App Groups 能力里 **Edit/Configure** 关联它(三个都要)。
4. **设备****Devices** → → 填 UDID(插上手机后 `just ios-devices`)。
5. **描述文件 ×3****Profiles** → **iOS App Development**,非 Distribution):每个选对应 App ID + 证书 + 设备,命名清楚(建议 `CDrop Dev` / `CDrop Share Dev` / `CDrop Widgets Dev`)→ 下载 → 双击安装
6. **APNs Auth Key****Keys** → → 勾 Apple Push Notifications service):下载 `AuthKey_XXXXX.p8`(仅一次),记 **Key ID** + **Issuer ID**(服务端发推送用,见 D)。这把 `.p8` 与 A1 的证书是两码事。
## 已知 TODO(真机阶段一并收)
- 会话 Keychain 持久化 + 自动续期(当前会话在内存、重启需重扫;续期端点 `/api/auth/refresh` 已可用,靠 cookie)。
- 发送侧大文件分块流式(R-iOS-4)。
- 剪贴板 App Intent + 控制中心控件(决策 C)、Share Extension——需上面的 capability + 账号才能跑。
> 常见坑:Bundle ID 选 **Explicit** 不是 WildcardApp Group 务必 3 个 App ID 都关联;Profile 选 **Development** 不要 Distribution。
---
## B. 本地签名配置(gitignore,填一次)
`ios/CDrop/Local.xcconfig` 写入(此文件已 gitignore,公开仓库不留你的账号标识):
```
CDROP_TEAM_ID = ABCDE12345
CDROP_PROFILE_APP = CDrop Dev
CDROP_PROFILE_SHARE = CDrop Share Dev
CDROP_PROFILE_WIDGETS = CDrop Widgets Dev
```
- `CDROP_TEAM_ID`A0 的 Team ID;三个 `CDROP_PROFILE_*`A5 你起的 profile 名(**名字**,不是文件路径)。
- 机制:`Signing.xcconfig`(已提交)仅对 **device SDKiphoneos** 套用手动签名 + 这些值;**模拟器**仍走 `project.yml` 的 ad-hoc`CODE_SIGN_IDENTITY = "-"`),故缺 `Local.xcconfig` 也不影响模拟器构建。
---
## C. 构建装机(全 CLI
```sh
just ios-devices # 手机插 USB,读 UDID(填进门户 A4 + 下行)
just ios-device <你的设备UDID> # 真机构建(手动签名)+ devicectl 装机
```
- `just ios-device` `xcodegen generate``xcodebuild`device,手动签名走 `Local.xcconfig`)→ `xcrun devicectl device install app`。无 Xcode GUI。
- 首次装机后,iPhone 上首启该开发者 app 即可直接跑(付费 ADP 开发证书,无需手动「信任开发者」)。
---
## D. 服务端前置
1. **引擎可达**:真机上引擎 WebView 加载 `https://drop.commilitia.net/engine.html`——**该文件随 cdrop 二进制部署到 prod**`//go:embed` 进 binary`just docker-image` 含最新 `dist`)。手机要用,prod 须是含本轮改动的最新部署。
2. **APNs 真发**:把 A6 的 `.p8` 放到服务器,给后端容器配 `CDROP_APNS_KEY_PATH` / `CDROP_APNS_KEY_ID` / `CDROP_APNS_TEAM_ID` / `CDROP_APNS_TOPIC=net.commilitia.Commilitia-Drop` / `CDROP_APNS_ENV`Xcode 开发构建的 device token 属 **sandbox**,故联调填 `sandbox`)。缺配置则推送惰性关闭,其余功能照常。
3. 本机联调可选:环境变量 `CDROP_ENGINE_URL` 指向可达引擎。
---
## E. 只能真机验的清单
代码已实现,下列是真机才能验的点:
- [ ] 液态玻璃真机渲染(陀螺仪高光 / 动效)。
- [ ] 扫码登录:本机显码 → 已登录 cdrop 扫码批准 → 进主界面(强制 full/persist)。
- [ ] **本地网络权限 + 同内网直连**R-iOS-6):首次同内网传输弹 `NSLocalNetworkUsageDescription`;授予后 ICE 收 host 候选、走真直连;拒绝则回退中继仍可传。
- [ ] 发送 / 接收:选文件 → 选设备 → 对端收到;对端发来落 Files(Documents)。
- [ ] **大文件流式发送**(R-iOS-4 已实现):发大文件,WebView 内存应有界(按 Range 块拉取,不整文件入内存)。
- [ ] **后台续传**R-iOS-1 / R-iOS-3):传输中切后台 → `BGContinuedProcessingTask` 系统进度 UI;验 WKWebView JS 是否随之保活(不保活则退化为回前台续传,可接受)。
- [ ] **APNs 推送**:离线设备收「收到文件」通知(需 D2 的 `.p8`)。
- [ ] **Share Extension**:别的 app 分享 → 选 Commilitia Drop → 唤起主 app 选设备发送。
- [ ] **控制中心剪贴板两控件**:控制中心加「上传 / 拉取剪贴板」控件 → 锁屏 / 解锁态点按 → 云剪贴板读写。
+11
View File
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<!-- 与主 app 共享的 App GroupShare Extension 把待发文件搬进收件箱(见 AppGroup.swift)。 -->
<key>com.apple.security.application-groups</key>
<array>
<string>group.net.commilitia.cdrop</string>
</array>
</dict>
</plist>
+43
View File
@@ -0,0 +1,43 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>$(DEVELOPMENT_LANGUAGE)</string>
<key>CFBundleDisplayName</key>
<string>Commilitia Drop</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>$(PRODUCT_NAME)</string>
<key>CFBundlePackageType</key>
<string>XPC!</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleVersion</key>
<string>1</string>
<key>NSExtension</key>
<dict>
<key>NSExtensionAttributes</key>
<dict>
<key>NSExtensionActivationRule</key>
<dict>
<key>NSExtensionActivationSupportsFileWithMaxCount</key>
<integer>20</integer>
<key>NSExtensionActivationSupportsImageWithMaxCount</key>
<integer>20</integer>
<key>NSExtensionActivationSupportsMovieWithMaxCount</key>
<integer>20</integer>
</dict>
</dict>
<key>NSExtensionPointIdentifier</key>
<string>com.apple.share-services</string>
<key>NSExtensionPrincipalClass</key>
<string>$(PRODUCT_MODULE_NAME).ShareViewController</string>
</dict>
</dict>
</plist>
+77
View File
@@ -0,0 +1,77 @@
import UIKit
import UniformTypeIdentifiers
// Share Extension share sheet App Group app
// 120MB jetsam PLAN §I5 compose UI
//
final class ShareViewController: UIViewController
{
override func viewDidAppear(_ animated: Bool)
{
super.viewDidAppear(animated)
Task { await processAndClose() }
}
private func processAndClose() async
{
let items = (extensionContext?.inputItems as? [NSExtensionItem]) ?? []
var staged = 0
for item in items
{
for provider in item.attachments ?? []
{
if await stage(provider) { staged += 1 }
}
}
let ctx = extensionContext
guard staged > 0, let url = URL(string: "cdrop://share") else
{
ctx?.completeRequest(returningItems: nil)
return
}
// app open completeRequest completeRequest
// self open openViaResponder L8 ctx 使
//
ctx?.open(url)
{ [weak self] ok in
if !ok { self?.openViaResponder(url) }
ctx?.completeRequest(returningItems: nil)
}
}
// App Group loadFileRepresentation
// / /
//
private func stage(_ provider: NSItemProvider) async -> Bool
{
return await withCheckedContinuation
{ cont in
provider.loadFileRepresentation(forTypeIdentifier: UTType.item.identifier)
{ url, _ in
guard let url, let dest = AppGroup.stagedDestination(originalName: url.lastPathComponent)
else { cont.resume(returning: false); return }
do
{
try FileManager.default.copyItem(at: url, to: dest)
cont.resume(returning: true)
}
catch
{
cont.resume(returning: false)
}
}
}
}
// open 沿 UIApplication app open
private func openViaResponder(_ url: URL)
{
var responder: UIResponder? = self
let sel = NSSelectorFromString("openURL:")
while let r = responder
{
if r.responds(to: sel) { _ = r.perform(sel, with: url); return }
responder = r.next
}
}
}
+66
View File
@@ -0,0 +1,66 @@
import Foundation
// App Group app Share Extension
// 120MB jetsam PLAN §I5 / D target xcodegen
// target
//
// <uuid>
// /
enum AppGroup
{
static let identifier = "group.net.commilitia.cdrop"
// App Group nil
static func inboxURL() -> URL?
{
guard let base = FileManager.default.containerURL(forSecurityApplicationGroupIdentifier: identifier)
else { return nil }
let inbox = base.appendingPathComponent("SharedInbox", isDirectory: true)
try? FileManager.default.createDirectory(at: inbox, withIntermediateDirectories: true)
return inbox
}
// URL<inbox>/<uuid>/<originalName>
static func stagedDestination(originalName: String) -> URL?
{
guard let inbox = inboxURL() else { return nil }
let dir = inbox.appendingPathComponent(UUID().uuidString, isDirectory: true)
try? FileManager.default.createDirectory(at: dir, withIntermediateDirectories: true)
let safeName = originalName.isEmpty ? "file" : originalName
return dir.appendingPathComponent(safeName)
}
// app remove
static func inboxFiles() -> [URL]
{
guard let inbox = inboxURL() else { return [] }
let dirs = (try? FileManager.default.contentsOfDirectory(at: inbox, includingPropertiesForKeys: nil)) ?? []
return dirs.compactMap
{ dir in
guard dir.hasDirectoryPath else { return nil }
let inner = (try? FileManager.default.contentsOfDirectory(at: dir, includingPropertiesForKeys: nil)) ?? []
return inner.first { !$0.hasDirectoryPath }
}
}
// / <uuid>
static func removeStaged(_ fileURL: URL)
{
try? FileManager.default.removeItem(at: fileURL.deletingLastPathComponent())
}
//
// 6 app
static func pruneStale(olderThan seconds: TimeInterval = 6 * 60 * 60)
{
guard let inbox = inboxURL() else { return }
let dirs = (try? FileManager.default.contentsOfDirectory(
at: inbox, includingPropertiesForKeys: [ .creationDateKey ])) ?? []
let cutoff = Date().addingTimeInterval(-seconds)
for dir in dirs
{
let created = (try? dir.resourceValues(forKeys: [ .creationDateKey ]).creationDate) ?? .distantPast
if created < cutoff { try? FileManager.default.removeItem(at: dir) }
}
}
}
+28
View File
@@ -0,0 +1,28 @@
import Foundation
// app +
enum CDropAPI
{
// / EngineController.engineURL URL
static let base = "https://drop.commilitia.net"
private static let widgetDeviceIDKey = "cdrop.widget.device_id"
// device_iddev_ + [A-Za-z0-9_-] validDeviceID
// App Group UserDefaults app
static func widgetDeviceID() -> String
{
let defaults = UserDefaults(suiteName: AppGroup.identifier) ?? .standard
if let existing = defaults.string(forKey: widgetDeviceIDKey) { return existing }
let id = "dev_widget" + UUID().uuidString.replacingOccurrences(of: "-", with: "").prefix(16)
defaults.set(id, forKey: widgetDeviceIDKey)
return id
}
// id device_id 使
// UI L2
static func clearWidgetDeviceID()
{
UserDefaults(suiteName: AppGroup.identifier)?.removeObject(forKey: widgetDeviceIDKey)
}
}
@@ -1,8 +1,9 @@
import Foundation
// i18n app bundle <locale>.json web web/scripts/emit-i18n.mjs
// ios/PLAN.md §5退 zh-CN JSON 退
// zh-CN loader locale
// i18n bundle <locale>.json web web/scripts/emit-i18n.mjs
// ios/PLAN.md §5退 zh-CN JSON 退
// zh-CN loader localeShared app / Share Extension /
// target bundle i18n JSONresourceURL 退
enum I18n
{
private static let dict: [String: String] = load()
@@ -39,6 +40,10 @@ enum I18n
?? Bundle.main.url(forResource: loc, withExtension: "json")
}
// localezh-CN / zh-TW / en-US
// APNs 使 UI
static var locale: String { preferredLocale() }
private static func preferredLocale() -> String
{
for lang in Locale.preferredLanguages
+41
View File
@@ -0,0 +1,41 @@
import Foundation
// app /api/auth/device-session
// refresh App Group /api/clipboard
// 401 refresh app
struct WidgetSession: Codable
{
var accessToken: String
var refreshToken: String
let userId: String
}
enum WidgetSessionStore
{
private static func fileURL() -> URL?
{
guard let base = FileManager.default.containerURL(forSecurityApplicationGroupIdentifier: AppGroup.identifier)
else { return nil }
return base.appendingPathComponent("widget_session.json")
}
static func load() -> WidgetSession?
{
guard let url = fileURL(), let data = try? Data(contentsOf: url) else { return nil }
return try? JSONDecoder().decode(WidgetSession.self, from: data)
}
static func save(_ session: WidgetSession)
{
guard let url = fileURL(), let data = try? JSONEncoder().encode(session) else { return }
// .completeFileProtection
// UntilFirstUserAuthentication
try? data.write(to: url, options: [ .atomic, .completeFileProtectionUntilFirstUserAuthentication ])
}
static func clear()
{
guard let url = fileURL() else { return }
try? FileManager.default.removeItem(at: url)
}
}
+11
View File
@@ -0,0 +1,11 @@
// 真机签名配置。仅对 device SDK(iphoneos)生效——模拟器仍走 project.yml base 的 ad-hoc
// 签名(CODE_SIGN_IDENTITY = "-"),无需 Apple 账号即可构建 / 跑模拟器。
//
// 账号特定值(Team ID、各 target 的 profile 名)放在同目录 **gitignore** 的 Local.xcconfig
// 里(公开仓库不留账号标识)。Local.xcconfig 不存在时下面的可选 include 跳过,device 构建会
// 因缺 Team/profile 失败——这正是预期(真机构建须先按 REALDEVICE.md 建好 Local.xcconfig)。
#include? "Local.xcconfig"
CODE_SIGN_STYLE[sdk=iphoneos*] = Manual
CODE_SIGN_IDENTITY[sdk=iphoneos*] = Apple Development
DEVELOPMENT_TEAM[sdk=iphoneos*] = $(CDROP_TEAM_ID)
+35
View File
@@ -0,0 +1,35 @@
import UIKit
// launch UIKit
// APNs SwiftUI App
// @UIApplicationDelegateAdaptor
final class AppDelegate: NSObject, UIApplicationDelegate
{
func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? = nil
) -> Bool
{
// BGContinuedProcessingTask launch handler launch
BackgroundTaskManager.shared.registerOnce()
return true
}
// APNs PushRegistry
func application(
_ application: UIApplication,
didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data
)
{
PushRegistry.shared.didRegister(tokenData: deviceToken)
}
// APNs APNs / / 退线 SSE
func application(
_ application: UIApplication,
didFailToRegisterForRemoteNotificationsWithError error: Error
)
{
// Push
}
}
@@ -0,0 +1,106 @@
import BackgroundTasks
import UIKit
// iOS 26 BGContinuedProcessingTask
// UI AirDrop0>0
// progress 0
//
// R-iOS-3BGContinuedProcessingTask + UI
// WKWebView WebContent JS / WebRTC
// 退R-iOS-1
//
// 线register .main sync 线 actor
final class BackgroundTaskManager
{
static let shared = BackgroundTaskManager()
private init() {}
// Info.plist BGTaskSchedulerPermittedIdentifiers "<prefix>.*"
// false退
private static let prefix = "net.commilitia.Commilitia-Drop.transfer"
private static let wildcard = prefix + ".*"
private var triedRegister = false
private var registerOK = false
private var task: BGContinuedProcessingTask?
private var pendingId: String? // attach 0
private var latestFraction: Double = 0
// launch AppDelegate.didFinishLaunching
func registerOnce()
{
guard !triedRegister else { return }
triedRegister = true
registerOK = BGTaskScheduler.shared.register(
forTaskWithIdentifier: Self.wildcard, using: .main)
{ [weak self] task in
guard let cpt = task as? BGContinuedProcessingTask
else { task.setTaskCompleted(success: false); return }
self?.attach(cpt)
}
}
// activeCount fraction [0, 1]
func sync(activeCount: Int, fraction: Double)
{
latestFraction = fraction
if activeCount > 0
{
if let task { task.progress.completedUnitCount = Int64(fraction * 100) }
else { submitIfForeground() }
}
else
{
finish(success: true)
}
}
private func submitIfForeground()
{
// / / attach
guard registerOK, task == nil, pendingId == nil else { return }
//
guard UIApplication.shared.applicationState != .background else { return }
let id = "\(Self.prefix).\(UUID().uuidString.prefix(8))"
let request = BGContinuedProcessingTaskRequest(
identifier: id, title: t("ios.bg.title"), subtitle: t("ios.bg.subtitle"))
request.strategy = .queue
do
{
try BGTaskScheduler.shared.submit(request)
pendingId = id
}
catch
{
// /
}
}
private func attach(_ task: BGContinuedProcessingTask)
{
pendingId = nil
self.task = task
task.progress.totalUnitCount = 100
task.progress.completedUnitCount = Int64(latestFraction * 100)
task.expirationHandler = { [weak self] in
self?.task?.setTaskCompleted(success: false)
self?.task = nil
}
}
private func finish(success: Bool)
{
if let task
{
task.progress.completedUnitCount = task.progress.totalUnitCount
task.setTaskCompleted(success: success)
self.task = nil
}
if let pendingId
{
BGTaskScheduler.shared.cancel(taskRequestWithIdentifier: pendingId)
self.pendingId = nil
}
}
}
+8
View File
@@ -5,6 +5,7 @@ import SwiftUI
@main
struct CDropApp: App
{
@UIApplicationDelegateAdaptor(AppDelegate.self) private var appDelegate
@State private var auth = AuthManager()
@State private var engine = EngineController()
@@ -47,5 +48,12 @@ struct AppRoot: View
auth.debugSession()
}
}
// Share Extension cdrop://share RootView
// AppRoot 便 / onAppear
.onOpenURL
{ url in
guard url.scheme == "cdrop", url.host == "share" else { return }
engine.loadPendingShares()
}
}
}
+152 -4
View File
@@ -60,6 +60,10 @@ final class EngineController: NSObject
var presenceCount = 0
var lastEngineLog = ""
// JS "ready" APNs
// didRegister ready flushPushRegistration
private var engineReady = false
// / /
var clipboardStatus = ""
var deviceActionStatus = ""
@@ -89,6 +93,7 @@ final class EngineController: NSObject
override init()
{
super.init()
PushRegistry.shared.engine = self
}
// makeWebView WebView __CDROP_BOOT__device_type:"ios"
@@ -126,6 +131,8 @@ final class EngineController: NSObject
wv.load(request)
webView = wv
deviceName = currentDeviceName()
//
PushRegistry.shared.requestAuthorizationAndRegister()
return wv
}
@@ -135,11 +142,19 @@ final class EngineController: NSObject
{
sendCommand("shutdown", payload: [:])
webView = nil
engineReady = false
devices = []
transfers = []
history = []
status = t("ios.engine.disconnected")
deviceName = ""
PushRegistry.shared.reset()
WidgetSessionStore.clear()
// L1访 + outgoing访 /
for (_, url) in outgoing { url.stopAccessingSecurityScopedResource() }
outgoing.removeAll()
// L2 id
CDropAPI.clearWidgetDeviceID()
}
// Documents Files app /
@@ -185,6 +200,24 @@ final class EngineController: NSObject
sendCommand("revokeDevice", payload: [ "name": name ])
}
// APNs PushRegistry.didRegisterready
// + /api/push/apns/register token
func flushPushRegistration()
{
guard engineReady, let token = PushRegistry.shared.deviceTokenHex else { return }
sendCommand("registerPush", payload: [ "token": token, "locale": I18n.locale ])
}
// App Group device_id +
// <> ·
func provisionWidgetSessionIfNeeded()
{
guard engineReady, WidgetSessionStore.load() == nil else { return }
let id = CDropAPI.widgetDeviceID()
let label = t("ios.control.sessionLabel", [ "name": currentDeviceName() ])
sendCommand("provisionWidgetSession", payload: [ "device_id": id, "device_name": label ])
}
// JSwindow.__cdropEngineEvent
func sendCommand(_ name: String, payload: [String: Any])
{
@@ -207,6 +240,48 @@ final class EngineController: NSObject
])
}
// Share Extension App Group cdrop://share
//
var pendingShareFiles: [URL] = []
// pendingShareFiles
func loadPendingShares()
{
AppGroup.pruneStale()
pendingShareFiles = AppGroup.inboxFiles()
}
// App Group move app
// 便 loadPendingShares /
// M1
func sendShares(to device: String)
{
for url in pendingShareFiles
{
if let staged = moveShareToPrivate(url) { sendFile(to: device, fileURL: staged) }
AppGroup.removeStaged(url)
}
pendingShareFiles = []
}
// app
private func moveShareToPrivate(_ url: URL) -> URL?
{
let dir = FileManager.default.temporaryDirectory
.appendingPathComponent("ShareOutbox/\(UUID().uuidString)", isDirectory: true)
try? FileManager.default.createDirectory(at: dir, withIntermediateDirectories: true)
let dest = dir.appendingPathComponent(url.lastPathComponent)
do { try FileManager.default.moveItem(at: url, to: dest); return dest }
catch { return nil }
}
// +
func dismissShares()
{
for url in pendingShareFiles { AppGroup.removeStaged(url) }
pendingShareFiles = []
}
// cdrop-file://<id> URL
// start...Access
private func stageOutgoingFile(_ url: URL) -> String
@@ -278,6 +353,9 @@ extension EngineController: WKScriptMessageHandler
{
case "ready":
status = t("ios.engine.ready")
engineReady = true
flushPushRegistration()
provisionWidgetSessionIfNeeded()
case "probe":
// WebRTC-in-WKWebView arch A R-iOS-3
if let p = payload as? [String: Any]
@@ -300,6 +378,7 @@ extension EngineController: WKScriptMessageHandler
if let p = payload as? [String: Any], let raw = p["active"] as? [Any]
{
transfers = raw.compactMap { ($0 as? [String: Any]).flatMap(Self.parseTransfer) }
syncBackgroundTask()
}
case "transferDone":
// sessionId
@@ -309,6 +388,7 @@ extension EngineController: WKScriptMessageHandler
history.removeAll { $0.sessionId == item.sessionId }
history.insert(item, at: 0)
if history.count > 30 { history.removeLast(history.count - 30) }
syncBackgroundTask()
}
case "sendStarted":
// transfers
@@ -362,6 +442,15 @@ extension EngineController: WKScriptMessageHandler
{
auth?.updateSession(accessToken: access, refreshToken: refresh)
}
case "widgetSession":
// App Group /
if let p = payload as? [String: Any],
let access = p["access_token"] as? String,
let refresh = p["refresh_token"] as? String,
let userId = p["user_id"] as? String
{
WidgetSessionStore.save(WidgetSession(accessToken: access, refreshToken: refresh, userId: userId))
}
case "authExpired":
// refresh / Keychain
auth?.logout()
@@ -375,6 +464,16 @@ extension EngineController: WKScriptMessageHandler
{
webView?.evaluateJavaScript("window.__cdropEngineResolve(\(id), \(ok), \(jsonValue(value)));")
}
// transfers history
// BackgroundTaskManager / / R-iOS-1 / R-iOS-3
private func syncBackgroundTask()
{
let total = transfers.reduce(0) { $0 + $1.fileSize }
let done = transfers.reduce(0) { $0 + ($1.bytesTransferred ?? 0) }
let fraction = total > 0 ? Double(done) / Double(total) : 0
BackgroundTaskManager.shared.sync(activeCount: transfers.count, fraction: fraction)
}
}
// MARK: - schemecdrop-file
@@ -382,8 +481,9 @@ extension EngineController: WKScriptMessageHandler
extension EngineController: WKURLSchemeHandler
{
// cdrop-file://<id> JS fetch
// PLAN §2 / R-iOS-4v1 /
// didReceive jetsam R-iOS-4
// PLAN §2 / R-iOS-4rangeSource `Range` seek
// 206 Partial Content jetsam Range
// 退 Range
func webView(_ webView: WKWebView, start urlSchemeTask: any WKURLSchemeTask)
{
guard let url = urlSchemeTask.request.url, let id = url.host, let fileURL = outgoing[id]
@@ -392,16 +492,48 @@ extension EngineController: WKURLSchemeHandler
respond(urlSchemeTask, status: 404)
return
}
guard let data = try? Data(contentsOf: fileURL)
guard let attrs = try? FileManager.default.attributesOfItem(atPath: fileURL.path),
let total = attrs[.size] as? Int,
let handle = try? FileHandle(forReadingFrom: fileURL)
else
{
respond(urlSchemeTask, status: 404)
return
}
defer { try? handle.close() }
if let range = Self.parseByteRange(urlSchemeTask.request.value(forHTTPHeaderField: "Range"), total: total)
{
let data: Data
do
{
try handle.seek(toOffset: UInt64(range.lowerBound))
data = (try handle.read(upToCount: range.count)) ?? Data()
}
catch
{
respond(urlSchemeTask, status: 500)
return
}
let resp = HTTPURLResponse(url: url, statusCode: 206, httpVersion: "HTTP/1.1",
headerFields: [
"Content-Type": "application/octet-stream",
"Content-Length": "\(data.count)",
"Content-Range": "bytes \(range.lowerBound)-\(range.upperBound - 1)/\(total)",
"Accept-Ranges": "bytes",
])!
urlSchemeTask.didReceive(resp)
urlSchemeTask.didReceive(data)
urlSchemeTask.didFinish()
return
}
let data = (try? handle.readToEnd()) ?? Data()
let resp = HTTPURLResponse(url: url, statusCode: 200, httpVersion: "HTTP/1.1",
headerFields: [
"Content-Type": "application/octet-stream",
"Content-Length": "\(data.count)",
"Accept-Ranges": "bytes",
])!
urlSchemeTask.didReceive(resp)
urlSchemeTask.didReceive(data)
@@ -410,7 +542,23 @@ extension EngineController: WKURLSchemeHandler
func webView(_ webView: WKWebView, stop urlSchemeTask: any WKURLSchemeTask)
{
// v1
// read
}
// HTTP `Range: bytes=start-end`end [lowerBound, upperBound)
// end "bytes=start-" EOF / nil
static func parseByteRange(_ header: String?, total: Int) -> Range<Int>?
{
guard let header, header.hasPrefix("bytes="), total > 0 else { return nil }
let spec = header.dropFirst("bytes=".count)
let parts = spec.split(separator: "-", maxSplits: 1, omittingEmptySubsequences: false)
guard parts.count == 2, let start = Int(parts[0]), start >= 0, start < total else { return nil }
let endInclusive: Int
if parts[1].isEmpty { endInclusive = total - 1 }
else if let e = Int(parts[1]) { endInclusive = min(e, total - 1) }
else { return nil }
guard endInclusive >= start else { return nil }
return start ..< (endInclusive + 1)
}
private func respond(_ task: any WKURLSchemeTask, status: Int)
+19
View File
@@ -2,6 +2,10 @@
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>BGTaskSchedulerPermittedIdentifiers</key>
<array>
<string>net.commilitia.Commilitia-Drop.transfer.*</string>
</array>
<key>CFBundleDevelopmentRegion</key>
<string>zh-Hans</string>
<key>CFBundleDisplayName</key>
@@ -24,6 +28,17 @@
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleURLName</key>
<string>net.commilitia.Commilitia-Drop</string>
<key>CFBundleURLSchemes</key>
<array>
<string>cdrop</string>
</array>
</dict>
</array>
<key>CFBundleVersion</key>
<string>1</string>
<key>LSSupportsOpeningDocumentsInPlace</key>
@@ -41,6 +56,10 @@
<string>Commilitia Drop 使用相机扫描二维码登录新设备。</string>
<key>NSLocalNetworkUsageDescription</key>
<string>Commilitia Drop 需要访问本地网络以发现同内网设备并建立直连传输。</string>
<key>UIBackgroundModes</key>
<array>
<string>remote-notification</string>
</array>
<key>UIFileSharingEnabled</key>
<true/>
<key>UILaunchScreen</key>
+60
View File
@@ -0,0 +1,60 @@
import UIKit
import UserNotifications
// APNs AppDelegate UIKit EngineController
// token POST /api/push/apns/register
// / token
//
// / Push Notifications aps-environment entitlement
// ADP profile .p8iOS 16+ / Apple Silicon
// `simctl push`
@MainActor
final class PushRegistry: NSObject
{
static let shared = PushRegistry()
private override init() { super.init() }
weak var engine: EngineController?
private(set) var deviceTokenHex: String?
private var requested = false
// AppDelegate didRegister
//
func requestAuthorizationAndRegister()
{
guard !requested else { return }
requested = true
UNUserNotificationCenter.current().delegate = self
UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .sound, .badge])
{ granted, _ in
guard granted else { return }
Task { @MainActor in UIApplication.shared.registerForRemoteNotifications() }
}
}
// AppDelegate 线APNs Data
func didRegister(tokenData: Data)
{
deviceTokenHex = tokenData.map { String(format: "%02x", $0) }.joined()
engine?.flushPushRegistration()
}
// /
func reset()
{
requested = false
deviceTokenHex = nil
}
}
extension PushRegistry: UNUserNotificationCenterDelegate
{
// +
func userNotificationCenter(
_ center: UNUserNotificationCenter,
willPresent notification: UNNotification
) async -> UNNotificationPresentationOptions
{
return [ .banner, .sound ]
}
}
+7 -1
View File
@@ -354,5 +354,11 @@
"ios.files.empty": "No files received yet",
"ios.files.share": "Share",
"ios.files.done": "Done",
"ios.detail.openFile": "Open File"
"ios.detail.openFile": "Open File",
"ios.bg.title": "Transferring files",
"ios.bg.subtitle": "Continues in the background",
"ios.share.title": "Send {{n}} file(s) to a device",
"ios.control.upload": "Upload Clipboard",
"ios.control.pull": "Pull Clipboard",
"ios.control.sessionLabel": "{{name}} · Control"
}
+7 -1
View File
@@ -354,5 +354,11 @@
"ios.files.empty": "还没有收到文件",
"ios.files.share": "分享",
"ios.files.done": "完成",
"ios.detail.openFile": "打开文件"
"ios.detail.openFile": "打开文件",
"ios.bg.title": "正在传输文件",
"ios.bg.subtitle": "切到后台仍继续传输",
"ios.share.title": "发送 {{n}} 个文件到设备",
"ios.control.upload": "上传剪贴板",
"ios.control.pull": "拉取剪贴板",
"ios.control.sessionLabel": "{{name}} · 控件"
}
+7 -1
View File
@@ -354,5 +354,11 @@
"ios.files.empty": "尚未收到檔案",
"ios.files.share": "分享",
"ios.files.done": "完成",
"ios.detail.openFile": "開啟檔案"
"ios.detail.openFile": "開啟檔案",
"ios.bg.title": "正在傳輸檔案",
"ios.bg.subtitle": "切到背景仍繼續傳輸",
"ios.share.title": "傳送 {{n}} 個檔案到裝置",
"ios.control.upload": "上傳剪貼簿",
"ios.control.pull": "拉取剪貼簿",
"ios.control.sessionLabel": "{{name}} · 控制項"
}
+17
View File
@@ -54,6 +54,23 @@ struct RootView: View
.opacity(0)
.allowsHitTesting(false)
}
// Share Extension cdrop://share
.onAppear { engine.loadPendingShares() }
.confirmationDialog(
t("ios.share.title", [ "n": String(engine.pendingShareFiles.count) ]),
isPresented: Binding(
get: { !engine.pendingShareFiles.isEmpty },
set: { if !$0 { engine.dismissShares() } }
),
titleVisibility: .visible
)
{
ForEach(engine.sendableDevices())
{ dev in
Button(dev.name) { engine.sendShares(to: dev.name) }
}
Button(t("common.cancel"), role: .cancel) { engine.dismissShares() }
}
}
}
+19 -8
View File
@@ -1,11 +1,22 @@
# cdrop iOS 待办(择期处理)
# cdrop iOS 待办
2026-06-24 记录:扫码登录端到端验通后用户列出,留待后续处理(“A”任务覆盖的数据侧除外)。
## 计划主体(I1I7):已实现(2026-06-27
1. **登录会话显示修复**(未做):iOS 客户端在(web)“登录会话”列表中误显示为“本地账号”,应按 device_type 显示“iOS 客户端”(`deviceType.ios`)。疑似列表按会话 kind(self / 扫码自签)而非设备类型贴标签——需让扫码自签会话也带 device_type 标签呈现
2. **设备 / session 管理非空壳**(数据侧已做,管理操作未做):列表数据已由“A”接真实 presence(`DeviceListView``engine.devices`)。剩余:会话管理操作(查看 / 吊销其他会话等)。
3. **禁止临时登录**(未做):iOS app 不应允许 guest / 临时(once)登录;扫码登录应强制 full / persist(“信任此设备”)scope。当前后端 qr 默认 guest、`AuthManager` 也写死 `scope: "guest"`——需 iOS 侧走 full。
4. **退出登录**(已做):设置页“账户”区已加登出(destructive),清 Keychain 会话 + 复位引擎 + 回登录页(`SettingsView.logout``auth.logout()` + `engine.reset()`)。
5. **传输详情**(已做):`TransferDetailView` 按 sessionId 实时查引擎态,展示方向 / 对端 / 状态 / 阶段 / 通道 / 大小 / 进度 / 速度;卡片可点入。剩余可选:ICE 候选明细(`transfer.debug.*` catalog 已有,未接)。
传输(含发送端流式 R-iOS-4)/ 设备 + 会话管理 / 强制 full 登录 / 登出 / 传输详情 / 后台续传(BGContinuedProcessingTask/ APNs(后端 + 原生注册)/ Share Extension / 控制中心剪贴板两控件——全部落地、模拟器验、经 ultracode 审查修讫。详见 `ios/PLAN.md` 里程碑 + `ios/PARITY.md` 漂移日志
> **A 已完成**:引擎 presence / 传输 → 原生 UI 数据绑定(三屏全替 demo+ `TransferDetailView` + Keychain 会话持久化 + 登出 + i18n 插值。闭合 #4 / #5 与 #2 数据侧;prod 已部署 `engine.html`presence 生效)。**剩余择期**#1device_type 标签)、#3(强制 full 登录)、#2 会话管理操作、#5 ICE 明细(可选)。全部仍未提交(按用户序:真机测完再 commit)。
## 早期 5 项(2026-06-24 列)状态
1. **登录会话列表显示**:iOS 设备在(web)「登录会话」列表的标签——broker 迁移后 sessions 已按设备 cache 叠加 typedevice-session 铸入 `device_type:"ios"`),**疑已解决,待真会话核**。
2. 设备 / 会话管理:✅(设备页吊销 + 后端 list/revoke/rename)。
3. 强制 full 登录:✅(iOS 拒非 full + 后端对非 browser 兜底 full/persist)。
4. 登出:✅。
5. 传输详情:✅(`TransferDetailView`;可选 ICE 明细已接)。
## 真机阶段(账号门控,见 REALDEVICE.md
真机签名跑通 + 同内网直连 / 本地网络权限(R-iOS-6)+ 后台挂起行为(R-iOS-3+ APNs 真发 + Share Extension / 控件真机交互验证。代码就绪,等付费 ADP + 门户 + 设备。
## 余项(择期)
- 控件「添加控件」库名 + Shortcuts 标题随设备语言(需为 `CDropWidgets``.xcstrings`;当前简体静态,审查 L7,平台专属可接受)。
- 发送端 `outgoing` 暂存 + 安全作用域访问按传输完成逐项释放(当前登出统一清,审查 L1 余量)。
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<!-- 与主 app 共享的 App Group:控件读取 widget_session.json(主 app 代铸的控件会话)。 -->
<key>com.apple.security.application-groups</key>
<array>
<string>group.net.commilitia.cdrop</string>
</array>
</dict>
</plist>
+89
View File
@@ -0,0 +1,89 @@
import Foundation
// WidgetSessionStore
// /api/clipboard access 401 /api/auth/refresh
// app RESTPLAN §I4使
// refresh
enum ClipboardClient
{
enum ClientError: Error { case noSession, http(Int) }
// PUT /api/clipboard
static func upload(_ text: String) async throws
{
let body = try JSONSerialization.data(withJSONObject: [
"content": text,
"content_type": "text/plain",
"origin_ts": Int(Date().timeIntervalSince1970 * 1000),
])
_ = try await authed(method: "PUT", path: "/api/clipboard", body: body)
}
// GET /api/clipboard
static func pull() async throws -> String
{
let data = try await authed(method: "GET", path: "/api/clipboard", body: nil)
let obj = try? JSONSerialization.jsonObject(with: data) as? [String: Any]
return (obj?["content"] as? String) ?? ""
}
// + 401
private static func authed(method: String, path: String, body: Data?) async throws -> Data
{
guard var session = WidgetSessionStore.load() else { throw ClientError.noSession }
do
{
return try await send(method: method, path: path, body: body, token: session.accessToken)
}
catch ClientError.http(401)
{
session = try await refresh(session)
WidgetSessionStore.save(session)
return try await send(method: method, path: path, body: body, token: session.accessToken)
}
}
private static func send(method: String, path: String, body: Data?, token: String) async throws -> Data
{
var req = URLRequest(url: URL(string: CDropAPI.base + path)!)
req.httpMethod = method
req.setValue("Bearer \(token)", forHTTPHeaderField: "Authorization")
if let body
{
req.httpBody = body
req.setValue("application/json", forHTTPHeaderField: "Content-Type")
}
let (data, resp) = try await URLSession.shared.data(for: req)
let code = (resp as? HTTPURLResponse)?.statusCode ?? 0
// 200 409PUT LWW 401
guard code == 200 || code == 409 else { throw ClientError.http(code) }
return data
}
private static func refresh(_ session: WidgetSession) async throws -> WidgetSession
{
let body = try JSONSerialization.data(withJSONObject: [ "refresh_token": session.refreshToken ])
var req = URLRequest(url: URL(string: CDropAPI.base + "/api/auth/refresh")!)
req.httpMethod = "POST"
req.httpBody = body
req.setValue("application/json", forHTTPHeaderField: "Content-Type")
let (data, resp) = try await URLSession.shared.data(for: req)
let code = (resp as? HTTPURLResponse)?.statusCode ?? 0
guard code == 200,
let obj = try? JSONSerialization.jsonObject(with: data) as? [String: Any],
let access = obj["access_token"] as? String
else
{
// refresh / app
// CAS-before-clear refresh
// intent L3
if WidgetSessionStore.load()?.refreshToken == session.refreshToken
{
WidgetSessionStore.clear()
}
throw ClientError.http(401)
}
let newRefresh = (obj["refresh_token"] as? String) ?? session.refreshToken
return WidgetSession(accessToken: access, refreshToken: newRefresh, userId: session.userId)
}
}
+45
View File
@@ -0,0 +1,45 @@
import AppIntents
import SwiftUI
import WidgetKit
// iOS 18+ ControlWidgetPLAN C / §I4 /
// t() i18n bundle
@main
struct CDropWidgetBundle: WidgetBundle
{
var body: some Widget
{
UploadClipboardControl()
PullClipboardControl()
}
}
struct UploadClipboardControl: ControlWidget
{
var body: some ControlWidgetConfiguration
{
StaticControlConfiguration(kind: "net.commilitia.cdrop.control.upload")
{
ControlWidgetButton(action: UploadClipboardIntent())
{
Label(t("ios.control.upload"), systemImage: "square.and.arrow.up")
}
}
.displayName("上传剪贴板")
}
}
struct PullClipboardControl: ControlWidget
{
var body: some ControlWidgetConfiguration
{
StaticControlConfiguration(kind: "net.commilitia.cdrop.control.pull")
{
ControlWidgetButton(action: PullClipboardIntent())
{
Label(t("ios.control.pull"), systemImage: "square.and.arrow.down")
}
}
.displayName("拉取剪贴板")
}
}
+32
View File
@@ -0,0 +1,32 @@
import AppIntents
import UIKit
//
struct UploadClipboardIntent: AppIntent
{
static var title: LocalizedStringResource = "上传剪贴板"
static var description = IntentDescription("把本机剪贴板内容上传到 Commilitia Drop 云剪贴板")
func perform() async throws -> some IntentResult
{
let text = await MainActor.run { UIPasteboard.general.string ?? "" }
if !text.isEmpty { try? await ClipboardClient.upload(text) }
return .result()
}
}
//
struct PullClipboardIntent: AppIntent
{
static var title: LocalizedStringResource = "拉取剪贴板"
static var description = IntentDescription("把 Commilitia Drop 云剪贴板内容写入本机剪贴板")
func perform() async throws -> some IntentResult
{
if let text = try? await ClipboardClient.pull(), !text.isEmpty
{
await MainActor.run { UIPasteboard.general.string = text }
}
return .result()
}
}
+29
View File
@@ -0,0 +1,29 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>$(DEVELOPMENT_LANGUAGE)</string>
<key>CFBundleDisplayName</key>
<string>Commilitia Drop</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>$(PRODUCT_NAME)</string>
<key>CFBundlePackageType</key>
<string>XPC!</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleVersion</key>
<string>1</string>
<key>NSExtension</key>
<dict>
<key>NSExtensionPointIdentifier</key>
<string>com.apple.widgetkit-extension</string>
</dict>
</dict>
</plist>
+88 -2
View File
@@ -7,19 +7,37 @@ options:
settings:
base:
SWIFT_VERSION: "5.0"
CODE_SIGNING_ALLOWED: "NO"
# 模拟器用 ad-hoc 签名(身份 "-",无需 Apple 账号),使 App Group / Push 等 entitlement 在
# 模拟器实际生效(否则共享容器不创建、远程通知注册失败)。真机签名须付费 ADP 配
# team / provisioning profile(账号门控,见 REALDEVICE.md)。
CODE_SIGN_IDENTITY: "-"
CODE_SIGNING_REQUIRED: "NO"
CODE_SIGNING_ALLOWED: "YES"
targets:
CDrop:
type: application
platform: iOS
deploymentTarget: "26.0"
configFiles:
Debug: Signing.xcconfig
Release: Signing.xcconfig
sources:
- path: Sources
- path: Shared
dependencies:
- target: CDropShare
embed: true
- target: CDropWidgets
embed: true
info:
path: Sources/Info.plist
properties:
CFBundleDisplayName: Commilitia Drop
# cdrop:// URL schemeShare Extension 交接后经 cdrop://share 深链唤起主 app 选设备发送。
CFBundleURLTypes:
- CFBundleURLName: net.commilitia.Commilitia-Drop
CFBundleURLSchemes:
- cdrop
# 声明支持的语言,使系统控件(EditButton 的「编辑」、滑动删除的「删除」等系统字符
# 串)跟随设备语言本地化,而非永远英文。开发区域设简体。
CFBundleDevelopmentRegion: zh-Hans
@@ -28,6 +46,13 @@ targets:
- zh-Hant
- en
UILaunchScreen: {}
# 后台续传:BGContinuedProcessingTask 的通配标识符须在此声明,系统才允许注册 / 提交
# (见 BackgroundTaskManager)。默认资源(CPU + 网络)无需额外 entitlement。
BGTaskSchedulerPermittedIdentifiers:
- "net.commilitia.Commilitia-Drop.transfer.*"
# 远程通知后台模式:APNs 推送送达 / 后台处理(如「收到文件」通知)。
UIBackgroundModes:
- remote-notification
# 让接收文件落地的 Documents 目录在 Files app「我的 iPhone / Commilitia Drop」下
# 可见、可就地打开(收到的文件有处可开、可被其他 app 取用)。
UIFileSharingEnabled: true
@@ -40,9 +65,70 @@ targets:
NSCameraUsageDescription: "Commilitia Drop 使用相机扫描二维码登录新设备。"
settings:
base:
PRODUCT_BUNDLE_IDENTIFIER: net.commilitia.cdrop
PRODUCT_BUNDLE_IDENTIFIER: net.commilitia.Commilitia-Drop
TARGETED_DEVICE_FAMILY: "1,2"
ASSETCATALOG_COMPILER_APPICON_NAME: AppIcon
# APNs 推送的 aps-environment entitlement(见 CDrop.entitlements)。模拟器取令牌可用;
# 真机签名须付费 ADP 开 Push 能力(账号门控)。
CODE_SIGN_ENTITLEMENTS: CDrop.entitlements
# 真机:用门户 profile 手动签名(仅 device SDK;模拟器走 base ad-hoc)。profile 名取自
# gitignore 的 Local.xcconfig(见 Signing.xcconfig / REALDEVICE.md)。
"PROVISIONING_PROFILE_SPECIFIER[sdk=iphoneos*]": "$(CDROP_PROFILE_APP)"
# Share Extension:抓分享文件 → App Group 收件箱 → 深链主 app 选设备发送(只交接、不跑引擎,
# 见 PLAN §I5)。只编 ShareViewController + 共享的 AppGroup,绝不拉主 app Sources(避超 120MB)。
CDropShare:
type: app-extension
platform: iOS
deploymentTarget: "26.0"
configFiles:
Debug: Signing.xcconfig
Release: Signing.xcconfig
sources:
- path: Share
- path: Shared
info:
path: Share/Info.plist
properties:
CFBundleDisplayName: Commilitia Drop
NSExtension:
NSExtensionPointIdentifier: com.apple.share-services
NSExtensionPrincipalClass: $(PRODUCT_MODULE_NAME).ShareViewController
NSExtensionAttributes:
NSExtensionActivationRule:
NSExtensionActivationSupportsFileWithMaxCount: 20
NSExtensionActivationSupportsImageWithMaxCount: 20
NSExtensionActivationSupportsMovieWithMaxCount: 20
settings:
base:
PRODUCT_BUNDLE_IDENTIFIER: net.commilitia.Commilitia-Drop.share
TARGETED_DEVICE_FAMILY: "1,2"
CODE_SIGN_ENTITLEMENTS: Share/CDropShare.entitlements
"PROVISIONING_PROFILE_SPECIFIER[sdk=iphoneos*]": "$(CDROP_PROFILE_SHARE)"
# 控制中心剪贴板两控件(WidgetKit ControlWidgetiOS 18+PLAN §I4)。纯原生 REST + 控件专用
# 设备会话(不跑引擎)。i18n JSON 一并打包使控件标签随设备语言(t() 经 no-subdir 回退读 bundle)。
CDropWidgets:
type: app-extension
platform: iOS
deploymentTarget: "26.0"
configFiles:
Debug: Signing.xcconfig
Release: Signing.xcconfig
sources:
- path: Widgets
- path: Shared
- path: Sources/Resources/i18n
info:
path: Widgets/Info.plist
properties:
CFBundleDisplayName: Commilitia Drop
NSExtension:
NSExtensionPointIdentifier: com.apple.widgetkit-extension
settings:
base:
PRODUCT_BUNDLE_IDENTIFIER: net.commilitia.Commilitia-Drop.widgets
TARGETED_DEVICE_FAMILY: "1,2"
CODE_SIGN_ENTITLEMENTS: Widgets/CDropWidgets.entitlements
"PROVISIONING_PROFILE_SPECIFIER[sdk=iphoneos*]": "$(CDROP_PROFILE_WIDGETS)"
schemes:
CDrop:
build:
+2
View File
@@ -33,6 +33,7 @@
- **导航外壳**:原生 `NavigationStack` / `TabView` vs web 布局。
- **字体 / 排版**:系统字体 + Dynamic Type vs Orbit Gothic / Noto;间距 / 圆角 / 字阶各用平台母语。
- **平台专属**:控制中心控件、Share Extension(仅 iOS);Web Push 订阅 UI、桌面设置区块(非 iOS)。
- **控制中心控件标签**:运行时控件标签(用户点按的那个)经 `t()` 跟随设备语言;但「添加控件」库名 + Shortcuts 标题是 `LocalizedStringResource` 静态值、`CDropWidgets` target 无 String Catalog,故对 en / zh-TW 用户回退简体字面量(审查 L7,平台专属功能可接受分叉;要彻底本地化须为 Widgets target 加 `.xcstrings`)。
---
@@ -58,3 +59,4 @@
| 2026-06-24 | i18n locales + scripts/emit-i18n.mjs(未提交) | ios/CDrop i18n(未提交) | **强约束②落地**web locales 加 `ios.*` 键 → `emit-i18n.mjs` 产出 JSON → iOS `t()` 读(loader I18n.swift)。用户可见**去代号 cdrop**(品牌用 `app.brand`=Commilitia Drop),显示名改 Commilitia Drop。**改 locale 后须重跑 `node web/scripts/emit-i18n.mjs`**(已记入脚本头) |
| 2026-06-24 | engine/main.ts 加 presence 推送 + 初始快照(未提交) | RootView / EngineController / AuthManager 真数据绑定(未提交) | **A 任务**:引擎订阅 `store.devices``presence` 事件 + boot 后补发 presence/transfers 初始快照;原生 `EngineController` 解码进 `@Observable` devices/transfers/history`RootView` 三屏全替 demo→真数据 + 新增 `TransferDetailView`TODO #5)。i18n 加 `ios.detail.*` / `ios.settings.account|user|logout` / `ios.transfer.empty|incoming|outgoing` / `ios.send.noDevices` / `ios.devices.empty`,传输态文案复用共享 `transfer.state|phase|mode|bytesRate`。iOS `t()``{{name}}` 插值变体对齐 web。Keychain 会话持久化 + 设置页登出(闭合 TODO #4)。web tsc/build + xcodebuild iphonesimulator26.5 双过,模拟器三屏空态截图验。**已部署 prod**:`engine.html``engine-BB8iav7K.js`(含 presence 推送),真会话下即生效 |
| 2026-06-24 | engine/main.tstransfers 推送节流 ~3Hz + toWire 加 ice 摘要(未提交,**待部署** | EngineController 手动容忍解析 + ICE 字段;RootView 详情页 ICE 行 + 收到文件视图 + 设备名编辑 + 设备计数;DownloadManager listFiles/delete;新 DeviceNameStore / QuickLookPreviewproject.yml 加文件共享键 + 品牌化权限串(未提交) | **首轮真机测试反馈修复**:① 速度数字 ~10Hz 闪 → 节流活跃传输推送到 3Hz(iOS-only,亦降 P2P 接收主线程抖动);② 设备列表空 → 原生改手动容忍解析(严格 JSONDecoder 遇 bool/int 失配整组失败的隐患),加「已知设备」计数诊断;③ 收到文件无处开 / Files 不可见 / 阻塞发送 → `UIFileSharingEnabled`+`LSSupportsOpeningDocumentsInPlace`Documents 已是落地目录)+ 应用内「收到的文件」视图(QuickLook 预览 / 系统分享 / 转发在线设备 / 删除);④ 设备名不可改 → `DeviceNameStore`UserDefaults)+ 设置页编辑框(后端令牌烤名、改名下次登录生效);⑤ P2P <100KB/srelay 1MB/s)→ 详情页暴露选中 ICE 候选对诊断是否 TURN 中继(不盲改共享 p2p.ts 水位)。i18n 加 `ios.files.*`/`ios.settings.deviceName|deviceNameNote|deviceCount`ICE 行复用 `transfer.debug.*`。web 双过 + xcodebuild 编过 + 模拟器设置 / 传输屏截图验。**已部署 prod**:`engine.html``engine-BC6mZ9zP.js`(含节流 + ice 摘要) |
| 2026-06-27 | source.ts(新 FileSource+ p2p/relay/transfer 改 src + engine/main.ts 加 registerPush/provisionWidgetSession + i18n 加 `ios.bg.*`/`ios.share.*`/`ios.control.*`(本提交) | 新 BackgroundTaskManager / AppDelegate / PushRegistry / Shared(AppGroup,I18n,CDropAPI,WidgetSession) / Share(ShareViewController) / Widgets(控件+intents+client)EngineController 加 Range handler / 后台 sync / 分享导入 / 控件代铸;project.yml 加两扩展 target + 真机签名 scaffold;包名改 `net.commilitia.Commilitia-Drop`(本提交) | **计划完成(I3I7**:发送端流式(FileSource + 原生 Range,新增**分享发送 + 控件**两条非引擎流程,对应残余项 1/2)/ 后台续传 / APNs(后端 internal/apns + 原生注册,新后端字段 `push_subscriptions.platform` + 端点 `POST /api/push/apns/register` 对应残余项 3/ Share Extension / 控制中心两控件(新允许分叉:控件标签见上)。经 ultracode 多 agent 审查(0 HIGH,修 2 MED + 7 LOW)。web tsc/build + go build/test + xcodebuild 全过;模拟器验登录 / 分享弹窗 / 控件嵌入 / App Group 容器。**真机 + 真发推送 + 分发账号门控**(见 REALDEVICE.md)。**待部署 prod**engine.html(新桥)+ cdrop binaryAPNs 端点 + platform 列) |
+2
View File
@@ -111,6 +111,8 @@ Share Extension 落法(据上):**抓文件 → 写 App Group 容器 →
| **I6** APNs | 服务端通道(§3)+ 原生注册;不含剪贴板 | `.p8` + 真机硬等账号 |
| **I7** 打磨与分发 | 后台窗口;图标 / 启动屏(复用品牌资产);旁加载分发 | 硬等账号 |
> **实现状态(2026-06-27**I1/I2/I3/I4/I5/I6 的**代码**全部落地——发送端流式(R-iOS-4FileSource + 原生 Range,整文件不进 WebView 内存);后台续传(BGContinuedProcessingTask);APNs(后端 `internal/apns` ES256 + 原生注册经引擎桥);Share ExtensionApp Group 收件箱 + `cdrop://share` 深链);控制中心两控件(**专用 broker 设备会话**,纯原生 REST,不与引擎抢 refresh 轮换)。模拟器验 + ultracode 多 agent 审查修讫(0 HIGH,修 2 MED + 7 LOW)。**I0 账号 / 证书 + 真机签名 / 真发推送 / 旁加载分发**仍账号门控——手册 `ios/CDrop/REALDEVICE.md`(手动签名 + `just ios-device` 全 CLI 装机,门户手动建)。包名 `net.commilitia.Commilitia-Drop`。
---
## 5. 一致性:强约束同步 vs 检查单(决策 D 展开)