Skip to content

Instantly share code, notes, and snippets.

@zzdjk6
Created August 17, 2019 04:29
Show Gist options
  • Save zzdjk6/7d815ca094d6d7c195c8e04da5dcf252 to your computer and use it in GitHub Desktop.
Save zzdjk6/7d815ca094d6d7c195c8e04da5dcf252 to your computer and use it in GitHub Desktop.
WKWebView CORS Solution: sendRequest.js
const sendNativePostRequest = (url, params) => {
return new Promise((resolve, reject) => {
const uuid = uuidv4();
_.set(window, `jsCallbackBridge.promises.${uuid}`, { resolve, reject });
const body = ''; //TODO: construct body
window.webkit.messageHandlers.native.postMessage({
type: 'SEND_HTTP_REQUEST',
url,
body,
method: 'POST',
uuid,
accept: 'application/json',
content_type: 'application/x-www-form-urlencoded; charset=utf-8'
});
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment