Likely you are pasting that in the wrong place ( top level) ??!.
I did not elaborate as you seemed to get the gist of my previous examples for you..
which has similar postMessage handlers.
The code above is doing a similar thing but is using the print code.
This example is on older 12.2 iOS as I am constrained to that build at the min.
But should open ok.
hype
printTest.hype.zip (19.4 KB)
xcode
printTest.zip (437.8 KB)