codelover
codelover

Reputation: 1139

How to decide if the URL is local file path or Remote file path

I am getting a scenario where the file may be uploaded to the server so that time the path will be like file://some path starting with /somepath .../ which i convert using NSURL urlWithFilePath to server.

Once the server have the file there is a mechanism where I download that contents and get the remote path like http:// for the same file.

Now decision is when I tap on the image I want to decide to open this in full screen , but before that have to device whether to apply [NSURL URLWithString] or [NSURL fileURLPath].

Any guess how to detect this before applying to open image correctly.

Upvotes: 0

Views: 1813

Answers (1)

codelover
codelover

Reputation: 1139

Adding a Category "NSString+URL.m" Class

-(NSURL*)url
{
   NSURL *myURL;
 if ([self.lowercaseString hasPrefix:@"http://"] || [self.lowercaseString hasPrefix:@"https://"] || [self.lowercaseString hasPrefix:@"file://"]) {
    myURL = [NSURL URLWithString:self];
}
else 
 {
    //Default consider it file url path 
    myURL = [NSURL fileUrlWithPath:self];
 }
return myURL;
}

Upvotes: -2

Related Questions