2

I am trying to change the UserAgent with FMX IOS.

I have tried following code in Rad Studio 11.1 but doesn't seem to work?

procedure SetUserAgent;
var
  LUserAgentDict: Pointer;
begin
  LUserAgentDict := TNSDictionary.OCClass.dictionaryWithObject(StrToObjectID('Mozilla/5.0 (X11; CrOS x86_64 10066.0.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.0.0 Safari/537.36'), StrToObjectID('UserAgent'));
  StandardUserDefaults.registerDefaults(TNSDictionary.Wrap(LUserAgentDict));
  //StandardUserDefaults.
end;
Dalija Prasnikar
  • 27,212
  • 44
  • 82
  • 159
Rob
  • 31
  • 4

1 Answers1

2

You could do it this way:

uses
  FMX.WebBrowser, iOSapi.WebKit, Macapi.Helpers;

procedure SetUserAgent(const ABrowser: TWebBrowser);
var
  LWebView: WKWebView;
begin
  if Supports(ABrowser, WKWebView, LWebView) then
    LWebView.setCustomUserAgent(StrToNSStr('Mozilla/5.0 (X11; CrOS x86_64 10066.0.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.0.0 Safari/537.36'));
end;
Dave Nottage
  • 3,411
  • 1
  • 20
  • 57
  • 1
    Thank you so so much, all working now, What a awesome community for development , appreciate it BIG TIME!!! – Rob Aug 28 '22 at 21:22