TwitterKit iOS SDK counting image and URL against character count - ios

I am using the latest version of TwitterKit (2.5), and when I attempt to share a Tweet with an image and URL, the TWTRComposer is counting them against the character count. Twitter is supposed to no longer count media against the character count, and in fact I am able to post the exact same tweet from the web that I cannot post in-app (app says it is too long).
In my current use case, my actual tweet text is 100 characters. With an image and URL, TWTRComposer is showing that I am 8 characters over the limit. Yet, I can post this exact same Tweet with the exact same content from Chrome with 16 characters to spare.
Is this a known bug?
Code snippet:
func didTapShareToTwitter() {
// Configure composer
let composer = TWTRComposer()
composer.setText(composerText)
composer.setURL(shareURL)
if shareImageURL != nil {
if let imageData = NSData(contentsOfURL: shareImageURL!) {
composer.setImage(UIImage(data: imageData))
}
}
// Present composer
composer.showFromViewController(self) { result in
if (result == TWTRComposerResult.Cancelled) {
log("Tweet composition cancelled.")
}
else {
log("Sending tweet...")
}
}
}

Looks like this an iOS system-level bug, not necessarily the Twitter SDK. The TWTRComposer is actually just a wrapper around the built-in iOS sharing view controller, SLComposeViewController.
The iOS SLComposeViewController still counts attached URLs and images against the total Twitter character limit (140) as of the latest iOS release, 10.1. Most likely, Apple just hasn’t updated their OS code since Twitter made the move to not count images and URLs against the character limit earlier this year.
After doing some testing, I have come to the following conclusion:
On iOS, a URL counts as 23 characters no matter original length of
the URL is.
On iOS, an image counts as 23 characters no matter what
size it is.
Therefore, with an image and URL, we have only 94 characters
available on iOS per Tweet. And there’s nothing that can be done
about it unless Twitter updates their SDK or Apple updates
SLComposeViewController.

Related

How to Hide *DTMF* number while making Phone Call in iOS

I'm trying to initiate a call which also contains DTMF Numbers
ex:- 012345678,1*0001*000*1*1#
and i'm using the following code to initiate the call
guard let number = URL(string: "tel://" + number) else { return }
UIApplication.shared.open(number)
and then the systems shows popup to the user to make the call with the Full number also including the DTMF.
so i was wondering if it is possible that we can hide the DTMF part from that Popup ?
so the user only sees "012345678" instead of "012345678,1*0001*000*1*1#" as this DTMF numbers are secure data that he shouldn't see it.
Thanks
That's not possible, as far as I know. That popup is created by iOS itself and you have no control over it.

UIActivityController does not report the text and image when sharing on Facebook

I have this simple piece of code to display a sharing dialog for a number of social avenues:
let text = String(format:NSLocalizedString("I %# with the Dhammapada verse \"%#\"", comment:"$ to be composed with $$"), part, verse)
let url = URL(string:"http://www.ipuja.net")
let image = buddhanetImage.image ?? UIImage(named:"Icon-72")
let shareController=UIActivityViewController(activityItems:[text, url!, image!], applicationActivities:nil)
shareController.excludedActivityTypes = [UIActivityTypeAssignToContact, UIActivityTypeAddToReadingList,UIActivityTypePostToVimeo];
if (UI_USER_INTERFACE_IDIOM() == .pad){
shareController.popoverPresentationController?.sourceView = self.buddhanetImage;
}
self.present(shareController, animated:true, completion:nil)
Yet the tool woks fine for Google and Twitter, but when I try to share the contents on Facebook, just the url is shown without either text of image.
I checked that doing the thing on Photos and other other third party apps allows to display the full content even for Facebook, so what is missing in my code for that to work?
The URL will override the text and image when sharing to Facebook from a third-party application. Remove the URL and the image and text will appear. Also, if you have multiple hashtags in your text, only the first hashtag will be applied.
Prior to iOS 9, prefilling the Facebook share dialog with text, image, and URL was possible. Once iOS 9 was released, prefilling any fields when sharing to Facebook was not possible at all. Sometime around iOS 9.3 they reenabled prefilling fields, but prefilling all the fields is not possible.

How To Display Youtube Video Thumbnail?

I have a fragment with a ScrollView and I want to display the YouTube thumbnail of a video as one of the items in the scrollview.
I looked up everywhere but couldn't understand how to, I really need the base.
Please help me, I'm stuck like this for days...
This method supposed to take the VIDEO_ID(from YouTube) and take it's thumbnail.
This thumnbail should be displayed in youTubeThumbnailView.
Here is something I tried:
public void getThumbnail(){
String VIDEO_ID = "xxxxxx";
YouTubeThumbnailView youTubeThumbnailView = new YouTubeThumbnailView(getActivity());
youTubeThumbnailView = (YouTubeThumbnailView)youTubeThumbnailView.findViewById(R.id.thumbnail);
youTubeThumbnailView.//Dont know how to continue :(.
}
Take a look at the updated version of the youtube-android sdk (version 1.2.1 released on 22 Jan 2015).
The changelog states something interesting about thumnails:
The YouTubeThumbnailLoader interface's documentation has been updated to note that you must call the interface's release() method when you are finished with the YouTubeThumbnailLoader. The documentation for the YouTubeThumbnailView class also mentions this requirement.

Is Twitter sharing broken under iOS 7? (Example project attached.)

Example project: http://cl.ly/261z1P100T25
Under iOS 7, when I try to add a URL to a tweet, the method should return NO if there's no enough space to add it ("This method returns NO if url does not fit in the currently available character space") but this method ALWAYS returns YES in iOS 7. For example, in the following example, "Couldn't add." is never printed and the tweet is presented with -32 characters remaining.
SLComposeViewController *twitterViewController = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeTwitter];
NSString *titleToShare = #"i am a string a super string the most super string that ever existed in the world of the super string universe which as it happens is very super as well";
if (titleToShare.length > 140) {
titleToShare = [titleToShare substringToIndex:140];
}
[twitterViewController setInitialText:titleToShare];
if (![twitterViewController addURL:[NSURL URLWithString:#"http://google.com"]]) {
NSLog(#"Couldn't add.");
}
[self presentViewController:twitterViewController animated:YES completion:nil];
Is it broken? Do I have to code around this?
It's not broken, just it isn't publicly documented well. I found in code following comment for setInitialText: method:
// Sets the initial text to be posted. Returns NO if the sheet has already been
// presented to the user. On iOS 6.x, this returns NO if the specified text
// will not fit within the character space currently available; on iOS 7.0 and
// later, you may supply text with a length greater than the service supports,
// and the sheet will allow the user to edit it accordingly.
So, they allow you to set text greater then 140 characters, just you can't post this text because post button is disabled.

Why am I unable to post to Twitter using SLComposeViewController?

I'm trying to post an article title and an article URL to twitter and then append the app's name to the end of the tweet. So something like
"How to grow a cactus (via #appname)" attached URL
I was having trouble figuring out how to balance the length of the title and URL to make sure that the tweet doesn't exceed 140 characters. So if the URL is really long, cut some of the article title off so it can be under 140 characters.
Looking at Twitter's guidelines for SLComposeViewController they state this part:
Note that the methods for setting initial content respond with Boolean values; this allows you, the developer, to not have to worry about the current count of characters in the body of the Tweet that you are initializing. If the method returns YES, there was enough room to add the content. If the method returns NO, the content you attempted to add would result in a Tweet longer than 140 characters. The logic for character counting also takes into effect the current number of characters required for t.co URL wrapping.
(From the "Code Example" section.)
Given that, I wrote the following code to build a tweet and balance the URL length and article length:
if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeTwitter]) {
SLComposeViewController *twitterViewController = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeTwitter];
[twitterViewController addURL:[NSURL URLWithString:self.article.url]];
NSString *titleToShare = self.article.title;
while ([twitterViewController setInitialText:[NSString stringWithFormat:#"%# (via #SyllableApp)", titleToShare]]) {
titleToShare = [titleToShare substringToIndex:titleToShare.length - 1];
}
[self presentViewController:twitterViewController animated:YES completion:nil];
}
Which basically adds the URL then constructs the rest of the tweet by looping through the setInitialText: method until it returns YES, decreasing the length of the title by 1 each time it returns NO in order to get closer to the required length.
But it never returns YES! Even when I know it should. I was using one article where it could potentially exceed 140 characters as the title is 105 characters long and the URL is 55, plus the app credit. So it should theoretically be able to shorten the title down and then add it fine, but it never happens.
So what's going on? How do I accomplish link attachment with SLComposeViewController?
while ([twitterViewController setInitialText:[NSString stringWithFormat:#"%# (via #SyllableApp)", titleToShare]])
=>
while (![twitterViewController setInitialText:[NSString stringWithFormat:#"%# (via #SyllableApp)", titleToShare]])
There is a ! missing in condition, so you shorten the post when it fits, not when it is too long ;)
The problem with this approach is that it works only on iOS6.
SLComposeViewController *social = [[SLComposeViewController alloc] init];
NSString *stringToShare = #"";
for (int i = 0; i < 150; i++)
{
stringToShare = [stringToShare stringByAppendingString:#"x"];
}
NSLog(#"%#",[social setInitialText:stringToShare]?#"YES":#"NO");
yields different results on iOS6 (NO) and iOS7 (YES). The answer to this behaviour comes from the documentation of SLComposeViewController
// Sets the initial text to be posted. Returns NO if the sheet has already been
// presented to the user. On iOS 6.x, this returns NO if the specified text
// will not fit within the character space currently available; on iOS 7.0 and
// later, you may supply text with a length greater than the service supports,
// and the sheet will allow the user to edit it accordingly.
- (BOOL)setInitialText:(NSString *)text;
Probably is worth either having different approaches on iOS6 and 7, or check the length without using SLComposeViewController method.
As imihaly said, you did miss a "!".
And 140 characters count is the limit of title only, not including URL.So your title is 105 characters long which is less than 140,this method should return YES.
There is an open bug with link lengths not getting calculated correctly (radar://10469407). This might be related. You might try sending a Tweet with a link in it to check which URL shortener is being used (I imagine it's using t.co, but I could be wrong).

Resources