SLComposeViewController setInitialText not showing up in View
Asked Answered
P

2

11

I'm trying to use the SLComposeViewController to share a link in my iOS App.

SLComposeViewController *controller = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
[controller setInitialText:@"Here's the link I promised:"];
[controller addURL:[NSURL URLWithString:@"http://www.url.com"]];
[self presentViewController:controller animated:YES completion:nil];

When the controller presents, there is no text in the entry box. You can add text and send it fine (the URL shows up correctly in the Post as well).

I just installed FacebookSDK 4.01 and it's a iOS 7/8 App.

Any ideas on why the initial text isn't showing up. I even tried to do it without the URL and just do text, but nothing.

Additional Note: If I do remove the addURL, then the App freezes when I touch "Post" and the post never gets sent.

Thanks for any help!!!

Phenacite answered 30/4, 2015 at 14:42 Comment(7)
You know that you are not allowed to prefill the message field?Wiatt
This always worked before. And what would setInitialText be used for if not for that?Phenacite
You are allowed to set it if the user wrong the text. It was never allowed to prefill it with something you wrote. You should read the Facebook Policy at developers.facebook.com/policy 2.3Wiatt
Ok, so, again. What is setInitialText meant to be used for then?Phenacite
To fill in the text the user wrote in a form somewhere else in your appWiatt
But it still doesn't show up, no matter where the text comes from.Phenacite
Is the user writing the text in your app? What I mean is there is no reason to try to fix it if it isn't allowed anyway.Wiatt
R
8

I found a nice way to work around this which still gives the user control.

For Facebook only, just before presenting the SLComposerViewController I show a self dismissing alert (with a 6 second dismissal if OK wasn't tapped). This alert will contain "Write to your friends about how you did playing !\n\nYou can just PASTE for a preset message.".

Right after showing the alert, I then use the following to post a preset message to the UIPasteboard:

    UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
    pasteboard.string = msg;

So then the SLComposeViewController is presented and an alert view right over it. Once the user dismisses the alert view (or 6 seconds passes and it self dismisses), that the user has the option to just PASTE, right in the message text, your preset message. Or not, that's the beauty of it.

Hope this helps some others get around what FB decided to suddenly enforce. I didn't even realize it was against policy to use the setInitialText method for FB.

Cheers.

Richmal answered 24/5, 2015 at 21:48 Comment(1)
could you possibly provide the entire code block for this?Klute
S
7

This behaviour is intended. See also this bug report: https://developers.facebook.com/bugs/962985360399542/. As @WizKid mentions, it's against policy to pre-fill text. Up until recently, you could still do so (violating the policy) but now this is actually enforced.

There is nothing you can do for this on your side; it's a policy enforcement by Facebook.

Also, related Rdar: http://openradar.appspot.com/20709403

Sawyer answered 4/5, 2015 at 3:54 Comment(4)
This behavior is not intended. The SLComposeViewController has no idea if the value for initial text is a hardcoded string or if it was written by the user. Facebook does not enforce this policy on a code level; you will receive a warning / have your permissions denied by Facebook if they find you are using it incorrectly in your app. i.e. Set initialText should succeed except for the cases documented in SLComposeViewController.hSqueeze
Nothing in Apple's documentation do they say they are enforcing this policy by making setInitialText not function as intended for Facebook. As Patrick eludes to, it is fine if a user-entered string is placed there as initial text. The code has no idea where you got the string from, so it really couldn't enforce it effectively anyway.Phenacite
Yes, if this policy is being newly enforced in SLComposeViewController, it would be on Apple's side. Did this recently change with iOS 8.3? Unfortunately I diligently updated all of my devices so have nothing 8.2 to try this on. Setting initial text still works on iOS 7. And it still works on iOS 8.3 simulator! Wonder if this is just a bug on Apple's part.Lapidify
This smells like a bug on Apple's part. Just remove the Facebook app, and it works. Apple bug? Yes.Giraudoux

© 2022 - 2024 — McMap. All rights reserved.