RTC Forums
May 05, 2024, 06:31:51 AM *
Welcome, Guest. Please login or register.

Login with username, password and session length
 
   Home   Help Login Register  
Pages: [1]
  Print  
Author Topic: TRtcHTTPClient with TLocationSensor in FireMonkey  (Read 4193 times)
Kittipong
RTC Expired
*
Posts: 4


« on: March 13, 2016, 07:49:02 AM »

Hello

I found some problems that can not be solved.
I developed the program with FireMonkey on Android and iOS, writing a remote function call for user login. It seems to work without any problems occur.
But when I use the Component TLocationSensor simply place into main from. It seems that Android has not caused any problems, but iOS device is stopped immediately when called the remote function.

SDK:
RealThinClient SDK v7.17 (2015.Q4)

My Device:
Android Samsung Galaxy S4
iOS Emulator iPad2, iPad Air, iPhone 6

My Code:
function TFormMain.DoLogIn(const AUser, APassword: String): Boolean;
var
  IsOK: Boolean;
  Value: TRtcValue;
begin
  Result := False;
  
  RtcHttpAuthen.Blocking := True;
  RtcHttpAuthen.MultiThread := False;
  RtcHttpAuthen.ServerAddr := '192.168.1.3';
  RtcHttpAuthen.ServerPort := '80';
  
  with RtcAuthenModule do begin
    ModuleFileName := '/Users';
    Prepare('LogIn');
    Param.asWideString['UserID'] := AUser;
    Param.asWideString['Password'] := APassword;

    try
      IsOK := True;
      Value := Execute(False, 30, False);
    except
      IsOK := False;
    end;

    if not IsOK then begin
      //ShowMessage(StrServerError)
    end else begin
      if Value.isType = rtc_Record then begin
        with Value.asRecord do begin
          Result := asWideString['Status'] = '1';
          StrLogInMsg := asWideString['StatusMsg'];
          UserID := AUser; //UpperCase(AUser);
          UserName := asWideString['UserName'];
        end;
      end;
      Value.Free;
    end;
  end;
  if RtcHttpAuthen.isConnected then
    RtcHttpAuthen.Disconnect;
end;
Logged
D.Tkalcec (RTC)
Administrator
*****
Posts: 1881


« Reply #1 on: March 13, 2016, 12:17:48 PM »

Since you are making the remote function call in single-threaded blocking mode and iOS (as well as Android) does NOT have a message queue like Windows, the Main Thread of your Application will remain blocked until your code finishes execution. In my experience, leaving the Main Thread blocked and unresponsive for a bit "too long" under iOS could result in the App being terminated by the iOS, because it appears "frozen".

Leaving the Main Thread blocked for some time could also result in problems with FireMonkey or 3rd-party components which rely on a Timer or run in the background. If you need to use these components and want to avoid such problems, you will have to change your code to use the TRtcHttpClient component in non-blocking mode (Blocking=False) and make remote function calls event-driven and non-blocking by using the Call method with the TRtcResult component instead of using Execute.

PS. Before changing all of your code to work in non-blocking event-driven mode (which could take a while if you have more than a few places where you are making remote function calls), you could try running your App (without any modifications, in blocking single-threaded mode) on the iOS device with the Delphi Debugger, to find out what is really happening there. Maybe one or more of the component(s) you are trying to use does not work correctly under iOS, or requires some properties to be set differently for iOS, or does not like it when the Main Thread is blocked for a while, or ... something else is wrong.

Best Regards,
Danijel Tkalcec
Logged
Kittipong
RTC Expired
*
Posts: 4


« Reply #2 on: March 14, 2016, 03:46:49 PM »


Hi Danijel, Thanks for the help

I try to do as you suggested. But still can not solve the problem. I test change some remote function call to use TRtcDataProvider on the server do like JSON server and TRtcDataRequest like client request , The problem has gone.

Recently I changed all of my code from remote function calls to use TRtcDataProvider as REST API Server and TRtcDataRequest on iOS and Android mobile device.

PS. I think the problem is likely due to the use of remote function call with TLocationSensor.

Best Regards,
Kittipong Rungruangwat


Logged
D.Tkalcec (RTC)
Administrator
*****
Posts: 1881


« Reply #3 on: March 14, 2016, 03:58:04 PM »

1) Have you tried using the the TRtcClientModule component with the Call method and a TRtcResult component (standard event-driven way for calling remote functions) instead of using the Execute method?

2) Have you tried running the Client from a Debugger on an iOS device, to see what is going on?

Best Regards,
Danijel Tkalcec
Logged
Kittipong
RTC Expired
*
Posts: 4


« Reply #4 on: March 15, 2016, 05:39:07 PM »

1) Have you tried using the the TRtcClientModule component with the Call method and a TRtcResult component (standard event-driven way for calling remote functions) instead of using the Execute method?

Yes, I have.

2) Have you tried running the Client from a Debugger on an iOS device, to see what is going on?

No, It is quite difficult for me to debugging on iOS emulator.

And now I've moved from using remote function call to use TRtcDataProvider & TRtcClientRequest. It seems to work without any problems.

Thank you very much Danijel for your help.

Best Regards,
Kittipong Rungruangwat
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.21 | SMF © 2015, Simple Machines Valid XHTML 1.0! Valid CSS!
Page created in 0.026 seconds with 17 queries.