Hoy vamos a hacer una petición a la API de OMDb. Para ello yo he optado por usar un SearchBar por lo que lanzo la petición desde el método delegado correspondiente:
– (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar
Primero nuestras constantes:
1 2 3 |
#define MAX_TIMEOUT 10 #define ERROR_TIMEOUT @"timed out" #define API_URL @"http://www.omdbapi.com/?plot=short&r=json&s=" |
Creamos nuestra petición con la dirección: http://www.omdbapi.com/?s=her
1 2 3 4 |
NSString *title = searchBar.text; NSString *url = [NSString stringWithFormat:@"%@%@",API_URL,title]; NSURL *restURL = [NSURL URLWithString:url]; NSURLRequest *request = [NSURLRequest requestWithURL:restURL cachePolicy:NSURLRequestReloadIgnoringLocalAndRemoteCacheData timeoutInterval:MAX_TIMEOUT]; |