Tag: nsurl

Swift:将video从NSURL保存到用户相机胶卷

我有一个NSURLtypes的variablesvideoURL 。 如果我打电话给println(videoURL)它会返回这样的内容: http://files.parsetfss.com/d540f71f-video.mp4 : http://files.parsetfss.com/d540f71f-video.mp4 我有一个button,应该采取这个videoURL并保存video到用户的相机胶卷。 我做的最好的是这样的: UISaveVideoAtPathToSavedPhotosAlbum(videoPath: String!, completionTarget: AnyObject!, completionSelector: Selector, contextInfo: UnsafeMutablePointer<Void>) 虽然我什至不知道这是否会工作,我不知道如何将videoFile:NSURL转换为一个videoPath 。 任何帮助表示赞赏。 编辑: 以下是不成功的: UISaveVideoAtPathToSavedPhotosAlbum(videoURL.relativePath, self, nil, nil)

我可以创build一个指向内存NSData的NSURL吗?

NSURL的文档声明: NSURL对象表示可能包含远程服务器上的资源位置,磁盘上本地文件的path,甚至任意一段编码数据的URL 。 我有一堆内存数据,我想交给一个想通过NSURL加载资源的库。 当然,我可以先写这个NSData到一个临时文件,然后创build一个file:// NSURL ,但是我宁愿让这个URL直接指向我已经在内存中存在的缓冲区。 上面引用的文档似乎暗示这是可能的,但我找不到任何提示。 我错过了什么吗?

URL编码iOS NSURL错误

在Firefox中打开的URL,桌面上的Chrome浏览器,在iPhone上的WebView中不打开。 这个URL据说是访问一个GET请求。 当创buildNSURL没有percentescaping的url不会得到生成。 当使用percentescape时,url会redirect到一个Bad url内容。 在桌面浏览器上使用不同的编码,而不是在iPhone上使用? 或移动Safari? 有没有不同的方式来编码在iOS中的URL,而不是使用 -stringByAddingPercentEscapesUsingEncoding -CFURLCreateStringByAddingPercentEscapes 从服务器生成不好的请求内容页面。 任何帮助将是非常好的,谢谢。 编辑: 生成的URL如下 http://something.test.com/iostest/index.html?{"a":"b"} pipe理认为,不编码大括号是造成iOS中的问题。 如在 NSString *tempUrlSting = (NSString *)CFBridgingRelease(CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault, (CFStringRef)tempURLA,CFSTR("{}"), CFSTR("\""), CFStringConvertNSStringEncodingToEncoding(NSUTF8StringEncoding))); NSURL *tempUrl=[NSURL URLWithString:tempUrlSting]; 如果不是在URL中对大括号进行编码,而是使用[Rob's answer] [1]对其余的进行编码,如上所述。 创buildNSURL时,url是空的。 如果对大括号进行编码,则生成的URL很好,但服务器会引发exception。 这个问题build议使用CFNetworking。 编辑 使用CFNetworking如下 -(void)getDataFromUrl{ CFStringRef tempURLA = CFSTR("http://my.test.server/iostest/index.html?{\"a\":\"b\"}"); CFStringRef tempUrlSting = CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault, (CFStringRef)tempURLA,CFSTR("{}"), CFSTR("\""), CFStringConvertNSStringEncodingToEncoding(NSUTF8StringEncoding)); CFURLRef myURL = CFURLCreateWithString(kCFAllocatorDefault, tempUrlSting, NULL); CFStringRef […]

在URL中使用编码“&”问题

我必须发送一个https GET请求到在Swift 1.2中开发的iPhone应用程序中的Web服务。 我试图构造查询string参数,但得到编码之前,发送到服务器。 当密码包含'&'字符时,所有好的但不工作。 预计将“&”字符编码为“%26”,但不能正常工作… 刚做了'%'的testing。 如预期的那样工作,'%'提供'%25'。 但不转换'&'标志…. 试过以下方法: var testPassword1: String = "mypassword&1" var testPassword2: String = "mypassword%1" // Try to encode 'testPassword1' testPassword1.stringByAddingPercentEscapesUsingEncoding(NSUTF8StringEncoding)! testPassword1.stringByAddingPercentEncodingWithAllowedCharacters(.URLHostAllowedCharacterSet())! // Try to encode 'testPassword2' testPassword2.stringByAddingPercentEscapesUsingEncoding(NSUTF8StringEncoding)! testPassword2.stringByAddingPercentEncodingWithAllowedCharacters(.URLHostAllowedCharacterSet())! 我已经完成了上面的testing,接下来是响应 想知道正确的方法来做到这一点。 谢谢。

UIImagePickerControllerReferenceURL总是返回nill

我试图从下面的代码中获取我刚刚从相机捕获的图像的名称。 但是[info objectForKey:@"UIImagePickerControllerReferenceURL"]总是返回nil。 我怎样才能得到的url? – (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info { self.myinfo = info; NSLog(@"Dismissing camera ui…"); [self.cameraUI dismissViewControllerAnimated:YES completion:nil]; NSLog(@"Getting media url…"); NSString *mediaURL = [info objectForKey:UIImagePickerControllerMediaURL]; NSLog(@"Media url = %@", mediaURL); NSLog(@"Getting media type…"); NSString *mediaType = [info objectForKey:UIImagePickerControllerMediaType]; NSLog(@"Selected mediaType: %@", mediaType); if(mediaURL) { NSLog(@"This is a video = %@", mediaURL); if (![mediaType […]

无法从NSString创buildNSUrl总是得到零

NSMutableString *string = [[NSMutableString alloc]initWithString: @"http%3A%2F%2Fsupport24hour.com%2Fworkplace2%2Fbuttler%2Fimage.php%3Fwidth%3D534%26height%3D256%26image%3Duploads%2Fdeals%2FdealImage%2Fdeal_1383005121_IGA+Logo.JPG"]; [string replaceOccurrencesOfString:@"+" withString:@" " options:NSCaseInsensitiveSearch range:NSMakeRange(0, [string length])]; NSURL * url = [NSURL URLWithString:[string stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];

如何从UIWebView获取URL的哈希片段

我试图得到URL加载在UIWebView哈希片段,我已经尝试了不同的方法,它似乎并没有工作。 例如,如果UIWebView加载“http://www.mysite.com/home#main”: NSURL *url = [NSURL URLWithString:@"http://www.mysite.com/home#main"]; NSURLRequest *request = [NSURLRequest requestWithURL:url]; [webView loadRequest:request]; 那么我想获得完整的url,但它只返回“http://www.mysite.com/home”3种不同的方法: 1: NSString *currentURL = [webView.request.URL absoluteString]; 2: NSString *currentURL = [NSString stringWithFormat:@"%@",[[webView request] URL]]; 3: NSString *currentURL = [webView stringByEvaluatingJavaScriptFromString:@"window.location.hash"]; 我错过了什么

iOS – 仅在修改时下载文件(NSURL和NSData)

我正在从服务器上下载一大堆图像文件,而且我想确保只有在更新的情况下才能下载它们。 这种方法目前下载图像就好了。 但是,我不想浪费时间或精力重新下载图像,每次用户login到应用程序。 相反,我只想下载任何文件A)不存在B)在服务器上比在设备上更新 这里是我如何下载图像:*图像的url是保存在核心数据与它关联的video。 该url是使用一个简单的转换方法生成的(generateThumbnailURL) -(void)saveThumbnails{ NSManagedObjectContext *context = [self managedObjectContextThumbnails]; NSError *error; NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init]; NSEntityDescription *entity = [NSEntityDescription entityForName:@"Videos" inManagedObjectContext:context]; [fetchRequest setEntity:entity]; NSArray *fetchedObjects = [context executeFetchRequest:fetchRequest error:&error]; NSLog(@"Videos: %i",fetchedObjects.count); if (fetchedObjects.count!=0) { for(Videos *currentVideo in fetchedObjects){ // Get an image from the URL below NSURL *thumbnailURL = [self […]

NSURLErrorDomain错误-1021

我正在开发一个应用程序,我集成了Dropbox。 login正确完成,我也能够在dropBox中创build文件夹。 但是,当我尝试加载文件,我得到错误 以下错误我越来越 error making request to /1/files_put/dropbox/Info.plist – Error Domain=NSURLErrorDomain Code=-1021 "The operation couldn't be completed. (NSURLErrorDomain error -1021.)" UserInfo=0x6859bc0 {destinationPath=/Info.plist, sourcePath=/Users/bcod/Library/Application Support/iPhone Simulator/5.0/Applications/0E1EE43C-8F6B-40FA-8696-D3992DA2DCE5/DBRoulette.app/Info.plist} 当我创build文件夹时,我没有收到这个错误。

将身份validation令牌从iOS应用程序发送到Safari

我的应用程序中有一些URL,通过openURL API将用户带到Safari浏览器。 我的目标是从应用程序发送身份validation令牌到Safari,以便用户将使用此令牌login。 我们的服务器要求将此票据作为标题信息的一部分发送。 有没有可能发送自定义标题与NSURL? 我已经检查了下面的链接,它讨论了查询组件,但是服务器没有处理它,他们更喜欢不同的解决scheme。 Android在外部浏览器中打开URL时有可能发送额外的头文件,所以现在每个人都在iOS上:-)。 在Safari中打开NSURLRequest 身份validation令牌保存在共享钥匙串中,Safari可以访问吗? 什么是推荐的解决scheme? 我是否需要使用共享Web凭证 ? 在这种情况下,我相信很多工作要做。 我没有用过