1

I'm trying to make my iOS app receive a variable from a php-file.
Lets say that my php-website includes the variable $number=5. What is the easiest way to send that variable to my app? Maybe something like pressing a button in the app which gets the variable from the website and displays it in a text field?

I would be extremely thankful if someone could give me some advise. Please bare in mind that i'm a noob. Thanks!

3
  • 3
    You will have to use some kind of http communication like via a webservice .. Maybe search for "ios php webservice client" and read blog entries like raywenderlich.com/2941/… Commented Jan 21, 2015 at 17:43
  • Xcode is an IDE. You do not want to send a variable from PHP to Xcode. You want to send it to your iOS app. Commented Jan 21, 2015 at 19:17
  • You are basically asking how do I set up a PHP web service which can be read from an iOS app. As such, this it too broad a question on SO. We have no context as to how much you know about setting up web services using PHP or consuming web services in iOS/Objective C. Commented Jan 21, 2015 at 19:31

1 Answer 1

2

The way you describe your problem, won't never work, because it's two complete different devices with no shared memory.

What I recommend you, are by giving you some tutorial to guide you in the right way. I think you should make an API for communication between your website and the device witch want the data.

The first is for creating your own API in PHP: http://css.dzone.com/articles/create-your-own-xmljsonhtml

The second is for contacting the API in objective-c: http://www.raywenderlich.com/58682/introduction-restkit-tutorial

And if you want too, here is some swift code I have made

let listData = NSData(contentsOfURL: NSURL(string: "http://yourhost.com/api/categories")!)
let prop = NSPropertyListSerialization.propertyListFromData(listData, mutabilityOption: NSPropertyListMutabilityOptions.allZeros, format: nil, errorDescription: nil) as NSArray // or NSDictionary. NSDictionary are for key value, NSArray are for an Array

Hope that helped you a little for directions.

UPDATE

If you have en webView I just made a quick search on "ios webview pass data", and found this stackoverflow link: Passing Data To and From an Embedded UIWebView

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.