iPhone app freezes on presentViewController with SLComposerViewController - ios

I am implementing sharing with Facebook and Twitter - On the simulator both of these work, but on my iPhone 4S running iOS6 the Facebook button freezes the app. The code is the same as it is for the Twitter and functions the same (it hits presentViewController, then the app just stops responding).
The code is as follows:
SLComposeViewController *mulitpartPost = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
// Set the text of the tweet
[mulitpartPost setInitialText:[NSString stringWithFormat:#"I've had a change in weight of "]];
// Add the image to the tweet
if([[NSUserDefaults standardUserDefaults] boolForKey:#"fbProgPicShare"])
[mulitpartPost addImage:[_imgCurrent image]];
mulitpartPost.completionHandler = ^(SLComposeViewControllerResult res){
[self dismissViewControllerAnimated:YES completion:nil];
};
// Display the tweet sheet to the user
[self presentViewController:mulitpartPost animated:YES completion:nil];
isAvailableForServiceType also returns YES if I put that into the code - so I cannot think of why this would freeze when the Twitter button works on the phone. Both Twitter and FB accounts are setup.
Any help would be appreciated.
Strange Fix
It seems to work consistantly now that I do
// Display the tweet sheet to the user
if(!(multipartPost == nil))
[self presentViewController:mulitpartPost animated:YES completion:nil];
Otherwise it still freezes.

Related

SLComposeViewController setInitialText not working on Twitter in iOS 11

I am creating a SLComposeViewController of type SLServiceTypeTwitter and I'm adding an url and text to it. However, the text is not shown, only the url.
Does anybody know why SLComposeViewController's setInitialText is not working on Twitter in iOS 11?
Here is a snippet of my code:
SLComposeViewController *twPostSheet = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeTwitter];
[twPostSheet setInitialText:copy];
[twPostSheet addURL:[NSURL URLWithString:url]];
UIViewController *controller = RCTPresentedViewController();
twPostSheet.completionHandler = ^(SLComposeViewControllerResult result) {
// Shared with success
};
[controller presentViewController:twPostSheet animated:YES completion:nil];
This behaviour is intended. You should use Twitter iOS kit. With it you can share Tweets with text, URLs, photos and video. The same goes for Facebook share.

Unable to set initialtext in ios9 in native facebook share dialog

I am trying to set initial text to SLComposeViewController in iOS 9 , but it is displaying blank in dialog.
Here is my code.
SLComposeViewController *composeController = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeTwitter];
NSString *initialText = #"Tesing text issue.";
if (initialText != Nil)
{
[composeController setInitialText:initialText];
}
dispatch_async(dispatch_get_main_queue(), ^
{
//show progress hud here
[self presentViewController:composeController animated:YES completion:nil];
});
I have aslo check this in another sharing app, they have also same issue. Can anybody have any workaround here?
Facebook has deprecated the api to set initial text programmatically while sharing. Below are the references:
https://developers.facebook.com/docs/apps/review/prefill
https://developers.facebook.com/docs/sharing/ios
Hope this helps.
You can set the initial text using graph API and custom share dialogue.
https://developers.facebook.com/docs/sharing/opengraph/ios#custom

Adding iOS app to Twitter accounts in settings??

I am adding some sharing in my app to allow the use to post to FaceBook and to Twitter. I decided to use the Social Sharing framework as it does exactly what I need and works well.
However I noticed that my app doesn't ask the user for permission it assumes it has permission and does a check if there is an account setup.
The problem I see here is due to this - my app doesn't appear in the Settings - > Twitter under "Allow these apps to use your account" section.
Her is the code I use when I want to share an item - user taps on a UIButton which presents a UIActionSheet with various options"
if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook]){
SLComposeViewController *controller = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
SLComposeViewControllerCompletionHandler completionBlock = ^(SLComposeViewControllerResult result){
if (result == SLComposeViewControllerResultCancelled){
NSLog (#"Cancelled");
}else {
NSLog(#"Done");
}
[controller dismissViewControllerAnimated:YES completion:nil];
};
controller.completionHandler = completionBlock;
NSURL *url = [NSURL URLWithString:self.item.url];
/* Adding the text to the Tweet */
[controller setInitialText:#"Online now!"];
[controller addURL:url];
[controller addImage:self.imageView.image];
[self presentViewController:controller animated:YES completion:nil];
}
else {
[self showUserAlert:#"" message:#"Please make sure your FaceBook account has been setup on this device"
delegate:self
cancelButtonTitle:#"Okay"];
}
How do I ask for access first? And add the app to the settings part of iOS so the user can turn it on or off?
I think you don't need a permission because your app can't post without user action. User have all control.
You can check if sharing possible with canSendTweet method in TWTweetComposeViewController. Look up Xcode documentation. I'm sure Apple has something similar for Facebook.
Apple documentation

Detecting if Twitter account is set up on iOS 7

I've been following some tutorials on integrating Twitter into my application. Here is what I have so far:
- (IBAction)postToTweeter:(id)sender {
if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeTwitter]) {
SLComposeViewController *tweetSheet = [SLComposeViewController
composeViewControllerForServiceType:SLServiceTypeTwitter];
[tweetSheet setInitialText:#"this is a test"];
[self presentViewController:tweetSheet animated:YES completion:nil];
}
}
My storyboard has a button, and when a user taps that button, this is the code that gets called. However, this only works whenever they have a Twitter account setup on their iPhone first. How can I handle the case where a user has not set up a twitter account yet, and show them an alert instructing them to add a Twitter account?
SLComposeViewController has a very handy built-in mechanism, whereby it will offer to send the user to Settings if you instantiate a ComposeViewController when the user hasn't set up / logged into the social-media service in question. To test this, all you need to do is remove the conditional so your code looks like this:
- (IBAction)postToTweeter:(id)sender {
SLComposeViewController *tweetSheet = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeTwitter];
[tweetSheet setInitialText:#"this is a test"];
[self presentViewController:tweetSheet animated:YES completion:nil];
}
...and you'll find that iOS will automatically pop up an alert which will take the user through to Settings.
Note that I've found that this doesn't tend to work in the simulator, so it's best to test on a device.

iOS - Tweet Sheet not displayed - SLComposeViewControllerResultCancelled called automatically

I am using SLComposeViewController to send a tweet. I have all the necessary permissions from Twitter to send a tweet, however, when I present the tweet sheet it never shows. From debugging my code I can see that the SLComposeViewController's completion handler is automatically called at SLComposeViewControllerResultCancelled is the result.
Has anyone come across this before? As I said, I have all necessary permissions and my Twitter account and password are set up correctly in my iPhone settings.
EDIT
This only happens sometimes. Majority of the time I have no problem with the Tweet sheet, so the code does work, but for some users they are experiencing this.
thanks
My code here:
- (void)presentTweetSheet {
SLComposeViewController *tweetSheet = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeTwitter];
tweetSheet.completionHandler = ^(SLComposeViewControllerResult result) {
switch (result) {
case SLComposeViewControllerResultCancelled:
SWLog(#"Tweet Cancelled");
break;
case SLComposeViewControllerResultDone:
SWLog(#"Tweet sent");
break;
default:
break;
}
};
UIWindow *window = [UIApplication sharedApplication].keyWindow;
ECSlidingViewController *slidingVC = (ECSlidingViewController *)window.rootViewController;
[slidingVC.topViewController presentViewController:tweetSheet animated:YES completion:^{
SWLog(#"Tweet sheet displayed");
[self removeActivityIndicatorFromCell];
}];
}
I checked multiple apps with the same code written in them, non of them worked. i tried sorting it out by code but it did not work. So i re-booted my iPhone and it WORKED!
Hope this helps

Resources