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
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"];
}
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"];
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
Related
I recently upgraded a project to SDWebImage 4.0, which I'm only using to cache images and later retrieve them. Had this working flawlessly on the 3.x version. I'm now getting the following error after migrating...
-[SDImageCache storeImage:forKey:toDisk:completion:]: unrecognized selector sent to instance 0x174097cf0
This seems like it should be a simple error to resolve, but after multiple attempts, I'm unable to fix it.
Here is my previous code from the 3.x API...
#property (strong, nonatomic) SDImageCache *imageCache;
- (SDImageCache *)imageCache {
if (!_imageCache) {
_imageCache = [[SDImageCache alloc] initWithNamespace:NAME_SPACE_IMAGE_CACHE];
}
return _imageCache;
}
[self.imageCache storeImage:[UIImage imageWithContentsOfFile:imageData.imageURL.path] forKey:imageData.imageURL.absoluteString toDisk:YES];
Here is my updated code for the 4.0 API, which is the line of code throwing the error...
[self.imageCache storeImage:[UIImage imageWithContentsOfFile:imageData.imageURL.path] forKey:imageData.imageURL.absoluteString toDisk:YES completion:^{
NSLog(#"INFO: Image cached successfully!");
}];
Could someone please help clarify what the issue is?
Thanks in advance!
I try like this and it works, you must shift + cmd + k and build again, must solve the problem as is pointed out here https://github.com/rs/SDWebImage/issues/1602
#import "ViewController.h"
#interface ViewController ()
#property SDImageCache * imageCache;
#end
#implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.imageCache = [SDWebImageManager sharedManager].imageCache;
// Do any additional setup after loading the view, typically from a nib.
[_imageCache storeImage:[UIImage imageNamed:#"test"] forKey:#"testKey" toDisk:YES completion:^{
NSLog(#"INFO: Image cached successfully!");
}];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#end
CONSOLE OUTPUT
2017-07-11 00:55:12.146 SDWebImageSOQuestion[17275:339149] INFO: Image
cached successfully!
Hope this helps
I had the same issue when my pod updated to 5.0. To fix it I needed to...
Change
[imageCache clearDisk];
To
[imageCache clearDiskOnCompletion:^{
}];
I have built a view controller in my app whose only element is a UIWebView. I am trying to load a webpage on this uiwebview element with the following code, right after its view controller loads:
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
NetworkHelper *networkHelper = [NetworkHelper getInstance];
NSString *tocsUrl = [NSString stringWithFormat:#"%#%#", networkHelper.clientConfiguration[#"hdv_production_uri"],
#"/tocs?device=iOS"];
NSURL *url = [NSURL URLWithString:tocsUrl];
NSURLRequest *urlRequest = [NSURLRequest requestWithURL:url];
[self.webView loadRequest:urlRequest];
}
String tocsUrl is a valid http string (http://192.168.1.12:3000/tocs?device=iOS).
However, the line [self.webView loadRequest:urlRequest]; is crashing the app with the following exception:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIView loadRequest:]: unrecognized selector sent to instance 0x170188fd0'
*** First throw call stack:
(0x186d86530 0x197d640e4 0x186d8d5f4 0x186d8a3ac 0x186c8ec4c 0x1000b5d18 0x18b594958 0x18b594668 0x18bc881d0 0x18b88f790 0x18b8aab50 0x18b8acf68 0x18b681c4c 0x18b5c8a14 0x18b5b1d08 0x18b5c83b0 0x18b587ec8 0x186d3ed98 0x186d3bd24 0x186d3c104 0x186c691f4 0x19008b6fc 0x18b5fa10c 0x1000e0ad8 0x1983e2a08)
libc++abi.dylib: terminating with uncaught exception of type NSException
self.webView is defined in the .h file as:
#property (strong, nonatomic) IBOutlet UIWebView *webView;
Any pointers on how to solve this crash will be highly appreciated.
Check your webView, you have assigned it to UIView instead of your UIWebView. You can also remove and re add the connection to your UIWebView and Interface Builder. You can use shift+option+right click to make sure that you're choosing right controller in IB
In Xcode 5.0.2
I create a blank single view app for iPhone,
then add a "male.png" image to the project,
drag a UIImageView to the storyboard
and finally add the following code to the viewDidLoad:
_imageView.image = [UIImage imageNamed:#"male.png"];
This works well:
Then I add the 4 files from JMImageCache project and change the ViewController.m to:
#import "ViewController.h"
#import "JMImageCache.h"
static NSString* const kAvatar = #"http://gravatar.com/avatar/55b3816622d935e50098bb44c17663bc.png";
#interface ViewController ()
#end
#implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
[_imageView setImageWithURL:[NSURL URLWithString:kAvatar]
placeholder:[UIImage imageNamed:#"male.png"]];
}
#end
Unfortunately, this results in app crash with the error message Thread 1: EXC_BAD_ACCESS:
At his webpage Jake Marsh (the author of JMImageCache) notes:
JMImageCache purposefully uses NSString objects instead of NSURL's to make things easier and cut down on [NSURL URLWithString:#"..."] bits everywhere. Just something to notice in case you see any strange EXC_BAD_ACCESS exceptions, make sure you're passing in NSString's and not NSURL's.
But (as an iOS programming newbie) I don't understand, what exactly does Mr. Marsh mean - since his file UIImageView+JMImageCache.m declares the 1st argument for the public method as NSURL:
- (void) setImageWithURL:(NSURL *)url placeholder:(UIImage *)placeholderImage {
[self setImageWithURL:url key:nil placeholder:placeholderImage];
}
Is the note maybe outdated and how could I fix my app?
That's a bug in JMImageCache. setImageWithURL:key:placeholder:completionBlock: calls itself, exhausting the stack.
To work around the bug, call the longer form of the method:
[_imageView setImageWithURL:[NSURL URLWithString:kAvatar]
key:nil
placeholder:[UIImage imageNamed:#"male.png"]
completionBlock:nil
failureBlock:nil];
Or, use an older version of the library (e.g. 0.4.0). Looks like the bug was introduced in 1af09be78a.
I'm using the Pinterest iOS SDK to share an item in my iPad app. The following snippet of code will always crash with a message sent to deallocated instance on the line with the comment:
NSString *clientId = [NSMutableString stringWithString:#"1431665"];
NSLog(#"clientId: %#", clientId);
Pinterest *pinterest = [[Pinterest alloc] initWithClientId:clientId];
NSLog(#"gone: %#", clientId); // <- CRASH!
I'm using NSMutableString stringWithString to simulate the conditions in my app. I don't actually use that line in my code.
Even if don't output the clientId on the last line, the app crashes when leaving the block. I assume it's because ARC is trying to release the reference which has already been deallocated.
It seems like the Pinterest SDK must be doing something wonky and trashing the string I'm passing in. Is there some way I can get around this while they fix their code?
EDIT 1
Simplified the test case.
EDIT 2
It looks like the Pinterest SDK is consuming the clientId argument. Based on the clang ARC documentation, the way to indicate this to clang is to indicate this with __attribute((ns_consumed)).
New question: Is it possible to indicate this to ARC without modifying the signature of the method to add the attribute?
EDIT 3
So this works, but it's ugly as sin? Is there another way?
NSString *clientId = [NSMutableString stringWithString:#"1431665"];
[clientId performSelector:NSSelectorFromString(#"retain")]; // <- UGLY!
NSLog(#"clientId: %#", clientId);
Pinterest *pinterest = [[Pinterest alloc] initWithClientId:clientId];
NSLog(#"gone: %#", clientId);
What I did was make a static variable that represented the Pinterest class:
//I put this outside my #implementation code at the top of my m file
static Pinterest *_pinterest = nil;
// instantiating
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
_pinterest = [[Pinterest alloc] initWithClientId:clientId];
});
I think that Pinterest assumed that everyone would use their class as a static singleton because that's probably what they do internally. To be fair, I don't foresee using multiple client ID's with a single app in most cases. I agree, though, this is a stupefying oversight on their part. They didn't even document this behavior, what were they thinking?!
My current workaround, which seems to be the least hacky of the ideas so far is this wrapper class that doesn't use ARC:
+ (void) createPinWithClientId:(NSString *)clientId
imageURL:(NSURL *)imageURL
sourceURL:(NSURL *)sourceURL
description:(NSString *)descriptionText {
Pinterest *pinterest = [[Pinterest alloc] initWithClientId:clientId];
[pinterest createPinWithImageURL:imageURL
sourceURL:sourceURL
description:descriptionText];
}
The key is to disable ARC for the class, which keeps the runtime from deallocating the clientId.
I have a ViewController embedded in a NavigationController. The ViewController has a UIWebView that I'm trying to capture links from. I'm able to intercept the links, but when I try to push the link content to a detail page, it seems to be firing a new Controller but it's invisible. If I click a link for a second time (or if I just click a second link) I see a back button pop up, but again the actual content of the new ViewController is not visible.
Here is the log output for the first link click:
2011-11-07 10:38:27.526 WGGB[43875:f803] *** WebKit discarded an uncaught exception in the webView:decidePolicyForNavigationAction:request:frame:decisionListener: delegate: <NSInternalInconsistencyException> Could not load NIB in bundle: 'NSBundle </Users/sonnyjitsu/Library/Application Support/iPhone Simulator/5.0/Applications/4B3D5152-4EA5-4C84-BB22-A774FCB8B6A7/WGGB.app> (loaded)' with name 'Detail View'
As you can see, it's "loading" the new view, but I see nothing in the simulator. Then the second time I click the same link (or click a new link) I see this in the log:
2011-11-07 10:38:30.605 WGGB[43875:f803] url is http://www.blahblahblah.com/mobile
The method in question is this:
-(BOOL) webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
NSURL *url = request.URL;
NSString *urlString = url.absoluteString;
NSRange page = [ urlString rangeOfString: #"/mobile" ];
if (page.location == NSNotFound) {
SingleStoryViewController *detailViewController = [[SingleStoryViewController alloc] initWithNibName:#"Detail View" bundle:nil];
NSString *requestURL =
[NSString stringWithContentsOfURL:url encoding:NSUTF8StringEncoding error:nil];
[detailViewController.webView loadRequest:
[NSURLRequest requestWithURL:[NSURL URLWithString:requestURL]]];
[self.navigationController pushViewController:detailViewController animated:YES];
NSLog(#"url is %#", url);
return NO;
} else {
return YES;
}
}
Top of my SingleStoryViewController.m
#import "SingleStoryViewController.h"
#implementation SingleStoryViewController
#synthesize webView;
Entire SingleStoryViewController.h
#import
#interface SingleStoryViewController : UIViewController
#property (weak, nonatomic) IBOutlet UIWebView *webView;
#end
Here is a link to an image of my Xcode storyboard, for what it's worth: http://i.imgur.com/I653v.png
I've been working on this for a good 14 to 16 hours now and I'm finally saying 'uncle' and asking for help. Any help would be appreciated, I'm very new to iOS programming so I apologize if there is something really stupid I'm missing.
As you can see, it's "loading" the new view...
That's not what the error says. The error says this:
Could not load NIB in bundle: [...] with name 'Detail View'
I'd start by checking the name of the .xib file in your app -- it sounds like it may not match the name you're using in the code.
Update: Per comments below, it turns out that this is app uses storyboards and doesn't contain any .xib files, so it's no surprise that attempting to load a view controller from a .xib produces an error. The correct way to load a view controller from a storyboard, when necessary, is to use UIStoryboard's -instantiateViewControllerWithIdentifier: method instead of UIViewController's -initWithNibName:bundle:.