Jump to content

How to get type of platform on UniGUIServerModuleHTTPCommand


irigsoft

Recommended Posts

Hello, I try to get UniApplication.UniPlatform on UniGUIServerModuleHTTPCommand, when user start Session, but I get "Access violation at address".

Is it possible to get this information from something else like ExtractSessionId(ARequestInfo.UnParsedParams)?

I have write some restrictions if Platform is Android or IPhone and I need to know this when Session Start.

Link to comment
Share on other sites

Hello @irigsoft

Can you try also this approach?

procedure TUniServerModule.UniGUIServerModuleHTTPCommand(
  ARequestInfo: TIdHTTPRequestInfo; AResponseInfo: TIdHTTPResponseInfo;
  var Handled: Boolean);
  function getOSName(AUserAgent: string): string;
  begin
    if AUserAgent = '' then
    begin
      Result := 'Unknown OS';
      Exit;
    end;

    AUserAgent := LowerCase(AUserAgent);

    if Pos('win', AUserAgent) > 0 then Result := 'Windows'
    else if Pos('mac', AUserAgent) > 0 then Result := 'Macintoch'
    else if Pos('linux', AUserAgent) > 0 then Result := 'Linux'
    else if Pos('android', AUserAgent) > 0 then Result := 'Android'
    else if Pos('like Mac', AUserAgent) > 0 then Result := 'iOS'
    else Result := 'Unknown OS';
  end;
begin
  // getOSName(ARequestInfo.UserAgent)
end;

Based:

 

  • Thanks 1
Link to comment
Share on other sites

1 hour ago, Sherzod said:

Hello @irigsoft

Can you try also this approach?

procedure TUniServerModule.UniGUIServerModuleHTTPCommand(
  ARequestInfo: TIdHTTPRequestInfo; AResponseInfo: TIdHTTPResponseInfo;
  var Handled: Boolean);
  function getOSName(AUserAgent: string): string;
  begin
    if AUserAgent = '' then
    begin
      Result := 'Unknown OS';
      Exit;
    end;

    AUserAgent := LowerCase(AUserAgent);

    if Pos('win', AUserAgent) > 0 then Result := 'Windows'
    else if Pos('mac', AUserAgent) > 0 then Result := 'Macintoch'
    else if Pos('linux', AUserAgent) > 0 then Result := 'Linux'
    else if Pos('android', AUserAgent) > 0 then Result := 'Android'
    else if Pos('like Mac', AUserAgent) > 0 then Result := 'iOS'
    else Result := 'Unknown OS';
  end;
begin
  // getOSName(ARequestInfo.UserAgent)
end;

Based:

 

thanks, my problem is (how to check if navigator.connection is supported from browser of user ?):

I want to use this code on all devices Android and Iphone (but Safari not support navigator)

function window.afterrender ( .......

//  if (window?.navigator?.connection) { //- this work on IPhone + Safary, but not work on Android 5 + Google Chrome

// this work only on Android
        var connection = navigator.connection || navigator.mozConnection || navigator.webkitConnection;
        //alert (navigator.connection);
        
        var type = connection.effectiveType;
        
        function updateConnectionStatus() {
              
                 //console.log("Connection type changed from " + type + " to " + connection.effectiveType);
                 type = connection.type || connection.effectiveType;
                 ajaxRequest(sender, "connectionType", ["ctype="+type]);
        };

        updateConnectionStatus();
        connection.addEventListener('change', updateConnectionStatus);
//  }
//   else {
//     var type = "None";
//     ajaxRequest(sender, "connectionType", ["ctype="+type]);
//   }

Link to comment
Share on other sites

2 hours ago, irigsoft said:

thanks, my problem is (how to check if navigator.connection is supported from browser of user ?):

I want to use this code on all devices Android and Iphone (but Safari not support navigator)

function window.afterrender ( .......

//  if (window?.navigator?.connection) { //- this work on IPhone + Safary, but not work on Android 5 + Google Chrome

// this work only on Android
        var connection = navigator.connection || navigator.mozConnection || navigator.webkitConnection;
        //alert (navigator.connection);
        
        var type = connection.effectiveType;
        
        function updateConnectionStatus() {
              
                 //console.log("Connection type changed from " + type + " to " + connection.effectiveType);
                 type = connection.type || connection.effectiveType;
                 ajaxRequest(sender, "connectionType", ["ctype="+type]);
        };

        updateConnectionStatus();
        connection.addEventListener('change', updateConnectionStatus);
//  }
//   else {
//     var type = "None";
//     ajaxRequest(sender, "connectionType", ["ctype="+type]);
//   }

Thanks again, I correct my code to and now it's work :

from: //  if (window?.navigator?.connection) { //- this work on IPhone + Safary, but not work on Android 5 + Google Chrome

to :

  if (window.navigator && window.navigator.connection) { //- this work on IPhone + Safary + Android + Google Chrome

... my code from above

};

 

I will use information from userAgent for some of my functions.

  • Upvote 1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...