如何使用最新的iOS SDK在Pinterest中共享图像

问题描述 投票:5回答:3

我想在Pinterest中分享图片。我已经配置了没有CocoaPods的Pinterest iOS SDK。

我编写的代码让我重定向到Pinterest应用程序并获得授权。但在那之后我没有得到任何回应。

在以前版本的iOS SDK中,我们只需要传递该图像的URL。但现在它也在询问Board id。

我不知道如何获得电路板ID并在Pinterest中共享图像,因为我没有从成功块中获得任何响应。

这是我正在使用的代码。

[[PDKClient sharedInstance] authenticateWithPermissions:[NSArray arrayWithObjects:PDKClientReadPublicPermissions, nil] withSuccess:^(PDKResponseObject *responseObject) {  

        NSLog(@"Response Object:%@",responseObject);

    } andFailure:^(NSError *error) {

        NSLog(@"Error:%@",error);
}];

我正在尝试过去一周。请建议我在哪里犯错误。

谢谢。

ios objective-c pinterest
3个回答
3
投票

我解决了这个问题,我想感谢帮助我的人。现在,我可以在Pinterest中分享图像。我已经从这个Github链接https://github.com/pinterest/ios-pdk中引用了示例应用程序来分享Pinterest中的图像。这是我遵循的步骤。

1)我使用Cocoapods安装了Pinterest SDK。

2)我在didFinishLaunchingWithOptions添加了以下行

[PDKClient configureSharedInstanceWithAppId:@"1234566"];

3)我在AppDelegate.m文件中添加了以下两个函数

- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url
{
    return [[PDKClient sharedInstance] handleCallbackURL:url];
}

- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary *)options
{
    return [[PDKClient sharedInstance] handleCallbackURL:url];
}

4)我在图像共享按钮操作中添加了以下代码。

[PDKPin pinWithImageURL:[NSURL URLWithString:@"https://about.pinterest.com/sites/about/files/logo.jpg"] link:[NSURL URLWithString:@"https://www.pinterest.com"]
                   suggestedBoardName:@"Testing" note:@"The Pinterest Logo" withSuccess:^
               {
                   // weakSelf.resultLabel.text = [NSString stringWithFormat:@"successfully pinned pin"];
               }
                           andFailure:^(NSError *error)
               {
                   //weakSelf.resultLabel.text = @"pin it failed";
                   NSLog(@"Error:%@",error);

               }];

1
投票

您可以使用Pinterest api通过以下代码获取电路板信息:

PDKClient.sharedInstance().getAuthenticatedUserBoardsWithFields(NSSet(array: ["id","image","description","name"]) as Set<NSObject>, success: { 
(responseObject: PDKResponseObject!) -> Void in

        self.currentResponseObject = responseObject
        self.boardsArray = responseObject.boards()

        print("self.boards are \(self.boardsArray)") //Contains identifiers(board-id) which is used for image sharing

        })
        {
            (err :NSError!) -> Void in
            print("e rror NSError: \(err)")
            self.hideHUD()
    }

0
投票
#import <PinterestSDK/PDKPin.h>

-(void)shareOnPinterestUsingSDKWithText:(NSString*)text andURL:(NSURL*)imageUrl Image:(UIImage*)imagePinterest completionHandler:(void (^)(BOOL completed))completion{

    [PDKPin pinWithImageURL:imageUrl link:imageUrl suggestedBoardName:@"" note:text withSuccess:^{
        NSLog(@"success");
        completion(true);
    } andFailure:^(NSError *error) {
        NSLog(@"error %@", error);
        completion(false);
    }];
}


TODO:- 

1) Install SDK using cocopods

pod 'PinterestSDK', '~> 1.0'

2) Add pinterest app id in Appdelegate

static NSString* const kPinterestAppId = @“{PINTEREST_ID}”;

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{

[PDKClient configureSharedInstanceWithAppId: kPinterestAppId];
Return true;
}

3) Add pinterest key in info.plist

<key>CFBundleURLTypes</key>
    <array>
        <dict>
            <key>CFBundleURLName</key>
            <string>${BUNDLE_IDENTIFIER}</string>
            <key>CFBundleURLSchemes</key>
            <array>
                <string>${APP_URL_SCHEME}</string>
                <string>pdk${PINTEREST_ID}</string>
            </array>
        </dict>
    </array>

===========================================================

<key>LSApplicationQueriesSchemes</key>
    <array>
    <string>pinterestsdk.v1</string>
    </array>

===========================================================

    <key>PinterestAppId</key>
    <string>${PINTEREST_ID}</string>

===========================================================

4) For handling callback when pinterest sharing done and control return to app

-(BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options
{
    NSString *pinterestKey = [[[NSBundle mainBundle] infoDictionary] valueForKey:@"PinterestAppId"];
    if (pinterestKey && ![pinterestKey isKindOfClass:[NSNull class]])
    {
        pinterestKey = [NSString stringWithFormat:@"pdk%@", pinterestKey];
        if ([urlStr rangeOfString:pinterestKey].location != NSNotFound)
        {
            return [[PDKClient sharedInstance] handleCallbackURL:url];
        }
    }
}
© www.soinside.com 2019 - 2024. All rights reserved.