5

I have an issue specifying access from SFSafariViewController since it has the exact same user agent as Safari browser.

What i'm trying to do is display a picture only inside the webview and remove it if its viewed on normal browser.

Tried to see if document.refferer can be used and I tried it on twitter since the latest update has its webview changed to SFSafariViewController. Almost worked but the referrer info is also being passed to safari if its opened directly from SFSafariViewController.

Would really appreciate any ideas... thanks!!

dvfend
  • 51
  • 3

2 Answers2

0

I did a bit of quick research on this, and it appears that this is not possible, hence the word Safari in SFSafariViewController.

However you can do this using the WebKit WKWebView: https://developer.apple.com/documentation/webkit/wkwebview/1414950-customuseragent

Leo
  • 172
  • 2
  • 14
0

You can't check the user agent, but there are other detection mechanisms to differentiate sfsafariviewcontroller from safari.

For example, you can check for the existence of an obscure webfont: .Helvetica LT MM.

Here's some example code: https://gist.github.com/aeharding/08eaafbb7742f78ede9b8d2f5d096354

aeharding
  • 486
  • 1
  • 4
  • 13
  • This doesn't seem to work anymore when testing in iOS 16.0.2, the baseline and new text font size are equal, maybe the font was removed or something was fixed here. – Alex Burgos Feb 22 '23 at 15:33