Arbaz Shaikh Arbaz Shaikh - 1 year ago 66
iOS Question

Login with pinterest in iOS

There is an explanation for pin in Pinterest for developers.

But I still have got the two following questions:

  • How to log in?

  • How to get a response of logged in user from the server after logging in?

I have gone through towards all demo available on google & stack overflow ,all they explain by using web view. but using web view, we can't get response of logged in user and in some Demo they have explained just how to pin it ?

In my app, I want login with pinterest.

Any help with the questions would be greatly appreciated.

Answer Source

The SDK provided by Pinterest You cannot login,but you can Pin images with it.there is no api available for the Pinterest logging so you not get the any response. you pin on the Pinterest using the below code.

- (IBAction)pinit:(id)sender {
    [self postToPinterest];

- (IBAction)closeWebVIew:(id)sender {
    [webViewPinterest setHidden:YES];

- (NSString*) generatePinterestHTML {
   NSString *description = @"Post your description here";
 NSURL* sUrl = [NSString stringWithFormat:@"http://flower3.jpg"];// pass your link here with your image name

    NSLog(@"URL:%@", sUrl);
   NSString *protectedUrl = ( NSString *)CFURLCreateStringByAddingPercentEscapes(NULL,( CFStringRef)sUrl, NULL, (CFStringRef)@"!*'\"();:@&=+$,/?%#[]% ",CFStringConvertNSStringEncodingToEncoding(NSUTF8StringEncoding));
    NSLog(@"Protected URL:%@", protectedUrl);
    NSString *imageUrl = [NSString stringWithFormat:@"\"%@\"", sUrl];
    NSString *buttonUrl = [NSString stringWithFormat:@"\"\"", protectedUrl, description];

    NSMutableString *htmlString = [[NSMutableString alloc] initWithCapacity:1000];
    [htmlString appendFormat:@"<html> <body>"];
    [htmlString appendFormat:@"<p align=\"center\"><a href=%@ class=\"pin-it-button\" count-layout=\"horizontal\"><img border=\"0\" src=\"\" title=\"Pin It\" /></a></p>", buttonUrl];
    [htmlString appendFormat:@"<p align=\"center\"><img width=\"400px\" height = \"400px\" src=%@></img></p>", imageUrl];
    [htmlString appendFormat:@"<script type=\"text/javascript\" src=\"//\"></script>"];
    [htmlString appendFormat:@"</body> </html>"];
    return htmlString;

- (void) postToPinterest {
    NSString *htmlString = [self generatePinterestHTML];
    NSLog(@"Generated HTML String:%@", htmlString);
    webViewPinterest.backgroundColor = [UIColor clearColor];
    webViewPinterest.opaque = NO;
    if ([webViewPinterest isHidden]) {
        [webViewPinterest setHidden:NO];
    [webViewPinterest loadHTMLString:htmlString baseURL:nil];
    //[webViewPinterest loadHTMLString:@"<img src=images.png>" baseURL:nil];

- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
    return YES;

- (void)webViewDidStartLoad:(UIWebView *)webView {
    [busyIndicator startAnimating];

-(void)webViewDidFinishLoad:(UIWebView *)webView {
    [busyIndicator stopAnimating];