I've buil开发者_JAVA百科t a backend in python that posts data to the database. I want a layer of abstraction, so I thought that the best thing to do was to call a python function from objective-c. The python function would then post to the database. How can this be done?
You'll need to access the Python function via a web server (potentially using an intermediate scripting language to call the Python script). You can read more about this via http://docs.python.org/howto/webservers.html
Being honest, it may prove to be less hassle to simply use a more common web scripting language (i.e.: not Python) if this is an option.
Moving on, in terms of the iPhone-side activity, you'll need to :
Ensure there's a network connection available to the remote site in question. (There's a plethora of questions here on Stack Overflow, such as: Determining Internet Availability on iPhone?)
Open a request to the remote web server. The NSURLRequest class should be ideal for this.
Handle the results of the above correctly.
精彩评论