On macOS 10 however, the process is a little more involved. A method will be appended to window
that allows the response to be delivered there instead. It's not exactly this, but you can visualize the flow
as being something along the lines of:
// add the window method window["_0123456"] = (response) => { // decrypt `response` and deliver the result to the caller here // then remove the temporary method deletewindow["_0123456"] };
// later in swift, the following JavaScript snippet will be executed (() => { window["_0123456"]({ ciphertext: [12, 13, 4], tag: [3, 5, 67, 56] }) })()
A mapping function to call on every element of the array.
(v, k): U
Parameters
v: T
k: number
Returns U
OptionalthisArg: any
Value of 'this' used to invoke the mapfn.
Returns U[]
<T>(iterable): T[]
Creates an array from an iterable object.
Type Parameters
T
Parameters
iterable: Iterable<T> | ArrayLike<T>
An iterable object to convert to an array.
Returns T[]
<T, U>(iterable, mapfn, thisArg?): U[]
Creates an array from an iterable object.
Type Parameters
T
U
Parameters
iterable: Iterable<T> | ArrayLike<T>
An iterable object to convert to an array.
mapfn: ((v, k) => U)
A mapping function to call on every element of the array.
(v, k): U
Parameters
v: T
k: number
Returns U
OptionalthisArg: any
Value of 'this' used to invoke the mapfn.
Returns U[]
JSONparse: ((text, reviver?) => any)
(text, reviver?): any
Converts a JavaScript Object Notation (JSON) string into an object.
Parameters
text: string
A valid JSON string.
Optionalreviver: ((this, key, value) => any)
A function that transforms the results. This function is called for each member of the object.
If a member contains nested objects, the nested objects are transformed before the parent object is.
Adds a property to an object, or modifies attributes of an existing property.
Type Parameters
T
Parameters
o: T
Object on which to add or modify the property. This can be a native JavaScript object (that is, a user-defined object or a built in object) or a DOM object.
p: PropertyKey
The property name.
attributes: PropertyDescriptor & ThisType<any>
Descriptor for the property. It can be for a data property or an accessor property.
Returns T
Promise: PromiseConstructor
TextDecoder: (new (label?, options?) => TextDecoder)
Example
On macOS 11+, this will just call through to
window.webkit.messageHandlers.x.postMessage
Eg: for a
foo
message defined in Swift that accepted the payload{"bar": "baz"}
, the following would occur:Example
On macOS 10 however, the process is a little more involved. A method will be appended to
window
that allows the response to be delivered there instead. It's not exactly this, but you can visualize the flow as being something along the lines of:Implements