0

I'm using following code to get the NSURL from NSString but I always get NSURL as null :

NSString *CFURL = (NSString *)CFBridgingRelease(CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault,(CFStringRef)[assetURL absoluteString], NULL, CFSTR("!$&'()*+,-./:;=?@_~"), kCFStringEncodingUTF8));

NSString *instagramString = [NSString stringWithFormat:@"instagram://library?AssetPath=%@&InstagramCaption=%@", (NSURL *)CFURL, strInstagramCaption];

NSURL *instagramURL = [NSURL URLWithString:instagramString];
halfer
  • 19,824
  • 17
  • 99
  • 186
Vaibhav Jhaveri
  • 1,579
  • 3
  • 28
  • 53
  • The question is lacking enough information to answer, in particular missing are: `assetURL` and `strInstagramCaption`. Also instead of using `CFURLCreateStringByAddingPercentEscapes` See this: [SO Answer](http://stackoverflow.com/a/8086845/451475) for using `stringByAddingPercentEncodingWithAllowedCharacters:`. – zaph Jun 01 '15 at 11:37
  • @zaph is wrong ! Already answered here:- http://stackoverflow.com/questions/30566795/create-nsurl-using-assetpath – Vizllx Jun 01 '15 at 12:29
  • Nice link the a correct solution and a reference to another answer. Wondering what part of the comment is wrong? – zaph Jun 01 '15 at 13:08
  • Great complete blog post on sharing a video to Instagram: [horison blog](http://blog.horizon.camera/post/102273431070/video-share-objc-ios-instagram) – zaph Jun 01 '15 at 13:15

1 Answers1

1

NSURL does not natively support the instagram protocol. Here are the supported protocols.

The URL loading system provides support for accessing resources using the following protocols:

File Transfer Protocol (ftp://)

Hypertext Transfer Protocol (http://)

Hypertext Transfer Protocol with encryption (https://)

Local file URLs (file:///) Data URLs (data://)

As stated in the documentation, you will have to create a custom protocol.

Community
  • 1
  • 1
Michael
  • 6,561
  • 5
  • 38
  • 55
  • Can you please help me convert the `instagramString` into `instagramURL` ? – Vaibhav Jhaveri Jun 01 '15 at 05:47
  • While this is true for the URL loading system it is not true for just creating a URL, this will create a URL: `NSURL *instagramURL = [NSURL URLWithString:@"instagram://library?AssetPath=qqq"];` – zaph Jun 01 '15 at 11:39