Posted By

code4mac on 11/19/12


Tagged

php variable ios


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

dennywalker
capelanus


pass variable from web site to iOS app


 / Published in: Objective C
 

pass a variable from web site (in php, in this case) to iOS app.

  1. //in iOS code
  2. NSData *dataFromURL = [NSData dataWithContentsOfURL:[NSURL URLWithString:@"http://www.mywebsite.com/someProgramme.php"] options:NSDataReadingUncached error:&error];
  3. if(error)
  4. {
  5. NSLog(@"%@", [error localizedDescription]);
  6. }
  7. else
  8. {
  9. NSLog(@"Data had loaded successfully");
  10.  
  11. }
  12. NSString *resultString = [[NSString alloc] initWithData:dataFromURL encoding:NSUTF8StringEncoding];
  13. NSLog(@"result : %@", resultString);
  14.  
  15. /*
  16. in php code as a very simple example
  17. <?php
  18. - function someFunction ()
  19. {
  20.   $variable = rand(0,10);
  21.   echo $variable;
  22. }
  23. someFunction();
  24. ?>
  25. */

Report this snippet  

You need to login to post a comment.