nsurl

Initializer for conditional binding must have Optional type, not 'String'

大城市里の小女人 提交于 2019-11-27 22:57:48
问题 Here is a fun issue I'm running into after updating to Swift 2.0 The error is on the if let url = URL.absoluteString line func myFormatCompanyMessageText(attributedString: NSMutableAttributedString) -> NSMutableAttributedString { // Define text font attributedString.addAttribute(NSFontAttributeName, value: UIFont(name: "Montserrat-Light", size: 17)!, range: NSMakeRange(0, attributedString.length)) return attributedString } func textView(textView: UITextView, shouldInteractWithURL URL: NSURL,

How do I get the NSURLResponse before the downloadTaskWithURL finishes?

戏子无情 提交于 2019-11-27 22:42:53
问题 This is my code for download : let url = NSURL(string:"http://www.zastavki.com/pictures/originals/2013/Photoshop_Image_of_the_horse_053857_.jpg")! let documentsDirectoryURL = NSFileManager().URLsForDirectory(.DocumentDirectory, inDomains: .UserDomainMask).first as! NSURL NSURLSession.sharedSession().downloadTaskWithURL(url, completionHandler: { (location, response, error) -> Void in if let error = error { println(error.description) } else { println("Finished downloading \"\(response

How to get the image from uiwebview in ios

这一生的挚爱 提交于 2019-11-27 19:12:16
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 ([gestureRecognizer isKindOfClass:[UITapGestureRecognizer class]]) { CGPoint touchPoint = [touch

How To Get HTML source from URL with Swift

点点圈 提交于 2019-11-27 19:04:26
I need to look at the HTML of a page given by a certain URL. If I have this, what is the most efficient and synchronous way to get the HTML source for that URL using Swift? I haven't been able to find a concise way online that returns it into a variable as opposed to printing it in a completionHandler. I need to manipulate the source outside of whatever call uses the URL. How is this done in Swift? Disclaimer : Since this is getting quite a lot of views, I just want to remind everyone that this answer here is synchronous, and will block your app if you do it on the main thread. You should

Clicking on NSURL in a UITextView

二次信任 提交于 2019-11-27 18:56:29
问题 I have a UITextView that spans 100.0 points across my UIView . In the UITextView , I have links that get captured with the following function: - (BOOL) textView:(UITextView *)textView shouldInteractWithURL:(NSURL *)URL inRange:(NSRange)characterRange This works great to capture certain characters but I have one problem: if the link is the last characters in the text view, then the tap will get pressed all the way across that line. So if I have the text view with the following text where @test

When should I use NSURL instead of NSString and vice versa?

你离开我真会死。 提交于 2019-11-27 18:20:02
问题 This is not a question about a pertinent problem. It's a question by which I try to deepen my understanding of Objective-C or more specific Cocoa Foundation. When dealing with uploading and download files from a server to my apps, I'm constantly torn between using NSURL or NSString for all things path related. Of course when there's an existing API I just use it according to the specs. But when I store my own paths or create custom classes that deal with them, I'm confused which of the two

How to send a Get request in iOS?

自作多情 提交于 2019-11-27 18:01:22
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. Mobile Developer iOS Android NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:serverAddress] cachePolicy:NSURLRequestReloadIgnoringLocalAndRemoteCacheData timeoutInterval:10 ]

How can I retrieve local files with NSURL?

夙愿已清 提交于 2019-11-27 17:15:29
问题 I'm here with a question that probably has a really simple answer that I am overlooking... how can I retrieve local files with NSURL? I have this here: override func viewDidLoad() { super.viewDidLoad() var urlpath = NSBundle.mainBundle().pathForResource("bpreg", ofType: "xml") let url:NSURL = NSURL(string: urlpath!)! parser = NSXMLParser(contentsOfURL: url)! parser.delegate = self parser.parse() } But after it successfully builds it hangs on var urlpath. I've searched around and tried a few

App Updates, NSURL, and Documents Directory

安稳与你 提交于 2019-11-27 14:29:09
I have an app in the app store that uses Core Data to persist much of the data. The exception is storing images. I store images in subdirectories to the Documents directory and store an NSURL reference to that image in the appropriate object attribute in the core data store. We have noticed that, when an update makes it to the app store, those images are not found, and thus don't display, using the references stored with the previous version of the app. Now, I have a suspicion that the problem is that, since we are using development devices for testing, this issue propagates because the

Leak from NSURL and AVAudioPlayer using ARC

只谈情不闲聊 提交于 2019-11-27 12:47:22
I am runung Instruments on an iPhone 4S. I am using AVAudioPlayer inside this method: -(void)playSound{ NSURL *url = [self.word soundURL]; NSError *error; audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:&error]; if (!error) { [audioPlayer prepareToPlay]; [audioPlayer play]; }else{ NSLog(@"Problem With audioPlayer on general card. error : %@ | url %@",[error description],[url absoluteString]); } I am getting leaks when playing the sound files: Leaked objects: 1. Object : NSURL Responsible Library : Foundation Responsable Frame : Foundation -[NSURL(NSURL) allocWithZone:] 2.