FAQ Database Discussion Community

NSMutableURLRequest - HTTPBody from Swift Array

I need to send a post request to my server with HTTPBody of Array. Here's my array of parameters: params = [ "message" : [ "alert" : "Find your iPhone", "sound" : "Binocular_Default.caf" ] ] Now I need to set NSMutableURLRequest's HTTPBody to this array. How can I do that?...

Server IP or domain when connecting to backend?

When you are connecting to your backend in e.g. a iOS application do you then specify your server IP or your domain when sending the request. What would be considered best practice? ([NSMutableURLRequest requestWithURL:url ...] vs [NSMutableURLRequest requestWithURL:ip ...]) Why i am thinking about using the server ip is because...

NSURLResponse comes quickely in Simulator but on actual Device it comes after some time or returns NULL

I am creating a application which calls Web service on every view-controller.The Application runs fine on Simulator but on actual device, it runs very slowly or sometimes it returns null response that's why app crashes due to null response from sever.Is there any solution to solve this issue.I am very...

Unsupported URL on ios 8

I'm trying to fetch a json from google places with the following code: NSString *query = [NSString stringWithFormat:@"https://maps.googleapis.com/maps/api/place/search/json?location=%f,%f&radius=%i&types=%@&sensor=true&key=%@", center.latitude, center.longitude, rad, types, kGOOGLE_API_KEY]; NSLog(@"%@",query); NSURL *googleRequestURL=[NSURL URLWithString:query]; [NSURLConnection sendAsynchronousRequest:[[NSURLRequest alloc] initWithURL:googleRequestURL] queue:[[NSOperationQueue alloc] init]...

AFNetworking sending URL as post parameter

I am calling an API in which I am sending a URL link as a post parameter with it. But while converting it into JSON data using NSData* jsonData = [NSJSONSerialization dataWithJSONObject:lParameters options:NSJSONWritingPrettyPrinted error:&error]; it adds extra '\' character into the link. and when I log that data string, it...

Download Multiple File at a time in Swift

I was finally able to download 1 video from a server using the following code: import UIKit class ViewController: UIViewController, NSURLConnectionDelegate { var file:NSFileHandle? @IBOutlet weak var webView: UIWebView! override func viewDidLoad() { super.viewDidLoad() downloadVideo() } func downloadVideo(sender: UIButton) { let urlPath: String = "http://www.ebookfrenzy.com/ios_book/movie/movie.mov" var url: NSURL = NSURL(string:...

Create a Class that Makes HTTPRequest in Swift

I am making an app that has the need to make HTTP Request in many of its ViewControllers. I ended up copy and pasting these codes in to each of the ViewControllers and listen to the delegates callback of NSURLConnectionDelegate and NSURLConnectionDataDelegate func makeRequest() { //Base64 var username = "testUsername";...

Parse JSON output from AlamoFire

I am using the latest Alamofire to manage a GET http request to my server. I am using the following to GET and parse the JSON: Alamofire.request(.GET, "*******") .responseJSON {(request, response, JSON, error) in if let statusesArray = JSON as? NSArray{ if let aStatus = statusesArray[0] as? NSDictionary{ //OUTPUT SHOWN...

How do I add media to a Tweet using Parse.com and PFTwitterUtils?

I am trying to hit the media/upload endpoint to upload an image to twitter. I am signing the request with Parse.com's PFTwitterUtils class. Posting a tweet to the statuses/update works perfectly, but the media/upload endpoint keeps returning an authentication error: { "errors": [ { "message": "Could not authenticate you.", "code":...

NSURL/NSURLRequest is unexpectedly nil

I'm trying to load a PDF into a UIWebView, but when using loadRequest, I'm getting the error unexpectedly found nil while unwrapping an Optional. My relevant code is below: let url = NSURL(string: "http://www.urartuuniversity.com/content_images/pdf-sample.pdf")! println(url.fileURL) println("The URL is \(url.absoluteURL!)") let request = NSURLRequest(URL: url) webView.loadRequest(request) The second line of code...

iOS URL Request Not Working

I'm trying to send data to a PHP web page (which already knows what to do with the receiving URL). Once a specific button is clicked, my app should be sending a URL request, but it isn't. I'm using the "NSURLConnectionDelegate", but I didn't implement any methods, am I conforming...

Use local resources in WKWebview

How do I make WKWebview use local .js, .css and/or local image files, in place of remote files, in order to make the web page load faster. Also, I noticed NSURLProtocol methods (when implemented through register class) do not get called when WKNavigationDelegate methods are implemented, any idea on why?

UIWebView get http status code from loaded page

I using a UIWebView in a game to display a customer support form. I noticed i have problem to close the webview if the server return a 503 error (http status code sent from a load balancer) Is there a way to easily get this http status ? can I...

String is not convertible to String:AnyObject

I am trying out the Alamofire helpers for networking with my server. I am building up a router for handling my API endpoints. The construction itself seems clear to me, but I am struggling with some SWIFT syntax. enum Router:URLRequestConvertible { static let baseURLString = "url" case AEDS var URLRequest:...

Load UIImage from URL in iOS

I am trying to load a UIImage from its URL with completionand placeholder image , but neither the UIImage nor the placeholder UIImage are loaded. Here is my code: NSURL *url = [NSURL URLWithString:@"http://assets.gearlive.com/tvenvy/blogimages/stewiegriffin.jpg"]; NSURLRequest *request = [NSURLRequest requestWithURL:url]; [self.imageView setImageWithURLRequest:request placeholderImage:[UIImage imageNamed:@"bg.png"] success:^(NSURLRequest *request, NSHTTPURLResponse *response, UIImage *image) {...

Correct asynchronous Authentication while keeping a responsive UI

What it's supposed to be I have a username field. When the username is entered and the sendButton is clicked, the userdata is fetched with a asynchronousRequest as a JSON file. After the sendButton is clicked, I want to display an ActivityIndicator. The UI shall still be responsive, while the...

NSURL found nil while unwraping an Optional value

Anyone knows why am I getting fatal error: unexpectedly found nil while unwrapping an Optional value When i use let URL = NSURL(string: "https://roads.googleapis.com/v1/snapToRoads?path=-35.27801,149.12958|-35.28032,149.12907")! ...

Does the network link conditioner affect NSURLCache's response time?

When the iOS network link conditioner is enabled, will requests cached by the shared NSURLCache be returned more slowly?

Swift - Using less than “<” operator in REST api search with NSURLRequest

I am new to this HTTP request stuff so I apologize if my terminology is not correct. What I am trying to do is search a database using a particular query string. I have used it successfully using curl and partially successfully using NSURLRequest when I don't use the "<"...