3

我正在尝试浏览Pinterest 网站上的基本教程。

下载文档和 iOS sdk 的链接不提供文档或示例代码。其中只有捆绑包

这是我的 viewcontroller.m 文件

#import "ViewController.h"
#import <Pinterest/Pinterest.h>

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    UIButton* pinItButton = [Pinterest pinItButton];
    [pinItButton addTarget:self
                    action:@selector(pinIt:)
          forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:pinItButton];

}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)pinIt:(id)sender
{
    Pinterest *pinterest = [[Pinterest alloc]initWithClientId:@"1431885" urlSchemeSuffix:@"pin1431885"];
    [pinterest createPinWithImageURL:@"http://www.warrenphotographic.co.uk/photography/bigs/10122-Silver-and-red-kittens-white-background.jpg" sourceURL:@"http://placekitten.com" description:@"Pinning from Pin It Demo"];
}

@end

我的代码相当简单,我只是无法让它在我的开发 iphone 上运行,它一直在抛出:

2013-06-06 17:17:27.787 Pinterest Testing[9403:907] -[__NSCFConstantString absoluteString]: unrecognized selector sent to instance 0x1c86c
2013-06-06 17:17:31.626 Pinterest Testing[9403:907] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFConstantString absoluteString]: unrecognized selector sent to instance 0x1c86c'
*** First throw call stack:
(0x32f4d3e7 0x3ac48963 0x32f50f31 0x32f4f64d 0x32ea7208 0x1a9f9 0x1a71d 0x34e47087 0x34e4703b 0x34e47015 0x34e468cb 0x34e46db9 0x34d6f5f9 0x34d5c8e1 0x34d5c1ef 0x36a745f7 0x36a74227 0x32f223e7 0x32f2238b 0x32f2120f 0x32e9423d 0x32e940c9 0x36a7333b 0x34db02b9 0x19f4d 0x3b075b20)
libc++abi.dylib: terminate called throwing an exception
4

3 回答 3

7

您将 URL 作为NSString对象发送。NSString没有-absoluteString方法,这就是崩溃日志告诉你的。

Pinterest 方法的声明(在 Pinterest.h 中)如下:

- (void)createPinWithImageURL:(NSURL *)imageURL
                    sourceURL:(NSURL *)sourceURL
                  description:(NSString *)descriptionText;

您需要发送NSURL对象,而不是NSString'simageURLsourceURL

所以对于你的情况:

- (void)pinIt:(id)sender
{
    NSURL *imageURL     = [NSURL URLWithString:@"http://www.warrenphotographic.co.uk/photography/bigs/10122-Silver-and-red-kittens-white-background.jpg"];
    NSURL *sourceURL    = [NSURL URLWithString:@"http://placekitten.com"];

    Pinterest *pinterest = [[Pinterest alloc]initWithClientId:@"1431885" urlSchemeSuffix:@"pin1431885"];
    [pinterest createPinWithImageURL:imageURL
                           sourceURL:sourceURL
                         description:@"Pinning from Pin It Demo"];
}
于 2013-06-06T16:37:09.817 回答
0

已经给出了例外的答案。我找到了示例项目的位置。您可以从https://pinterest-ota-builds.s3.amazonaws.com/PinItDemo.zip下载它

当您查看示例文件时,您可以看到urlSchemeSuffix附加到您的 URL 方案中。以下代码取自示例项目:

[[Pinterest alloc] initWithClientId:@"1234" urlSchemeSuffix:@"prod"]

这意味着您必须在您的应用程序中注册以下 URL 方案:pin1234prod.

这确保回调有效。您还可以创建不带后缀的 Pinterest 客户端,并且回调也适用于 URL 方案pin1234

于 2013-06-20T11:02:27.813 回答
0

快速浏览一下标题会发现您应该将NSURL实例作为 imageURL 和 sourceURL 的值传递,因此一旦您这样做,它将不再抱怨尝试absoluteStringNSString.

自述文件可能不是最新的 API。有时候是这样的。很多。

你可能需要做:

[pinterest createPinWithImageURL:[NSURL URLWithString:@"http://www.warrenphotographic.co.uk/photography/bigs/10122-Silver-and-red-kittens-white-background.jpg"] sourceURL:[NSURL URLWithString:@"http://placekitten.com"] description:@"Pinning from Pin It Demo"];
于 2013-06-06T16:32:44.783 回答