nsurl

NSURL URLWithString:relativeToURL: is clipping relative url

我的梦境 提交于 2019-11-29 11:31:44
问题 I'm trying to implement an iOS app, which uses RestKit. In all examples I've seen so far the following code is used to create the URLs: NSURL *baseURL = [NSURL URLWithString:@"https://api.service.com/v1"]; NSURL *relativeURL = [NSURL URLWithString:@"/files/search" relativeToURL:baseURL]; But then [relativeURL absoluteString] will return https://api.service.com/files/search . So I tried a few examples: NSURL *baseURL1 = [NSURL URLWithString:@"https://api.service.com/v1/"]; NSURL *baseURL2 =

Launching App Store from App in Swift

半腔热情 提交于 2019-11-29 11:18:02
问题 I am creating an app, and I have a banner which promotes my other app. This is my code: var barsButton : UIButton = UIButton(frame: CGRectMake((self.view.bounds.width / 2) - 51, self.view.bounds.height - 100, 102, 30)) barsButton.setImage(UIImage(named: "Bars Icon 2.png"), forState: .Normal) barsButton.addTarget(self, action: "openBarsLink", forControlEvents: UIControlEvents.TouchUpInside) func openBarsLink() { var barsLink : String = "itms-apps:https://itunes.apple.com/app/bars/id706081574

session.dataTaskWithURL completionHandler never called

China☆狼群 提交于 2019-11-29 10:37:49
I have the following code : let urlPath:String = apiURL + apiVersion + url + "?api_key=" + apiKey let url = NSURL(string: urlPath) let session = NSURLSession.sharedSession() println(url!) let task = session.dataTaskWithURL(url!, completionHandler: {(data, reponse, error) in println("Task completed") // rest of the function... }) The completionHandler function is never called. I tried calling the URL in my browser, it works fine. I tried with another URL, it still doesn't work. I checked that my ios simulator could connect to the Internet, it does. I don't know why the function is not called

Getting URL of UIImage from UIImagePickerController

流过昼夜 提交于 2019-11-29 07:13:10
I'm trying to get the URL of an image imported from Library in Swift to send it to Apple Watch with transferFile(_:metadata) but I'm having two error on NSURL . This is my code: func imagePickerController(picker: UIImagePickerController, didFinishPickingImage image: UIImage!, editingInfo: [NSObject : AnyObject]!) { imagePicked.image = image let imageUrl = editingInfo[UIImagePickerControllerReferenceURL] as! NSURL let imageName = imageUrl.path!.lastPathComponent let documentDirectory = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true).first as String! let localPath

NSData dataWithContentsOfURL

此生再无相见时 提交于 2019-11-29 06:28:59
I have this method for button click (download). The problem is that it is terminating due to an exception: [Session started at 2011-03-14 13:06:45 +0530.] 2011-03-14 13:06:45.710 XML[7079:20b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSCFString isFileURL]: unrecognized selector sent to instance 0x62b8' -(IBAction) download { UIImage *image = [UIImage imageWithData: [NSData dataWithContentsOfURL:@"http://ws.cdyne.com/WeatherWS/Images/thunderstorms.gif"]]; [image release]; } What is the problem? It expects an NSURL as argument, not a string.

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

喜夏-厌秋 提交于 2019-11-29 05:26:44
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, inRange characterRange: NSRange) -> Bool { if let url = URL.absoluteString { if #available(iOS 8.0, *)

How do I get the NSURLResponse before the downloadTaskWithURL finishes?

扶醉桌前 提交于 2019-11-29 05:17:46
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.suggestedFilename)\".") println(location.path!) println("Started saving \"\(response.suggestedFilename)\".") if

Clicking on NSURL in a UITextView

萝らか妹 提交于 2019-11-29 04:53:27
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 is the link: // The entire remainder of the line will be the link (all the white space after @test)

Parse NSURL path and query on iOS

穿精又带淫゛_ 提交于 2019-11-29 03:47:22
Are there any standard objects or functions to parse an NSURL's components? Clearly I could write one, but why re-invent the wheel? [NSURL path] will return an NSString like "argX=x&argY=y&argZ=z" What I would rather get back is a dictionary populated with {@"argX" => @"x", @"argY" => @"y", @"argZ" = @"z"} For the path, which returns a string like "/partA/partB/partC", I would rather get an array with the structure {[0] => @"partA", [1] => @"partB", [2] => @"partC"} I realize this is a pretty specific ask, but it seems like something a lot of people would want. This is for iOS! Apparently