Reputation: 31
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;
Upvotes: 2
Views: 107
Reputation: 3602
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;
Upvotes: 2