Search code examples
iosnsurl

Is there a way to know whether NSURL points to a remote server or to an assets library on a user's device?


I have a data abstraction, which uses NSURL pointing to a video asset, which is either located locally on the device, or on a remote server.

How can I universally know, if it's a remote server asset or a local one? (I am fetching preview image for it, with 2 different methods)


Solution

  • NSURL has a -scheme method, which returns an NSString.

    Using this, you can check for 'http' or 'file' scheme using string comparison.

    There is also the -isFileReferenceURL method which will tell you if it is a file reference or not.

    [EDIT] as rmaddy points out in the comments, you should probably check for 'assets-library' scheme too.