Skip to content
This repository has been archived by the owner on Jan 10, 2024. It is now read-only.

How to add headers on iOS #47

Open
alonstar opened this issue Aug 23, 2019 · 2 comments
Open

How to add headers on iOS #47

alonstar opened this issue Aug 23, 2019 · 2 comments
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@alonstar
Copy link

I need to add headers & set user-agent in WebView, I used nativescript-webview-utils for this issue before, but if I need to use WebViewExt for handling mailto, how do I add headers or set user-agent when using WebViewExt ?

Thank you.

Nativescript 5.4.0
iOS 11
Angular 7

@m-abs
Copy link
Contributor

m-abs commented Aug 25, 2019

We don't support setting custom headers at the moment, and we don't have plans to add it.
We might accept a PR, if implements the feature for all three platforms (android webview, WKWebView and UIWebView).

I've had a look at nativescript-webview-utils and I don't think we'd want to set custom headers that way.

User-agent should be possible, but requires a little code on your part.

Without having tested it:

if (isAndroid) {
   webview.android.getSettings().setUserAgentString(userAgent);
} else if (isIOS) {
  if (webview.isWKWebView) {
    webview.ios.customUserAgent = userAgent;
  } else if (webview.isUIWebView) {
    // Note: applies to every webview on the app.
    NSUserDefaults.standardUserDefaults.registerDefaults(NSDictionary.dictionaryWithObjectForKey(userAgent, "UserAgent"));
  }
}

If you need to capture mailto-links, you should be able to use shouldOverrideUrlLoading-event.

Again without testing:

webview.on(WebViewExt.shouldOverrideUrlLoading, (args) => {
  if (url.startsWith('mailto:')) {
    // DO STUFF
    args.cancel = true;
  }
});

@m-abs m-abs added enhancement New feature or request help wanted Extra attention is needed labels Aug 29, 2019
@alonstar
Copy link
Author

I got it , thank you 👍

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants