nsurl

How to prepare an NSURL from an NSString continaing international characters?

会有一股神秘感。 提交于 2019-11-28 12:37:43
I have to access a web server using a GET with international characters (Hebrew in my case but could be anything). So I make an NSString just fine but [NSURL URLWithString:urlString]; // returns nil. I realize I probably have to convert the international characters to percent codes. Is there a built in method in Objective-c to do so? Yes there is, you need -stringByAddingPercentEscapesUsingEncoding: method: [NSURL URLWithString:[string stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]; This would ensure NSURL *url does not return nil because of the "|" in the urlString .

SMS WatchKit multiple number delimiter

我只是一个虾纸丫 提交于 2019-11-28 11:53:13
问题 I'm having a little trouble getting my WatchKit App to pre-compose an SMS message to multiple recipients (via the Apple Watch message app). let messageBody = "hello test message" let urlSafeBody = messageBody.stringByAddingPercentEncodingWithAllowedCharacters(NSCharacterSet.URLHostAllowedCharacterSet()) if let urlSafeBody = urlSafeBody, url = NSURL(string: "sms:8888888888&body=\(urlSafeBody)") { WKExtension.sharedExtension().openSystemURL(url) My question is, if you have multiple phone

Check URL validity

大兔子大兔子 提交于 2019-11-28 09:34:09
Can someone confirm that -checkResourceIsReachableAndReturnError: method of NSURL is working as expected. I have tried using it for known URLs and it is always returning NO . I am using XCode's iPhone Simulator 4.1. Thank you. According to NSURL Class Reference Returns whether the resource pointed to by a file URL can be reached. ... Discussion This method is unimplemented in iOS, so it performs no operation So it only works for file URLs (which your URL probably isn't) and it only works on Mac OS X anyway. You can use this method: - (BOOL) validateUrl: (NSString *) url { NSString *theURL = @"

NSURLErrorDomain with code=-1100

萝らか妹 提交于 2019-11-28 08:08:28
问题 I was trying to download a picture to my app from The request failed with the error NSURLErrorDomain and the code is really -1100. The url should be correct since I checked it in the browser. Anyone knows why? let userImageURL: String! = "http://i.imgur.com/QhCzQoR.jpg"; let url = NSURL(fileURLWithPath: userImageURL); let request:NSURLRequest = NSURLRequest(URL: url!) NSURLConnection.sendAsynchronousRequest(request, queue: NSOperationQueue.mainQueue(), completionHandler: { (response

NSURL returns Nil Value

北城以北 提交于 2019-11-28 07:20:45
问题 Here Below is my code NSString *string = [NSString stringWithFormat:@" http://abc.com /Demo/View.php?drinkId=%@&name=%@&comment=%@&date=%@&rating=%@& ReqestType=SubmitComment",DrinkId,Name,Comment,Date,Rating]; NSURL *url = [[NSURL alloc] initWithString:string]; Here in string there is value but url returns nil. Can Anyone tell why this happened. Thanks .... "This won't work, so here's what I did instead" NSString *string = [NSString stringWithFormat:@"http://abc.com/Demo/View.php?drinkId=%@

NSData contentsOfURL constructor returns nil

守給你的承諾、 提交于 2019-11-28 06:46:26
问题 I'm trying to access an API I made in PHP. It works fine in browser, but I can't get this code to fetch any sort of data from any given webpage. var jsonData: NSData = NSData(contentsOfURL: NSURL(string: "http://www.google.com")) let string1 = NSString(data: jsonData, encoding: NSUTF8StringEncoding) println(string1) What am I doing wrong here? Update: Here's the output after changing encoding. Also, NSURLConnection doesn't start when I do that either. Might be a related issue. 回答1: the code

Reliable way to compare two NSURL or one NSURL and an NSString?

梦想与她 提交于 2019-11-28 05:57:24
I recently had a problem when comparing two NSURLs and compare one NSURL with an NSString(which is a URL address), the situation is I got an NSURLRequest from somewhere, I may or may not know the URL address it points to, and I have an URL NSString, say "http://m.google.com", now I need to check if the URL in that NSURLRequest is the same as the URL string I had: [[request.URL.absoluteString lowercaseString] isEqualToString: [self.myAddress lowercaseString]]; this returns NO as the absoluteString gives me "http://m.google.com/" whereas my string is "http://m.google.com" without a slash in the

Testing file existence using NSURL

五迷三道 提交于 2019-11-28 04:03:08
Snow Leopard introduced many new methods to use NSURL objects to refer to files, not pathnames or Core Services' FSRefs. However, there's one task I can't find a URL-based method for: Testing whether a file exists. I'm looking for a URL-based version of -[NSFileManager fileExistsAtPath: ] . Like that method, it should return YES if the URL describes anything, whether it's a regular file, a directory, or anything else. I could attempt to look up various resource values , but none of them are explicitly guaranteed to not exist if the file doesn't, and some of them (e.g., NSURLEffectiveIconKey )

session.dataTaskWithURL completionHandler never called

风格不统一 提交于 2019-11-28 03:56:19
问题 I have the following code : let urlPath:String = apiURL + apiVersion + url + "?api_key=" + apiKey let url = NSURL(string: urlPath) let session = NSURLSession.sharedSession() println(url!) let task = session.dataTaskWithURL(url!, completionHandler: {(data, reponse, error) in println("Task completed") // rest of the function... }) The completionHandler function is never called. I tried calling the URL in my browser, it works fine. I tried with another URL, it still doesn't work. I checked that

NSURL returns Invalid Summary when merging WAV files

陌路散爱 提交于 2019-11-28 02:12:37
问题 I'm trying to merge 2 .wav files inside of an Objective-C project. The idea is that i want it to give this output: file1 + (file2 - header). In that case the first file's header has to be changed to reflect the new size. If the first file is empty (so only the first time) i want the method to return the second file as a whole, but in the file 1 url. Right now i have: +(NSURL *)mergeFile1:(NSURL *)file1 withFile2:(NSURL *)file2 { if(file1 == nil) { return [file2 copy]; } NSData * wav1Data =