2013-02-01 15 views
5

मैं this लिंक का उपयोग Pinterest पर पोस्ट करना चाहते हैं, लेकिन मैं अपने आवश्यकता यहाँ के अनुसार लिटिल बिट कोडिंग बदल मेरी MainClass कोड हैPinterest पर छवि कैसे पोस्ट करें?

- (void)pInterest { 
     UIImage *myImage; 
     myImage=imgView.image; 
     WebViewController *webViewController = [[WebViewController alloc] initWithNibName:@"WebViewController" bundle:nil]; 
     webViewController.mypimage = myImage; 
    [[[[UIApplication sharedApplication] keyWindow] rootViewController] presentModalViewController:webViewController animated:YES]; 
} 

तो मेरी WebViewController करने के लिए छवि पास करने के बाद अब मेरी WebViewController वर्ग कोड

है
- (void)viewDidLoad { 
    //imageview.image=mypimage; 
    [super viewDidLoad]; 
    NSString *description = @"Post your description here"; 

    // Generate urls for button and image 
    NSString *sUrl = [NSString stringWithFormat:@"http://d30t6wl9ttrlhf.cloudfront.net/media/catalog/product/Heros/mypimage"]; 
    // NSLog(@"URL:%@", sUrl); 
    NSString *protectedUrl = (__bridge NSString *)CFURLCreateStringByAddingPercentEscapes(NULL,(__bridge CFStringRef)sUrl, NULL, (CFStringRef)@"!*'\"();:@&=+$,/?%#[]% ",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&media=%@&description=%@\"", 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=\"http://assets.pinterest.com/images/PinExt.png\" 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=\"//assets.pinterest.com/js/pinit.js\"></script>"]; 
    [htmlString appendFormat:@"</body> </html>"]; 
    [mywebview setBackgroundColor:[UIColor clearColor]]; 
    [mywebview loadHTMLString:htmlString baseURL:nil]; 
    [mywebview setOpaque:NO]; 
} 

जब मैं कोडिंग मेरी वेबव्यू कोई छवि दिखाने के ऊपर का उपयोग करें और मेरे वेब दृश्य की तरह नीचे screenshow लग रहा है enter image description hereenter image description here

जब मैं WebViewController में छवि दृश्य में एक ही छवि उदाहरण असाइन करता हूं तो इसकी कार्यशील imageview.image = mypimage;

तो क्या कोई मुझे सुझाव दे सकता है कि क्यों मेरा वेबवीव छवि नहीं दिखाता है.धन्यवाद।

+1

मुझे कहना चाहिए कि यह एक उचित बटन यूआरएल नहीं है। कृपया यह सुनिश्चित करने का प्रयास करें कि उस संसाधन के लिए यूआरएल मौजूद है जिसे आप वास्तव में प्रश्न पोस्ट करने से पहले लोड करने का प्रयास कर रहे हैं। –

+0

जब मैं पिनशॉट बटन पर क्लिक करता हूं जो पहले स्क्रीनशॉट पर होता है तो यह दूसरा स्क्रीनशॉट खोलता है जिसका मतलब है कि url के बारे में कोई समस्या नहीं है। इसलिए केवल समस्या यह है कि यह मेरी छवि को पास नहीं करता है। – jamil

उत्तर

8

इस कोड का उपयोग करें ...... उम्मीद है कि यह आपकी मदद करेगा।

- (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://4.bp.blogspot.com/-w4oTZjlpgwo/T5_pi-KJPuI/AAAAAAAAAoM/rKm3E0XCbgY/s1600/red_rose_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:@"\"http://pinterest.com/pin/create/button/?url=www.flor.com&media=%@&description=%@\"", 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=\"http://assets.pinterest.com/images/PinExt.png\" 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=\"//assets.pinterest.com/js/pinit.js\"></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]; 
} 
+1

डुप्लिकेट के रूप में आपकी आखिरी पोस्ट को ध्वजांकित किया गया था और मॉडरेटर द्वारा हटा दिया गया था, इसलिए मेरा मुआवजा, + 1. कृपया उत्तर के रूप में लिंक पोस्ट न करें। –

+0

@MicRO ठीक है और धन्यवाद ...... :) –

+0

@MicRO धन्यवाद ... :) –

7

एक जवाब पोस्ट करने से पहले, मैं जो मुझे यह विचार है कि सर्वर पर चित्र पोस्ट के बिना हम स्थानीय छवि ऐप्लिकेशन से सीधे Pinterest पर पोस्ट नहीं कर सकते दिया @Sudha करने के लिए विशेष धन्यवाद देना चाहते हैं। इसलिए जब मैंने सर्वर पर छवियों को पोस्ट किया और बटन को पिन करने के लिए उपयुक्त यूआरएल पता सौंपा, तो इस तरह से विचार में आगे बढ़ना, फिर यह मेरे लिए काम किया। चीयर्स! जब मैंने पिन रुचि के साथ आईओएस ऐप एकीकरण के बारे में खोज शुरू की, तो मुझे इस संबंध में बहुत कम मदद और सामग्री मिली। मुझे लगता है कि अधिकांश डेवलपर्स this विधि का उपयोग करते थे, लेकिन जब मैंने उपरोक्त उद्धृत विधि का उपयोग किया तो उसने अपनी स्थानीय ऐप छवियों को पिन रुचि पर पोस्ट नहीं किया। अंत में, मैं उन लोगों के लिए अपना उत्तर पोस्ट करना चाहता हूं जो पिन पर रुचि से स्थानीय छवियों को पोस्ट करने की अधिक संभावना रखते हैं।

कदम

  1. एक नया वर्ग WebViewController बनाएँ और निम्नलिखित बातें जोड़ें।

    #import <UIKit/UIKit.h> 
    
    @interface WebViewController : UIViewController 
    { 
    IBOutlet UIActivityIndicatorView *UIHelper; 
    IBOutlet UIWebView *mywebview; 
    UIImage *mypimage; 
    } 
    @property(nonatomic,retain)UIActivityIndicatorView *UIHelper; 
    @property(nonatomic,retain)UIWebView *mywebview; 
    @property(nonatomic,retain) UIImage *mypimage; 
    -(IBAction)closeClicked:(id)sender ; 
    @end 
    
  2. अब WebViewController.m फ़ाइल कोड

    #import "WebViewController.h" 
    
    @interface WebViewController() 
    
    @end 
    
    @implementation WebViewController 
    @synthesize UIHelper,mypimage,mywebview; 
    NSString *username; 
    
    -(IBAction)closeClicked:(id)sender { 
    [self dismissModalViewControllerAnimated:YES]; 
    } 
    - (void)webViewDidStartLoad:(UIWebView *)webView { 
        [UIHelper startAnimating]; 
        } 
    -(void)webViewDidFinishLoad:(UIWebView *)webView { 
    [UIHelper stopAnimating]; 
        } 
    - (void)viewDidLoad 
    { 
        username = @"j&D"; 
    [username retain]; 
    
    NSData *imageData = UIImageJPEGRepresentation(mypimage, 90); 
    NSString *urlString = @"ServerURl/cap.php"; 
    NSMutableURLRequest *request = [[[NSMutableURLRequest alloc] init] autorelease]; 
    [request setURL:[NSURL URLWithString:urlString]]; 
    [request setHTTPMethod:@"POST"]; 
    NSString *boundary = @"---------------------------14737809831466499882746641449"; 
    NSString *contentType = [NSString stringWithFormat:@"multipart/form-data; boundary=%@",boundary]; 
    [request addValue:contentType forHTTPHeaderField: @"Content-Type"]; 
    NSMutableData *body = [NSMutableData data]; 
    [body appendData:[[NSString stringWithFormat:@"\r\n--%@\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]]; 
    [body appendData:[[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"userfile\"; filename=\"%@.jpg\"\r\n",username] dataUsingEncoding:NSUTF8StringEncoding]]; 
    [body appendData:[@"Content-Type: application/octet-stream\r\n\r\n" dataUsingEncoding:NSUTF8StringEncoding]]; 
    [body appendData:[NSData dataWithData:imageData]]; 
    [body appendData:[[NSString stringWithFormat:@"\r\n--%@--\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]]; 
    [request setHTTPBody:body]; 
    NSData *returnData = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil]; 
    NSString *returnString = [[NSString alloc] initWithData:returnData encoding:NSUTF8StringEncoding]; 
        NSLog(@"serverurl :%@",returnString); 
    
        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]; 
        [super viewDidLoad]; 
        } 
        - (NSString*) generatePinterestHTML { 
         NSString *description = @"Post your description here"; 
         NSString *sUrl = [NSString stringWithFormat:@"SerVerUrl/cap/j&D.jpg"]; 
         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:@"\"http://pinterest.com/pin/create/button/?url=www.flor.com&media=%@&description=%@\"", 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=\"http://assets.pinterest.com/images/PinExt.png\" 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=\"//assets.pinterest.com/js/pinit.js\"></script>"]; 
         [htmlString appendFormat:@"</body> </html>"]; 
         return htmlString; 
         } 
         @end 
    
  3. एक विधि बनाएं कॉल करने के लिए जब उपयोगकर्ता अपने "Pinit" बटन, जो दिखाता है कि छवि के साथ WebView, जिन्हें आप पोस्ट और होगा टैप करता UIWebView पर "पिनिट" बटन। अपने सर्वर यूआरएल साथ serverURL बदलें उपरोक्त कोड में:

    -(void)pInterest 
    { 
        UIImage *myImage; 
        myImage=imgView.image; 
        WebViewController *webViewController = [[WebViewController alloc] initWithNibName:@"WebViewController" bundle:nil]; 
        webViewController.mypimage = myImage; 
        [[[[UIApplication sharedApplication] keyWindow] rootViewController] presentModalViewController:webViewController animated:YES]; 
    } 
    

    नोट: यह मेरी कोड है।

अंत में वर्णन स्पष्ट करने के लिए, मैं प्रदान की है कुछ स्क्रीनशॉट किसी भी अस्पष्टता और गलतफहमी पैदा हो सकता दूर करने के लिए।

enter image description hereenter image description hereenter image description here

किसी भी प्रश्न के लिए, टिप्पणी करने के लिए संकोच न करें!

+1

धन्यवाद @ बॉब ऐप्पल –

+0

बॉब ऐप्पल और सुधा मेरे विचार में साझा करने के लिए फिट करने का कोई तरीका है जिसका अर्थ है साझा करने के लिए 320X480 में ? –

+0

हाँ आप इसे साझा कर सकते हैं @ NikunjR.Jadav – jamil

0

आप तथापि the Pinterest iOS SDK

Pinterest *_pinterest = [[Pinterest alloc] initWithClientId:pinterestKey]; 
[_pinterest createPinWithImageURL:@"http://placekitten.com/500/400" 
         sourceURL:@"http://placekitten.com" 
         description:@"Pinning from Pin It Demo"]; 

इसके लिए उपयोग कर सकते हैं, आप डिवाइस पर Pinterest एप्लिकेशन की आवश्यकता होगी।

+0

मुझे पिन रुचि पर छवियों को अपलोड करने के लिए यूआरएल नहीं है, पिन रुचि पर गैलरी छवि कैसे अपलोड करें ... –

संबंधित मुद्दे