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;
CodePudding user response:
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;
CodePudding user response:
kindly looking for a way to change how my app handles url scheme in FMX when a user clicks a url. Scenario, user clicks a Wikipedia link inside app and the safari in IOS opens up the default app if present Wikipedia to view the link instead of just opening the link in the default browser as a normal link.
link below shows apps can register to have urls open to their apps https://developer.apple.com/documentation/xcode/defining-a-custom-url-scheme-for-your-app
code is procedure SetUserAgent(const ABrowser: TWebBrowser); var LWebView: WKWebView; begin
if Supports(ABrowser, WKWebView, LWebView) then
LWebView.configuration.setURLSchemeHandler(nil,nil);