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!

rmaddy
  • 314,917
  • 42
  • 532
  • 579
ogloco18
  • 11
  • 2
  • 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 http://www.raywenderlich.com/2941/how-to-write-a-simple-phpmysql-web-service-for-an-ios-app – flob Jan 21 '15 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. – rmaddy Jan 21 '15 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. – Mike Brant Jan 21 '15 at 19:31

1 Answers1

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

Community
  • 1
  • 1