Delphi, Firemonkey, IOS, and TCP howto?

I was really excited about the new ability to compile IOS apps written in Delphi, but I'm starting to find some major limitations, unless I'm really overlooking something. I want to write an iphone/pad app that needs to retrieve data from a socket connection, or from a webpage (http, webservice, anything). It seems that all of the Firemonkey internet and indy components are not supported within xcode. 

Am I overlooking something here, or is this a feature that will not be implemented, or is it planned to be implemented?

If this kind of communication is not supported, this is a huge limitation of the new XE2 in my opinion. I hope I'm just overlooking something.

Thanks for any advice!
0
Registered
9/2/2011 3:13:53 PM
πŸ“ embarcadero.delphi.firemonkey
πŸ“ƒ 4901 articles.
⭐ 4 followers.

πŸ’¬ 12 Replies
πŸ‘οΈβ€πŸ—¨οΈ 2527 Views

Registered Programmer wrote:
> I was really excited about the new ability to compile IOS apps
> written in Delphi, but I'm starting to find some major limitations,
> unless I'm really overlooking something. I want to write an
> iphone/pad app that needs to retrieve data from a socket connection,
> or from a webpage (http, webservice, anything). It seems that all of
> the Firemonkey internet and indy components are not supported within
> xcode.      
> 
> Am I overlooking something here, or is this a feature that will not
> be implemented, or is it planned to be implemented? 
> 
> If this kind of communication is not supported, this is a huge
> limitation of the new XE2 in my opinion. I hope I'm just overlooking
> something.  
> 
> Thanks for any advice!

CFSocket looks like a good choice, included in Macapi.CoreFoundation.pas.
http://developer.apple.com/library/ios/#documentation/CoreFoundation/Reference/CFSocketRef/Reference/reference.html

-- 
Arno Garrels
0
Arno
9/2/2011 4:18:41 PM
> {quote:title=Arno Garrels wrote:}{quote}
> Registered Programmer wrote:
> > I was really excited about the new ability to compile IOS apps
> > written in Delphi, but I'm starting to find some major limitations,
> > unless I'm really overlooking something. I want to write an
> > iphone/pad app that needs to retrieve data from a socket connection,
> > or from a webpage (http, webservice, anything). It seems that all of
> > the Firemonkey internet and indy components are not supported within
> > xcode.      
> > 
> > Am I overlooking something here, or is this a feature that will not
> > be implemented, or is it planned to be implemented? 
> > 
> > If this kind of communication is not supported, this is a huge
> > limitation of the new XE2 in my opinion. I hope I'm just overlooking
> > something.  
> > 
> > Thanks for any advice!
> 
> CFSocket looks like a good choice, included in Macapi.CoreFoundation.pas.
> http://developer.apple.com/library/ios/#documentation/CoreFoundation/Reference/CFSocketRef/Reference/reference.html

Is that also available for iOS? iOS _does_ include a CoreFoundation framework, but the "Macapi" suggests that this might be for OS X, not iOS.

In general, there often low-level (Core) framework like this that have a simple "C" interface and high-level (NS) frameworks that consist of Objective C classes that wrap the low-level Core functions. Either can be used. Newer stuff is generally available only as ObjC classes, though, so you can see the trend.

Thanks.

-Phil
0
Phil
9/2/2011 5:37:25 PM
I see that I can use the NSURLxxx classes from within xcode itself for IOS development, but I am developing this app in Delphi, Rad Studio XE2. I don't believe I have access to the IOS foundation from there. Do you know if there is some sort of wrapper for these classes, or how to access them from within XE2?

Thanks!
0
Registered
9/2/2011 7:54:04 PM
> {quote:title=Registered Programmer wrote:}{quote}
> I see that I can use the NSURLxxx classes from within xcode itself for IOS development, but I am developing this app in Delphi, Rad Studio XE2. I don't believe I have access to the IOS foundation from there. Do you know if there is some sort of wrapper for these classes, or how to access them from within XE2?

OS X has access to these ObjC frameworks:

http://docwiki.embarcadero.com/RADStudio/en/Mac_OS_X_Application_Development#Mac_Objective-C_Frameworks

Look for something similar for iOS. With FPC that you build yourself and parse the header files yourself, the iPhoneAll unit includes CoreFoundation, CoreGraphics, Foundation, OpenGLES, QuartzCore, and UIKit frameworks, but this may not be the way they parsed the ObjC framework headers with XE2.

Thanks.

-Phil
0
Phil
9/2/2011 8:02:13 PM
> {quote:title=Phil Hess wrote:}{quote}
> > CFSocket looks like a good choice, included in Macapi.CoreFoundation.pas.
> > http://developer.apple.com/library/ios/#documentation/CoreFoundation/Reference/CFSocketRef/Reference/reference.html
> 
> Is that also available for iOS? iOS _does_ include a CoreFoundation framework, but the "Macapi" suggests that this might be for OS X, not iOS.
> 
> In general, there often low-level (Core) framework like this that have a simple "C" interface and high-level (NS) frameworks that consist of Objective C classes that wrap the low-level Core functions. Either can be used. Newer stuff is generally available only as ObjC classes, though, so you can see the trend.

Maybe this IP on iPhone using NS frameworks tutorial can be of interest?
http://www.devx.com/wireless/Article/43551

--
http://delphi.fosdal.com - Delphi Programming
http://plus.lars.fosdal.com - Google+
0
Lars
9/3/2011 4:08:24 PM
> {quote:title=Lars Fosdal wrote:}{quote}
> > {quote:title=Phil Hess wrote:}{quote}
> > > CFSocket looks like a good choice, included in Macapi.CoreFoundation.pas.
> > > http://developer.apple.com/library/ios/#documentation/CoreFoundation/Reference/CFSocketRef/Reference/reference.html
> > 
> > Is that also available for iOS? iOS _does_ include a CoreFoundation framework, but the "Macapi" suggests that this might be for OS X, not iOS.
> > 
> > In general, there often low-level (Core) framework like this that have a simple "C" interface and high-level (NS) frameworks that consist of Objective C classes that wrap the low-level Core functions. Either can be used. Newer stuff is generally available only as ObjC classes, though, so you can see the trend.
> 
> Maybe this IP on iPhone using NS frameworks tutorial can be of interest?
> http://www.devx.com/wireless/Article/43551

The point is that no tutorial will be very useful if a developer can't use the underlying iOS frameworks.

Here's an example of what's needed (in this case, the Foundation framework):

http://iphonedevelopertips.com/cocoa/json-framework-for-iphone-part-2.html

Look at the first Objective C method (stringWithUrl:). Here it is transliterated into Objective Pascal. Easy if you have access to the NS classes; if not, well...

function TestUrl1AppDelegate.stringWithUrl(url: NSURL) : NSString;
var
  urlRequest : NSURLRequest;
  urlData : NSData;
  response : NSURLResponse;
  error : NSError;
begin
  urlRequest := NSURLRequest.requestWithURL_cachePolicy_timeoutInterval(
                 url, NSURLRequestReturnCacheDataElseLoad, 30);

   //Fetch the JSON response

   //Make synchronous request
  urlData := NSURLConnection.sendSynchronousRequest_returningResponse_error(
              urlRequest, @response, @error);
 
   //Construct a string from the response data
  Result := NSString.alloc.initWithData_encoding(urlData, NSUTF8StringEncoding).autoRelease;
end;


Thanks.

-Phil
0
Phil
9/4/2011 1:38:33 AM
Hi

I am very interested in using TCP sockets on IOS application.
I have an existing windows app which provides a TCP server and I'd like to talk to that app from an IOS device (Ipod touch), so I need some way of doing the socket client on both IOS and Windows.

Are there any examples of how this can be done so that you can still test your app on the windows environment, then compile for the IOS on the MAC and have the same code run?

or

Do you need to use different components for each of the systems, which kind of defeats the purpose of Firemonkey.

Obviously, would be good if Indy worked both, but I see that it doesn't have a date yet for being available for both.
0
Barry
11/5/2011 1:50:57 AM
> {quote:title=Barry Andrews wrote:}{quote}
> Hi
> 
> I am very interested in using TCP sockets on IOS application.
> I have an existing windows app which provides a TCP server and I'd like to talk to that app from an IOS device (Ipod touch), so I need some way of doing the socket client on both IOS and Windows.
> 
> Are there any examples of how this can be done so that you can still test your app on the windows environment, then compile for the IOS on the MAC and have the same code run?
> 
> or
> 
> Do you need to use different components for each of the systems, which kind of defeats the purpose of Firemonkey.
> 
> Obviously, would be good if Indy worked both, but I see that it doesn't have a date yet for being available for both.

Use the CFNetwork framework:

http://oreilly.com/iphone/excerpts/iphone-sdk/network-programming.html

Maybe something like this would work for you cross-platform:

http://www.realthinclient.com/

If you need something more modern like a Web service, try this:

http://wiki.freepascal.org/Web_Service_Toolkit

This library is also popular. I've parsed the header files and tested it with iOS and Pascal. It has some nifty features:

http://allseeing-i.com/ASIHTTPRequest/

Thanks.

-Phil
0
Phil
11/5/2011 4:03:15 AM
Hello

Its been quite a while but after a busy start to the work year finally got the chance to do some work on this again.
I finally found a decent exaple of how to use this, it's in Japanese but code is pretty self explanatery and translate works quite good.

http://blogs.embarcadero.com/teamj/2012/04/03/3002/

This is a good example because it not only shows the code but also the conditionals needed for IOS and all the uses so you can just copy and test.

This runs as is, but when I start to expand on for my own requirements I have found that I get EXC_BAD_ACCESS errors when I run on the MAC.
I think this is due to my need to process the received strings and use them to update the UI.
Are there any thread safe string types for Freepascal under IOS that I can use to overcome this issue?

Currently in the on receive I am just adding the string to a global string

{code}
rcvdData: TStrings; // Ansistring UTF-8

procedure ReceiveData(str: string);
begin
     rcvdData := rcvdData + str;
end;
{code}

Then I parse the string in a timer routine.

I now I need to make this safe for threades but cannot find any examples of how to do this with firemonkey under ios using the free pascal.
0
Barry
8/12/2012 2:47:00 AM
Le 12/08/12 03:47, Barry Andrews a écrit :

> This runs as is, but when I start to expand on for my own
> requirements I have found that I get EXC_BAD_ACCESS errors when I run
> on the MAC. I think this is due to my need to process the received
> strings and use them to update the UI. Are there any thread safe
> string types for Freepascal under IOS that I can use to overcome this
> issue?
>
> Currently in the on receive I am just adding the string to a global
> string
>
> {code}
> rcvdData: TStrings; // Ansistring UTF-8
>
> procedure ReceiveData(str: string);
> begin
>       rcvdData := rcvdData + str;
> end;
> {code}
>
> Then I parse the string in a timer routine.
>
> I now I need to make this safe for threades but cannot find any
> examples of how to do this with firemonkey under ios using the free
> pascal.

My first question would be that you say you are parsing "the string" and 
yet you are using a TStrings variable, which is a list of strings.

Where are you instantiating a TStringList into the rcvdData variable and 
why are you using '+' instead of the Add method to add strings to it?

Joanna

-- 
Joanna Carter [Team OOAD]
0
Joanna
8/12/2012 8:16:10 AM
> {quote:title=Joanna Carter (Team OOAD) wrote:}{quote}
> Le 12/08/12 03:47, Barry Andrews a écrit :
> 
> > This runs as is, but when I start to expand on for my own
> > requirements I have found that I get EXC_BAD_ACCESS errors when I run
> > on the MAC. I think this is due to my need to process the received
> > strings and use them to update the UI. Are there any thread safe
> > string types for Freepascal under IOS that I can use to overcome this
> > issue?
> >
> > Currently in the on receive I am just adding the string to a global
> > string
> >
> > {code}
> > rcvdData: TStrings; // Ansistring UTF-8
> >
> > procedure ReceiveData(str: string);
> > begin
> >       rcvdData := rcvdData + str;
> > end;
> > {code}
> >
> > Then I parse the string in a timer routine.
> >
> > I now I need to make this safe for threades but cannot find any
> > examples of how to do this with firemonkey under ios using the free
> > pascal.
> 
> My first question would be that you say you are parsing "the string" and 
> yet you are using a TStrings variable, which is a list of strings.
> 
> Where are you instantiating a TStringList into the rcvdData variable and 
> why are you using '+' instead of the Add method to add strings to it?
> 
> Joanna
> 
> -- 
> Joanna Carter [Team OOAD]

My mistake when copying, I was going to try something with TStrings, but didn't undo the change before posting, rcvdData is actually just a string.
0
Barry
8/12/2012 1:27:30 PM
> {quote:title=Registered Programmer wrote:}{quote}
> I was really excited about the new ability to compile IOS apps written in Delphi, but I'm starting to find some major limitations, unless I'm really overlooking something. I want to write an iphone/pad app that needs to retrieve data from a socket connection, or from a webpage (http, webservice, anything). It seems that all of the Firemonkey internet and indy components are not supported within xcode. 
> 
> Am I overlooking something here, or is this a feature that will not be implemented, or is it planned to be implemented?
> 
> If this kind of communication is not supported, this is a huge limitation of the new XE2 in my opinion. I hope I'm just overlooking something.

You can use various Foundation classes to do that. See the "NSURLxxx" classes here:

http://developer.apple.com/library/ios/#documentation/Cocoa/Reference/Foundation/ObjC_classic/_index.html#//apple_ref/doc/uid/20001091

Thanks.

-Phil
0
Phil
10/4/2012 5:55:46 PM