Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/42.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
比较两个URL(iPhone)_Iphone - Fatal编程技术网

比较两个URL(iPhone)

比较两个URL(iPhone),iphone,Iphone,朋友们好,我想比较xcode中的两个URL(目标c) 怎么可能呢??? -(IBAction) download{ NSURL *url1 = [NSURL URLWithString:@"http://www.google.com/images?hl=en&q=flowers&bav=on.1,or.&um=1&ie=UTF-8&source=og&sa=N&tab=wi&biw=1512&bih=677"]; NSURL

朋友们好,我想比较xcode中的两个URL(目标c) 怎么可能呢???

-(IBAction) download{
NSURL *url1 = [NSURL URLWithString:@"http://www.google.com/images?hl=en&q=flowers&bav=on.1,or.&um=1&ie=UTF-8&source=og&sa=N&tab=wi&biw=1512&bih=677"];
NSURL *url2 = [NSURL URLWithString:@"http://www.google.com/imgres?imgurl=http://www.missouriplants.com/Yellowopp/Helianthus_divaricatus_flowers.jpg&imgrefurl=http://www.missouriplants.com/Yellowopp/Helianthus_divaricatus_page.html&usg=__W-J2oEuDpbxhlU4plpC3JHP3wU0=&h=449&w=450&sz=41&hl=en&start=0&zoom=1&tbnid=axuO9VsiGsWlCM:&tbnh=131&tbnw=134&ei=h9tsTebwLc3irAeW1Kz7Bg&prev=/images%3Fq%3Dflowers%26um%3D1%26hl%3Den%26sa%3DN%26biw%3D1512%26bih%3D677%26tbs%3Disch:1&um=1&itbs=1&iact=rc&dur=426&oei=h9tsTebwLc3irAeW1Kz7Bg&page=1&ndsp=33&ved=1t:429,r:0,s:0&tx=57&ty=98"]; 
url = [webView.request URL];    
NSLog(@"urlrecieved  .............................. %@", url);
NSLog(@"urlrecieved 1 ............................. %@", url1);
NSLog(@"urlrecieved  2.............................. %@", url2);

if([url isEqualToString:url1])  
{
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"warning" message:@"select an image" delegate:nil cancelButtonTitle:@"ok" otherButtonTitles:nil];
    [alert show];
    [alert release];
}
else if([url isEqualToString:url2])
{
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"warning" message:@"select an image" delegate:nil cancelButtonTitle:@"ok" otherButtonTitles:nil];
    [alert show];
    [alert release];
}   
else
{       
NSLog(@"Downloading...");
NSLog(@"url recieved: %@", url);
UIImage *image = [[UIImage alloc] initWithData:[NSData dataWithContentsOfURL:url]];
NSLog(@"%f,%f",image.size.width,image.size.height);
NSString *docDir = @"/Users/gauravmurghai/Desktop";
// If you go to the folder below, you will find those pictures
    NSLog(@"%@",docDir);
    NSLog(@"saving png");
//  NSString *pngFilePath = [NSString stringWithFormat:@"%@/neetu%d.png",docDir , r];
//      r++;

    NSString *pngFilePath = [NSString stringWithFormat:@"%@/flower.png",docDir];
    NSData *data1 = [NSData dataWithData:UIImagePNGRepresentation(image)];
    [data1 writeToFile:pngFilePath atomically:YES];
    [image release];
}

}

实际上,要绝对确保两个URL是相同的,需要做一些工作。看看这篇博文,它解释了更多


iOS对象层次结构的基类NSObject有一个由子类覆盖的isEqual方法,以提供相等性检查。NSUrl将提供它自己的实现,因此您不必担心转换为NSString来执行比较

NSURL *url1 = [NSURL URLWithString:@"http://www.google.com"];
NSURL *url2 = [NSURL URLWithString:@"http://www.google.com"];
if ([url1 isEqual:url2]) {
......

平视-两个NSURL可以指向同一资源,但由于使用了前缀(文件://),所以不能是字符对字符相等的,file://localhost/). 这把我绊倒了,引起了一个错误。对于我的解决方案,请比较
lastPathComponent
absolutePath