nsurl

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

我们两清 提交于 2019-11-27 07:08:01
问题 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? 回答1: Yes there is, you need -stringByAddingPercentEscapesUsingEncoding: method: [NSURL URLWithString:[string stringByAddingPercentEscapesUsingEncoding

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

别说谁变了你拦得住时间么 提交于 2019-11-27 06:47:29
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 synchronous request? Thanks in advance. You can use this NSURLSession extension to add a synchronous method:

Getting URL of UIImage selected from UIImagePickerController

拥有回忆 提交于 2019-11-27 05:45:47
问题 I'm trying to provide a user selection of an image from Photo Library. Thus I'm using UIImagePickerController for selecting. But here comes an issue with getting its initial URL in the file system (I need this for CKAsset ). My code. func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [NSObject : AnyObject]) { let imageURL = info[UIImagePickerControllerReferenceURL] as NSURL let path = imageURL.path! let imageName = path.lastPathComponent let paths

How to send a Get request in iOS?

老子叫甜甜 提交于 2019-11-27 04:14:25
问题 I am making a library to get response from a particular URL with specified data and method type. For this, I am making a request with url. But when I set its method type, it shows an exception of unrecognized selector send in [NSURLRequest setHTTPMethod:] I am setting it as [requestObject setHTTPMethod:@"GET"]; Tell me what could be the problem. Also provide me the code if you have. 回答1: NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:serverAddress]

Check URL validity

纵饮孤独 提交于 2019-11-27 03:00:44
问题 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. 回答1: 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

NSData & NSURL - url with space having problem

吃可爱长大的小学妹 提交于 2019-11-27 01:13:49
问题 I have following code in my application. NSData *data=[NSData dataWithContentsOfURL:[NSURL URLWithString:pathOfThumbNail]]; pathOfThumbNail has following path http://70.84.58.40/projects/igolf/TipThumb/GOLF 58B.jpg When I open above path in safari browser - path is changed automatically & image is successfully displayed. http://70.84.58.40/projects/igolf/TipThumb/GOLF%2058B.jpg But in iPhone, due to space in path, image isn't loaded in nsdata. 回答1: Use:

NSURL URLWithString: is null with non-english accented characters

隐身守侯 提交于 2019-11-27 00:36:52
I have the following string... NSString *googleSearchString = @"http://www.google.com/search?q=lyrics+%22Tænder+På+Dig%22+%22Jakob+Sveistrup%22"; Notice that it has some accented characters. When I try to turn that into a url the returned url is null... [NSURL URLWithString:googleSearchString]; So normally the url works except when there are accented non-english characters in the string. Any help on how to handle that? You need to escape the special characters to make it work properly. Something like: [NSURL URLWithString:[googlSearchString stringByAddingPercentEscapesUsingEncoding:

OSX Swift open URL in default browser

徘徊边缘 提交于 2019-11-27 00:09:24
问题 How to open a url in system default browser by using Swift as programming language and OSX as plattform. I found a lot with UIApplication like UIApplication.sharedApplication().openURL(NSURL(string: object.url)) but this works just on iOS and not on OSX And the Launch Services, I found has no examples for swift and there is a lot deprecated for OSX 10.10 Any help welcome - thanks. 回答1: Swift 3 or later import Cocoa let url = URL(string: "https://www.google.com")! if NSWorkspace.shared.open

How to get the image from uiwebview in ios

时光毁灭记忆、已成空白 提交于 2019-11-26 22:46:51
问题 here i loaded the content as well as the images in the webview, i want to take the image from the webview and load it into the imageview. the url of the image is received but the image is not loaded it in to the imageview here i use the code for taking the image from webview is -(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch { //Touch gestures below top bar should not make the page turn. //EDITED Check for only Tap here instead. if (

Get parts of a NSURL in objective-c

感情迁移 提交于 2019-11-26 21:09:55
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/ 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/business/24hr ) the parameter string (anything that follows a semicolon) the query string (that would be if you