pass variable from web site to iOS app


/ Published in: Objective C
Save to your folder(s)

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


Copy this code and paste it in your HTML
  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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.