nsurl

Convert an NSURL to an NSString

你说的曾经没有我的故事 提交于 2019-11-26 15:05:54
问题 I have an app where the user can choose an image either from the built-in app images or from the iphone photo library. I use an object Occasion that has an NSString property to save the imagePath . Now in the case of the built-in app images I do get the file name as an NSString an save in the [occasion imagePath] . But in the 2nd case where the user picks an image form the photo library I get an NSURL which I want to convert to an NSString to be able to save it in [occasion imagePath ]. Is it

How to use special character in NSURL?

回眸只為那壹抹淺笑 提交于 2019-11-26 11:54:17
My application is using an NSURL like this: var url = NSURL(string: "http://www.geonames.org/search.html?q=Aïn+Béïda+Algeria&country=") When I tried to make a task for getting data from this NSURL like this: let task = NSURLSession.sharedSession().dataTaskWithURL(url!, completionHandler: { (data: NSData!, response: NSURLResponse!, error: NSError!) -> Void in if error == nil { var urlContent = NSString(data: data, encoding: NSUTF8StringEncoding) println("urlContent \(urlContent!)") } else { println("error mode") } but I got error when trying to got data from that address, although when I using

NSURL path vs absoluteString

泄露秘密 提交于 2019-11-26 11:42:50
I've seen many questions on SO concerning converting between NSURL and NSString . They all involve using either NSString *path = [myURL absoluteString]; or NSString *path = [myURL path]; . What is the actual difference between these methods? Is there a time when one should be used over the other? I tried consulting the Apple Docs , but I found it less than helpful. I'm used to URL's only being mentioned in discussions concerning websites and other topics regarding sending information between different machines, and never being mentioned when dealing with just the file structure on a single

Can I somehow do a synchronous HTTP request via NSURLSession in Swift

痴心易碎 提交于 2019-11-26 10:31:05
问题 Can I somehow do a synchronous HTTP request via NSURLSession in Swift? I can do an asynchronous request via the following code: if let url = NSURL(string: \"https://2ch.hk/b/threads.json\") { let task = NSURLSession.sharedSession().dataTaskWithURL(url) { (data, response, error) in var jsonError: NSError? let jsonDict = NSJSONSerialization.JSONObjectWithData(data, options: nil, error: &jsonError) as [String: AnyObject] if jsonError != nil { return } // ... } task.resume() } But what about

Get parts of a NSURL in objective-c

倖福魔咒の 提交于 2019-11-26 09:05:06
问题 I have an NSString with the value of http://digg.com/news/business/24hr How can I get everything before the 3rd level? http://digg.com/news/ 回答1: This isn't exactly the third level, mind you. An URL is split like that way: the protocol or scheme (here, http ) the :// delimiter the username and the password (here there isn't any, but it could be username:password@hostname ) the host name (here, digg.com ) the port (that would be :80 after the domain name for instance) the path (here, /news

UILabel and NSLinkAttributeName: Link is not clickable

给你一囗甜甜゛ 提交于 2019-11-26 07:34:50
问题 I want to use attributed strings with NSLinkAttributeName to create clickable links inside a UILabel instance within my iOS 7 project, which is now finally possible without using external libraries. NSURL *url = [NSURL URLWithString:@\"http://www.google.com\"]; NSDictionary *attr = [NSDictionary dictionaryWithObjectsAndKeys: url, NSLinkAttributeName, nil]; Applying the attribute on a string displays the text as blue & underlined, but nothing happens on click/tap. User interaction is enabled

NSURLErrorDomain error code -999 in iOS

萝らか妹 提交于 2019-11-26 05:25:20
问题 I\'ve been trying to use Corona SDK\'s Facebook API to post the score on the game I\'m developing on facebook. However, I\'m having a problem with it. During the first time I try to post to facebook, I get this error after login and user authentication: NSURLErrorDomain error code -999 Then, it won\'t post on facebook. What are possible causes of this error and how can I address it? I tried searching the web but couldn\'t find information about it. Thanks in advance. By the way, I am not

Parse NSURL query property

泪湿孤枕 提交于 2019-11-26 05:20:55
问题 I have a URL like myApp://action/1?parameter=2&secondparameter=3 With the property query I get following part of my URL parameter=2&secondparameter=3 Is there any way easy to put this in a NSDictionary or an Array ? Thx a lot 回答1: Something like that: NSMutableDictionary *params = [[NSMutableDictionary alloc] init]; for (NSString *param in [url componentsSeparatedByString:@"&"]) { NSArray *elts = [param componentsSeparatedByString:@"="]; if([elts count] < 2) continue; [params setObject:[elts

iOS: Issue with ampersand in the URL string

假如想象 提交于 2019-11-26 04:46:24
问题 How do we pass a string Mr.X & Mr.Y in the URL. I have tried this but this one does all the chars but ampersand. [urlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding] 回答1: Or even shorter: @implementation NSString (Escaping) - (NSString*)stringWithPercentEscape { return [(NSString *) CFURLCreateStringByAddingPercentEscapes( NULL, (CFStringRef)[[self mutableCopy] autorelease], NULL, CFSTR("=,!$&'()*+;@?\n\"<>#\t :/"), kCFStringEncodingUTF8) autorelease]; } @end And here

NSURL pull out a single value for a key in a parameter string

瘦欲@ 提交于 2019-11-26 04:17:00
问题 I have an NSURL: serverCall?x=a&y=b&z=c What is the quickest and most efficient way to get the value of y? Thanks 回答1: UPDATE: Since 2010 when this was written, it seems Apple has released a set of tools for that purpose. Please see the answers below for those. Old-School Solution: Well I know you said " the quickest way " but after I started doing a test with NSScanner I just couldn't stop. And while it is not the shortest way, it is sure handy if you are planning to use that feature a lot.