How to integrate Pinterest in ios application

2019-03-08 06:43发布

问题:

I want to integrate pinterest in my application. i want to add button of pinterest in my app through which i can upload image on pinterest I refer their Developers site but it doesnt help me.

I include SDK and tried their code but it doesnt work for me.

  #import <Pinterest/Pinterest.h>

UIButton* pinItButton = [Pinterest pinItButton];
    [pinItButton addTarget:self
                    action:@selector(pinIt:)
          forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:pinItButton];

 - (void)pinIt:(id)sender
    {
        [_pinterest createPinWithImageURL:@"http://placekitten.com/500/400"
                                sourceURL:@"http://placekitten.com"
                              description:@"Pinning from Pin It Demo"];
    }

please any help will be appreciated.

Thanks in advance.

回答1:

I dont understand whats your actual problem but here i provide some easy step to integrate pinterest to your app

step : 1 Register for a Client ID from here

step : 2 Download the SDK from here and drag and drop into your project.

step : 3 You will then need to add a URL type to support opening your app from the Pinterest app , so add URL type to your plist file

Example if your client id is 18571937652947:
pin18571937652947 is the URL Scheme you need to support.

step : 4 To use the Pinterest framework you will need to import it into your file.

 #import <Pinterest/Pinterest.h>

and declare its object in your .h file

 Pinterest *pinterest

step : 5 initialise Pinterest object

 pinterest = [[Pinterest alloc]initWithClientId:@"your app client id"]

step : 6 To use the standard PinIt Button in a view add it as so:

 UIButton* pinItButton = [Pinterest pinItButton];
    [pinItButton addTarget:self
                    action:@selector(pinIt:)
          forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:pinItButton];

step : 7 You will need to handle the action an example of this is below:

- (void)pinIt:(id)sender
{
    NSURL *imageURL     = [NSURL URLWithString:@"http://placekitten.com/500/400"];
    NSURL *sourceURL    = [NSURL URLWithString:@"http://placekitten.com"];


    [pinterest createPinWithImageURL:imageURL
                           sourceURL:sourceURL
                         description:@"Pinning from Pin It Demo"];
}

Note : pinterest app should be installed in your device otherwise this code redirect to itunes to download pinterest app