Reputation: 5082
I'm trying to go through the basic tutorial on Pinterest's website.
the link for downloading documentation and iOS sdk doesn't provide documentation or sample code.there was only bundles in it
here is my viewcontroller.m file
#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
my code is fairly straight forward, i just couldn't get it running on my dev iphone it kept throwing:
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
Upvotes: 3
Views: 2705
Reputation: 1454
The answers for the exceptions have already been given. I found the location of the sample project. You can download it from https://pinterest-ota-builds.s3.amazonaws.com/PinItDemo.zip
When you look at the sample file you can see that the urlSchemeSuffix
is appended to your URL scheme. The following code is taken from the sample project:
[[Pinterest alloc] initWithClientId:@"1234" urlSchemeSuffix:@"prod"]
This means you have to register the following URL scheme in your app: pin1234prod
.
This make make sure the callback works. You can also create the Pinterest client without suffix and the callback will also work with URL scheme pin1234
Upvotes: 0
Reputation: 23359
You are sending your URLs as NSString
objects. NSString
doesn't have a -absoluteString
method, this is what the crash log is telling you.
The declaration of the Pinterest method (in Pinterest.h) is as follows:
- (void)createPinWithImageURL:(NSURL *)imageURL
sourceURL:(NSURL *)sourceURL
description:(NSString *)descriptionText;
You need to send NSURL
objects, not NSString
's for the imageURL
and sourceURL
.
So for your case:
- (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"];
}
Upvotes: 7
Reputation: 94729
A quick glance at the header reveals that you should be passing in NSURL
instances as the values for the imageURL and sourceURL, so once you do that it will no longer complain about trying to invoke absoluteString
on an NSString
.
The readme docs are probably not up to date with the API. This happens. A lot.
You probably need to do:
[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"];
Upvotes: 0