我正在将图像文件上传到FTP,在上传之前我需要检查天气它是png还是jpg,如果没有,我应该发出警告提醒,我尝试这样做,但它是扔警告虽然它是一个jpg的jpg如何检查这种情况
NSLog(@"%@",filePath.pathExtension);
if( ![filePath.pathExtension isEqualToString:@"png"] || ![filePath.pathExtension isEqualToString:@"jpg"] || ![filePath.pathExtension isEqualToString:@"PNG"] ||![filePath.pathExtension isEqualToString:@"JPG"] )
{
UIAlertView *alert = [[[UIAlertView alloc]initWithTitle:@"Warning" message:@"Image should be in png or jpg format to upload" delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil, nil]autorelease];
[alert show];
}
答案 0 :(得分:3)
您应该将||
替换为&&
,否则条件始终为真(扩展名不能同时为@"png"
和@"jpg"
,这就是要评估为false
的OR-ed条件。
答案 1 :(得分:1)
为什么你要为png,PNG和jpg,JPEG做,只需改成小写字母
NSString *str = [filePath.pathExtension lowercaseString];
if (![str isEqualToString:@"png"] && ![str isEqualToString:@"jpg"])
{
//Your Alert
}
else{
//Your Task
}