nsurl

How can I find out whether the user pressed the Call or the Cancel button when making a call from my app?

雨燕双飞 提交于 2019-11-26 20:43:38
问题 I need to return to my app after making a call from my app, so I use this code: NSURL *url = [NSURL URLWithString:@"telprompt://123-4567-890"]; [[UIApplication sharedApplication] openURL:url]; When the user presses a button to execute this code, an alert is shown with 2 buttons, "Call" and "Cancel". How can I find out if the user pressed the "Call" button? 回答1: This isn't perfect, but you could identify that "call" was pressed instead of "cancel" by listening for the

UILabel and NSLinkAttributeName: Link is not clickable

Deadly 提交于 2019-11-26 20:24:11
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 for the label. Does anybody know how to do this? Thanks! max.mustermann I can answer my own question now:

URLWithString: returns nil

浪尽此生 提交于 2019-11-26 18:02:15
问题 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]; 回答1: You need to

NSURL URLWithString: is null with non-english accented characters

99封情书 提交于 2019-11-26 17:27: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? 回答1: You need to escape the special characters to make it work properly.

NSURLErrorDomain error code -999 in iOS

允我心安 提交于 2019-11-26 17:21:51
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 using webview on my app. Just the widget api and a show_dialog listener in my Facebook class. The error has been

Parse NSURL query property

我们两清 提交于 2019-11-26 17:20:48
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 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 lastObject] forKey:[elts firstObject]]; } Note : This is sample code. All error cases are not managed. You

What is difference between URLWithString and fileURLWithPath of NSURL?

一个人想着一个人 提交于 2019-11-26 16:26:11
问题 In my code I have to use URLWithString to play streaming( HLS ) video and fileURLWithPath to play local video. What is the difference between these two methods? How should I use single method to play both videos. Also I need to show last frame as still image when HSL video ends. Its now showing blank screen when it ends. How should i achieve this? 回答1: +URLWithString: produces an NSURL that represents the string as given. So the string might be @"http://www.google.com" and the URL represents

iOS: Issue with ampersand in the URL string

会有一股神秘感。 提交于 2019-11-26 16:19:57
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] 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 it is again as an ARC conform inline function helper: #if __has_feature(objc_arc) static inline NSString

iOS: load an image from url

旧城冷巷雨未停 提交于 2019-11-26 15:37:15
问题 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? 回答1: 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; 回答2: In swift: var url = NSURL.URLWithString("http://www.example.com/picture.png") var data = NSData

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

让人想犯罪 __ 提交于 2019-11-26 15:11:14
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 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. I created a URLParser class that gets these vars using an NSScanner . The use is a simple as: URLParser