iOS: add APNs registration and notification signing config#20308
iOS: add APNs registration and notification signing config#20308
Conversation
| { | ||
| application.registerForRemoteNotifications() |
There was a problem hiding this comment.
Race between APNs callback and appModel wiring
registerForRemoteNotifications() is called in didFinishLaunchingWithOptions (line 15), but appDelegate.appModel is only set later inside a .task modifier (line 52) when the SwiftUI view appears. If didRegisterForRemoteNotificationsWithDeviceToken fires before the view body renders, appModel is still nil and the token is silently dropped via optional chaining (line 21). Since updateAPNsDeviceToken is the only path that persists the token to UserDefaults, a subsequent registerAPNsTokenIfNeeded on gateway connect would also find no token.
In practice, the APNs network round-trip makes this unlikely, but on a warm re-registration (where the OS may have a cached token) it could happen. Consider wiring the appModel in didFinishLaunchingWithOptions instead, or storing the device token in the delegate and forwarding it once appModel is assigned.
Prompt To Fix With AI
This is a comment left during a code review.
Path: apps/ios/Sources/OpenClawApp.swift
Line: 14:15
Comment:
**Race between APNs callback and `appModel` wiring**
`registerForRemoteNotifications()` is called in `didFinishLaunchingWithOptions` (line 15), but `appDelegate.appModel` is only set later inside a `.task` modifier (line 52) when the SwiftUI view appears. If `didRegisterForRemoteNotificationsWithDeviceToken` fires before the view body renders, `appModel` is still `nil` and the token is silently dropped via optional chaining (line 21). Since `updateAPNsDeviceToken` is the only path that persists the token to `UserDefaults`, a subsequent `registerAPNsTokenIfNeeded` on gateway connect would also find no token.
In practice, the APNs network round-trip makes this unlikely, but on a warm re-registration (where the OS may have a cached token) it could happen. Consider wiring the `appModel` in `didFinishLaunchingWithOptions` instead, or storing the device token in the delegate and forwarding it once `appModel` is assigned.
How can I resolve this? If you propose a fix, please make it concise.0c6ba66 to
6141800
Compare
…20308) Merged via /review-pr -> /prepare-pr -> /merge-pr. Prepared head SHA: 6141800 Co-authored-by: mbelinky <[email protected]> Co-authored-by: mbelinky <[email protected]> Reviewed-by: @mbelinky
|
lgtm |
…20308) Merged via /review-pr -> /prepare-pr -> /merge-pr. Prepared head SHA: 6141800 Co-authored-by: mbelinky <[email protected]> Co-authored-by: mbelinky <[email protected]> Reviewed-by: @mbelinky
Summary
Testing
Greptile Summary
This PR adds APNs (Apple Push Notification service) registration to the iOS app, along with signing/entitlements configuration and bundle ID variable alignment for watch targets.
OpenClawAppDelegatethat registers for remote notifications on launch, forwards device tokens toNodeAppModel, which persists them inUserDefaultsand sends apush.apns.registerevent to the gateway on connect. Includes sandbox/production environment detection.OpenClaw.entitlementsfile withaps-environmentcapability, wired inproject.yml.Config/Signing.xcconfig, with corresponding overrides inLocalSigning.xcconfig.example.Info.plistfiles andproject.ymlwith xcconfig variables for signing consistency across all targets.replyHandlercall outside ofTask { @MainActor }inWatchConnectivityReceiver, fixing a potential crash where the reply handler could be called after the system timeout.NSExtensionActivationSupportsMovieWithMaxCount) and addsinfo.propertiesinproject.ymlfor XcodeGen.type_body_lengthlimits to accommodateNodeAppModelgrowth.Confidence Score: 4/5
apps/ios/Sources/OpenClawApp.swift- potential race between APNs token delivery andappModelwiringLast reviewed commit: 0c6ba66