您可以使用下面的代碼來檢查如果文件存在服務器上或不存在
NSURLRequest* request = [NSURLRequest requestWithURL:[NSURL URLWithString:url]
cachePolicy:NSURLRequestUseProtocolCachePolicy
timeoutInterval:5.0];
NSHTTPURLResponse *response = nil;
__autoreleasing NSError *error = nil;
[NSURLConnection sendSynchronousRequest:request
returningResponse:&response
error:&error];
if (error)
DLog(@"[%@ %@] %@ (%@)",
NSStringFromClass([self class]),
NSStringFromSelector(_cmd),
[error localizedDescription],
[error localizedFailureReason]);
else
{
if ([response statusCode] == 404)
{
NSLog(@"File Doesn't exist");
}
else
{
NSLog(@"File exist");
}
}
我試試立即 – Harry
它對你有用嗎? –
是的,你是如此強大,並且對我非常感謝,非常感謝! – Harry