How to Make REST api call in Objective-C.
We can call using this. NSString * twitterUrl = @ "YourUrlString" ; NSString * resp = [ self makeRestAPICall : twitterUrl ]; and method is -( NSString *) makeRestAPICall : ( NSString *) reqURLStr { NSURLRequest * Request = [ NSURLRequest requestWithURL :[ NSURL URLWithString : reqURLStr ]]; NSURLResponse * resp = nil ; NSError * error = nil ; NSData * response = [ NSURLConnection sendSynchronousRequest : Request returningResponse : & resp error : & error ]; NSString * responseString = [[ NSString alloc ] initWithData : response encoding : NSUTF8StringEncoding ]; NSLog (@ "%@" , responseString ); return responseString ; } 1 2 3 4 @ interface ViewController : UIViewController < NSURLConnectionDelegate > { NSMutableData * _responseData ; }
Comments
Post a Comment