Skip to content

feat(ios): LibIOS binding layer (226 funs) + push notifications landed - #60

Open
zendrx wants to merge 1 commit into
mainfrom
ios-libios-push
Open

feat(ios): LibIOS binding layer (226 funs) + push notifications landed#60
zendrx wants to merge 1 commit into
mainfrom
ios-libios-push

Conversation

@zendrx

@zendrx zendrx commented Sep 12, 2026

Copy link
Copy Markdown
Contributor

What this PR does

1. LibIOS — the iOS binding layer (src/native/engine/ios/ios_bindings.cr) — the headline

The framework's iOS branches reference LibIOS.* 225 distinct functions across ~25 files — and none of them were ever written. This PR writes the complete lib LibIOS C-ABI contract:

  • 226 funs, each signature derived from its actual framework call sites (not guessed): widget creators return Void* handles, string getters return borrowed UInt8* released via free_string / free_string_array / free, colors are normalized Float32 components, music time is Float64, sensor/battery/etc. per its usage.
  • Mechanically audited: 225/225 referenced names bound, zero missing, and a call-site arity scan caught and fixed one real conflict (platform#share called share with 2 args while share.cr uses the 6-arg form — platform now passes NULL for absent fields).
  • Documented ABI conventions at the top of the file (handles, string ownership, threading, main-thread callbacks) so the Swift/ObjC libnative_ios dylib can be implemented directly against it.
  • Includes String#to_utf8 (the iOS branches' string convention) in the same file.

2. Push notifications (from the interrupted session)

  • The never-compiled push_notification.c_r from the repo root moved to its rightful place src/native/framework/push_notifications.cr and fixed: null-checked method ids, class-ref cleanup, new handle_token_refresh/on_token_refresh, exception-safe user callbacks (an app exception can no longer unwind through the JNI boundary).
  • Java bridge thread-safety: PushManager/FcmService now post every native callback to the main thread via Handler(Looper.getMainLooper()) — FCM/GMS executor threads were calling into the thread-bound cached JNIEnv (UB). Dead reflection listener removed; null tokens no longer cross JNI.
  • Wired into src/native.cr + require "log"; desktop-path spec coverage added (spec/push_notification_spec.cr); Changelog has an Unreleased section.

3. Note on CI (owner is checking personally — probe step removed)

While auditing I found the platform typecheck jobs pass despite 239→225 LibIOS references existing with no definition — meaning -Dnative_ios/-Dnative_android are likely not activating the flag?(:…) branches and the jobs are desktop compiles in disguise. A temporary probe step was added to ci.yml and is removed in this PR per owner decision. Once this PR merges, a good manual check is: crystal eval -Dnative_ios 'puts {{ flag?(:native_ios) }}' — if that prints false, the -D handling in the installed toolchain needs a look before the iOS branches can be considered genuinely type-checked.

🤖 Co-authored with the repo owner's in-flight batch work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant