nsurl

iOS: load an image from url

断了今生、忘了曾经 提交于 2019-11-27 11:32:42
I need to load an image from a url and set it inside an UIImageView; the problem is that I don't know the exact size of the image, then how can I show the image correctly? Just use the size property of UIImage, for example: NSURL *url = [NSURL URLWithString:path]; NSData *data = [NSData dataWithContentsOfURL:url]; UIImage *img = [[UIImage alloc] initWithData:data]; CGSize size = img.size; In swift: var url = NSURL.URLWithString("http://www.example.com/picture.png") var data = NSData(contentsOfURL : url) var image = UIImage(data : data) image.size // if you need it In swift regarding using

URLWithString: returns nil

半世苍凉 提交于 2019-11-27 11:31:06
it may be very easy, but I don't seems to find out why is URLWithString: returning nil here. //localisationName is a arbitrary string here NSString* webName = [localisationName stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; NSString* stringURL = [NSString stringWithFormat:@"http://maps.google.com/maps/geo?q=%@,Montréal,Communauté-Urbaine-de-Montréal,Québec,Canadae&output=csv&oe=utf8&sensor=false&key=", webName]; NSURL* url = [NSURL URLWithString:stringURL]; You need to escape the non-ASCII characters in your hardcoded URL as well: //localisationName is a arbitrary string here

Convert an NSURL to an NSString

半城伤御伤魂 提交于 2019-11-27 10:06:50
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 possible to convert the NSURL to an NSString ? Randall In Objective-C: NSString *myString = myURL

Why do I get this error when I try to pass a parameter in NSURL in iOS app?

那年仲夏 提交于 2019-11-27 08:48:42
问题 This is what I have in a public method - (IBAction)methodName NSString *quoteNumber = [[self textBox] text]; NSURL *url = [[NSURL alloc] initWithString:@"http://TestSite.com/virdirectory/Webservice1/Service1.asmx/GetQuote?number=%d", quoteNumber]; The error I get is: Too many arguments to method call, expected 1, have 2 What am I doing wrong? 回答1: The initWithString method can only accept a normal NSString, you are passing it a formatted NSString, Take a look at this code: NSURL *url = [

iPhone SDK: Check validity of URLs with NSURL not working?

两盒软妹~` 提交于 2019-11-27 08:24:47
问题 I'm trying to check if a given URL is valid and i'm doing it like this: - (BOOL)urlIsValid:(NSString *)address { NSURL *testURL = [NSURL URLWithString:address]; if (testURL == nil) { return NO; } else { return YES; } } Since "URLWithString" is supposed to return "nil" if the URL is malformed I thought this would work but it doesn't for some reason. Could someone please tell me why? Thanks in advance! 回答1: NSURLRequest *req = [NSURLRequest requestWithURL:[NSURL URLWithString:@"yourstring"]];

openURL: deprecated in iOS 10

空扰寡人 提交于 2019-11-27 07:58:28
Apple with iOS 10 has deprecated openURL: for openURL:option:completionHandler If I have: [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"https://www.google.com"]]; How it will become? options:<#(nonnull NSDictionary *)#> in detail [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"https://www.google.com"] options:<#(nonnull NSDictionary<NSString *,id> *)#> completionHandler:nil]; Thanks Update options:@{} For empty dictionary with no key and value http://useyourloaf.com/blog/querying-url-schemes-with-canopenurl/ Write like this. Handle completionHandler

Convert String to NSURL is return nil in swift

99封情书 提交于 2019-11-27 07:57:41
I am trying to convert a String to NSURL and my code for that is Below: var url = "https://maps.googleapis.com/maps/api/distancematrix/json?origins=\(self.latitude),\(self.longitude)&destinations=\(self.stringForDistance)&language=en-US" println("This is String: \(url)") var remoteUrl : NSURL? = NSURL(string: url) println("This is URL: \(remoteUrl)") And console prints something like this: This is String: https://maps.googleapis.com/maps/api/distancematrix/json?origins=-34.4232722,150.8865837&destinations=-34.4250728,150.89314939999997|-34.4356434,150.8858692|-34.4250728,150.89314939999997|-34

How to use openURL for making a phone call in Swift?

别来无恙 提交于 2019-11-27 07:45:58
I have converted the code for making a phone call from Objective-C to Swift, but in Objective-C, we can set the type of the URL that we like to open (e.g. telephone, SMS, web) like this: @"tel:xx" @"mailto:info@example.es" @"http://stackoverflow.com" @"sms:768number" The code in Swift is: UIApplication.sharedApplication().openURL(NSURL(string : "9809088798") I read that have not released any scheme parameter for tel: , but I don't know if Swift can detect if the string is for making a phone call, sending email, or opening a website. Or may I write: (string : "tel//:9809088798") ? I am pretty

NSURLProtocol isn't asked to load after YES response to canInitWithRequest

馋奶兔 提交于 2019-11-27 07:33:22
问题 I'm registering an implementation of NSURLProtocol to do some custom handling of certain URL requests (I tag these requests by setting properties on them). These URL requests are coming from a UIWebView's load method. Create a UI web view (first load after launch) Load content Destroy web view Create a new web view (subsequent loads) Load content I'm seeing significantly different behavior between steps 2 and 5. My NSURLProtocol implementation manages cached data and is designed to handle the

NSURL with Curly Braces

穿精又带淫゛_ 提交于 2019-11-27 07:23:15
问题 NSURL does not support the use of curly braces (i.e. {}) in URLs. My application needs to talk to a server that requires the use of curly braces in the URL. I'm considering using bridges to write the networking code in Python or C++, or even rewriting the C code for NSURL to make it accept curly braces. Percent escapes are not accepted by my remote server. Do I have any other good alternatives? EDIT: Explained why addingPercentEscapesUsingEncoding and the like don't work for me here. 回答1: