nsurl

Delaying an -(id)init instance; is it possible?

佐手、 提交于 2019-12-11 14:12:22
问题 I've been trying to get a PDF from an NSURL that is changed during a - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath The change in NSURL logs perfectly, but the view is loaded before the app has a chance to act upon that change. Is there a way to delay the reading of the change in URL by simply moving the code to the viewDidLoad section, or do I have to drastically change everything? Here's my -(id)init method: - (id)init { if (self = [super init])

How to encode special character like ’ (NSWindowsCP1250StringEncoding) in Swift2

孤人 提交于 2019-12-11 11:57:20
问题 As in Swift2 stringByAddingPercentEscapesUsingEncoding() is deprecated instead of stringByAddingPercentEncodingWithAllowedCharacters() is used. But how to encode the especial character like ' % & in swift2 For example in iOS8 (swift1.2) i used following code for encoding NSURL(string: "myurl.php?deviceName=name’phone".stringByAddingPercentEscapesUsingEncoding(NSWindowsCP1250StringEncoding)!) it work fine i.e. on server it decode correctly. But in iOS9 (Swift2.0) i used following code NSURL

CGImageSourceCreateWithURL returns always NULL

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-11 11:04:24
问题 I need to read the properties of an image without load or download it. In fact i have implemented a simple method that use the CGImageSourceCreateWithUrl for accomplish this. My problem is that it is returning always error because seems that the imageSource is null. So what can i do for fix it? In the NSURL object i pass urls like: "http://www.example.com/wp-content/uploads/image.jpg" but also ALAssets library Id used to retrieve images inside the phone like "assets-library://asset/asset.JPG

NSURL of UIImage from UIImagePickerController returns (null)

别说谁变了你拦得住时间么 提交于 2019-12-11 10:35:50
问题 - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editInfo { userURL = [editInfo objectForKey:UIImagePickerControllerMediaURL]; userImage = image; userImageView.image=userImage; [self dismissViewControllerAnimated:YES completion:nil];} I then take NSURL userURL, and put it in an UIActivityViewController to use to upload the image. However this never works, and always fails as it's trying to upload (null). However

Swift: 'ViewController.Type' does not have a member named 'URL'

流过昼夜 提交于 2019-12-11 09:38:46
问题 I have some code in my viewController var URL: NSURL = NSURL(string: "http://someurl.com")! var request : NSMutableURLRequest = NSMutableURLRequest(URL:URL) request.HTTPMethod = "POST" var bodyData = "data=something" NSURLConnection.sendAsynchronousRequest(request, queue: NSOperationQueue.mainQueue()) { (response, data, error) in println(NSString(data: data, encoding: NSUTF8StringEncoding)) } However I get the error: 'ViewController.Type' does not have a member named 'URL'. If I put the code

Check if link pressed in UIWebView

▼魔方 西西 提交于 2019-12-11 08:55:39
问题 I have a UIWebView which is set the URL like this: let url = NSURL (string: "http://google.com"); let requestObj = NSURLRequest(URL: url!); webView.loadRequest(requestObj); However I'd like to be able to check if the user as pressed a link. I tried something simple like this: if (url != "http://google.com") { println("Do Stuff"); } which worked fine, however this only checks it in the viewDidLoad I'd like to now every time a link is pressed or when the URL changes. 回答1: You can check the URL

Custom URL scheme as adapter on existing URL schemes

不想你离开。 提交于 2019-12-11 08:36:05
问题 Is there a clean and spec-conformant way to define a custom URL scheme that acts as an adapter on the resource returned by another URL? I have already defined a custom URL protocol which returns a decrypted representation of a local file. So, for instance, in my code, decrypted-file:///path/to/file transparently decrypts the file you would get from file:///path/to/file . However, this only works for local files. No fun! I am hoping that the URL specification allows a clean way that I could

How to get path of image, selected from gallery in swift

对着背影说爱祢 提交于 2019-12-11 07:44:34
问题 In obj-c with using image picker, I could get path of image with this: NSURL* localUrl = (NSURL *)[info valueForKey:UIImagePickerControllerReferenceURL]; but when I try this code in swift : func imagePickerController(picker: UIImagePickerController!, didFinishPickingImage image: UIImage!, editingInfo: NSDictionary!){ self.dismissViewControllerAnimated(true, completion: { () -> Void in }) var path : NSURL = editingInfo.valueForKeyPath("UIImagePickerControllerOriginalImage") as NSURL ... } it

URL File Size With NSURLConnection - Swift

坚强是说给别人听的谎言 提交于 2019-12-11 06:54:18
问题 i am trying to get a file size from url before downloading here is the obj-c code NSURL *URL = [NSURL URLWithString:"ExampleURL"]; NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:URL]; [request setHTTPMethod:@"HEAD"]; NSHTTPURLResponse *response; [NSURLConnection sendSynchronousRequest:request returningResponse:&response error: nil]; long long size = [response expectedContentLength]; and here is Swift Code var url:NSURL = NSURL(string: "ExmapleURL") var request

How can I add a url to an alert?

半世苍凉 提交于 2019-12-11 05:48:33
问题 Is there a method to add an url for users looking for additional information? My alert looks like this let alert = UIAlertController(title: "Alert details", message: "For more detailed information, click the link below", preferredStyle: UIAlertControllerStyle.Alert) // add url here let okayAction = UIAlertAction(title: "Ok", style: .Default) { (action) in print(action) } alert.addAction(okayAction) The idea is to redirect them to a webpage and close the UIAlertController in the app 回答1: You