title: Pinterest integration in ios app?
body: <p>I am trying to post image from my app on pinterest.From last five days i am looking for perfect solution finally after posting some question on SO now i am inch away to solve my problem.the issue is when i post any image using url its successfuly post my image on pinterest as my below code show.</p>
  
  <pre><code>-(NSString*) generatePinterestHTML {
  NSString *description = @"Post your description here";
  NSString *sUrl = [NSString stringWithFormat:@"http://4.bp.blogspot.com/-w4oTZjlpgwo/T5_pi-KJPuI/AAAAAAAAAoM/rKm3E0XCbgY/s1600/flower.png"];
  NSLog(@"URL:%@", sUrl);
  NSString *protectedUrl = (__bridge NSString *)CFURLCreateStringByAddingPercentEscapes(NULL,(__bridge CFStringRef)sUrl, NULL, (CFStringRef)@"!'\"();:@&amp;=+$,/?%#[]% ",CFStringConvertNSStringEncodingToEncoding(NSUTF8StringEncoding));
  NSLog(@"Protected URL:%@", protectedUrl);
  NSString *imageUrl = [NSString stringWithFormat:@"\"%@\"", sUrl];
  NSString *buttonUrl = [NSString stringWithFormat:@"\"http://pinterest.com/pin/create/button/?url=www.flor.com&amp;media=%@&amp;description=%@\"", protectedUrl, description];
  
  NSMutableString *htmlString = [[NSMutableString alloc] initWithCapacity:1000];
  [htmlString appendFormat:@"&lt;html&gt; &lt;body&gt;"];
  [htmlString appendFormat:@"&lt;p align=\"center\"&gt;&lt;a href=%@ class=\"pin-it-button\" count-layout=\"horizontal\"&gt;&lt;img border=\"0\" src=\"http://assets.pinterest.com/images/PinExt.png\" title=\"Pin It\" /&gt;&lt;/a&gt;&lt;/p&gt;", buttonUrl];
  [htmlString appendFormat:@"&lt;p align=\"center\"&gt;&lt;img width=\"400px\" height = \"400px\" src=%@&gt;&lt;/img&gt;&lt;/p&gt;", imageUrl];
  [htmlString appendFormat:@"&lt;script type=\"text/javascript\" src=\"//assets.pinterest.com/js/pinit.js\"&gt;&lt;/script&gt;"];
  [htmlString appendFormat:@"&lt;/body&gt; &lt;/html&gt;"];
  return htmlString;
  }
  -(void)viewDidLoad
  {
   [super viewDidLoad];
  NSString *htmlString = [self generatePinterestHTML];
  NSLog(@"Generated HTML String:%@", htmlString);
  mywebview.backgroundColor = [UIColor clearColor];
  mywebview.opaque = NO;
  if ([mywebview isHidden]) {
      [mywebview setHidden:NO];
  }
  [mywebview loadHTMLString:htmlString baseURL:nil];
  }
  </code></pre>
  
  <p>below screen shot show my above code result</p>
  
  <p><img src="https://i.stack.imgur.com/y7gXu.png" alt="enter image description here"><img src="https://i.stack.imgur.com/lHFAh.png" alt="enter image description here"></p>
  
  <p>But when i am trying to upload image from my app  its not works fine here is my code </p>
  
  <pre><code> - (void)viewDidLoad
   {
   NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES);
  NSString *documentsDirectory = [paths objectAtIndex:0];
  savedImagePath = [[documentsDirectory stringByAppendingPathComponent:@"savedImage.png"] mutableCopy];
  NSLog(@"savedImagePath..%@",savedImagePath);
  NSData*  imageData = UIImagePNGRepresentation(mypimage);
  [imageData writeToFile:savedImagePath atomically:YES];
  [super viewDidLoad];
  NSString *htmlString = [self generatePinterestHTML];
  NSLog(@"Generated HTML String:%@", htmlString);
  mywebview.backgroundColor = [UIColor clearColor];
  mywebview.opaque = NO;
  if ([mywebview isHidden]) {
      [mywebview setHidden:NO];
  }
  [mywebview loadHTMLString:htmlString baseURL:nil];
  }
  - (NSString*) generatePinterestHTML {
  NSString *description = @"Post your description here";
  NSString *stringUrl = [NSString stringWithFormat:@"%@",savedImagePath];
  NSLog(@"stringUrl:%@", stringUrl);
  NSURL *urlToUpload = [[NSURL alloc]initFileURLWithPath:stringUrl];
  NSString* sUrl = [NSString stringWithFormat:@"%@",urlToUpload];
  NSString *protectedUrl = (__bridge NSString *)CFURLCreateStringByAddingPercentEscapes(NULL,(__bridge CFStringRef)sUrl, NULL, (CFStringRef)@"!'\"();:@&amp;=+$,/?%#[]% ",CFStringConvertNSStringEncodingToEncoding(NSUTF8StringEncoding));
  NSLog(@"Protected URL:%@", protectedUrl);
  NSString *imageUrl = [NSString stringWithFormat:@"\"%@\"", sUrl];
  NSString *buttonUrl = [NSString stringWithFormat:@"\"http://pinterest.com/pin/create/button/?url=www.flor.com&amp;media=%@&amp;description=%@\"", protectedUrl, description];
  
  NSMutableString *htmlString = [[NSMutableString alloc] initWithCapacity:1000];
  [htmlString appendFormat:@"&lt;html&gt; &lt;body&gt;"];
  [htmlString appendFormat:@"&lt;p align=\"center\"&gt;&lt;a href=%@ class=\"pin-it-button\" count-layout=\"horizontal\"&gt;&lt;img border=\"0\" src=\"http://assets.pinterest.com/images/PinExt.png\" title=\"Pin It\" /&gt;&lt;/a&gt;&lt;/p&gt;", buttonUrl];
  [htmlString appendFormat:@"&lt;p align=\"center\"&gt;&lt;img width=\"400px\" height = \"400px\" src=%@&gt;&lt;/img&gt;&lt;/p&gt;", imageUrl];
  [htmlString appendFormat:@"&lt;script type=\"text/javascript\" src=\"//assets.pinterest.com/js/pinit.js\"&gt;&lt;/script&gt;"];
  [htmlString appendFormat:@"&lt;/body&gt; &lt;/html&gt;"];
  return htmlString;
  }
  </code></pre>
  
  <p>For above code my screen shot result is 
  <a href="http://tinypic.com/view.php?pic=118mumu&amp;s=6" rel="nofollow noreferrer">link1</a><a href="http://tinypic.com/view.php?pic=2h7p8ar&amp;s=6" rel="nofollow noreferrer">link2</a> so please suggest any method to reslove this problem.Thanks</p>