I have the following code to shorten a URL using the bit.ly API.
NSString *shortenedURL = [NSString stringWithContentsOfURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://api.bit.ly/v3/shorten?login=%@&apikey=%@&longUrl=%@&format=txt", login, key, self.link.text]] encoding:NSUTF8StringEncoding error:nil];
I also have the following code to copy the shortened URL to the pasteboard:
UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
pasteboard.string = shortenedURL;
However, this does not work. In the output log, this is what is displayed:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIPasteboard setString:]: Argument is not an object of type NSString [(null)]'
So if the argument isn't an object, what is it? I tried assuming it was a URL with this:
UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
pasteboard.URL = shortenedURL;
The same type of error is produced, only saying that the argument is not an NSURL
object, instead of the previous error saying the argument is not an NSString
object.
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIPasteboard setURL:]: Argument is not an object of type NSURL [(null)]'
Anyone know what to do?
is nil, so it's not a good idea to ignore the error.
Instead of that, do
You should get "Error loading: error message here", and debug the exact problem what happened.