Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
450 views
in Technique[技术] by (71.8m points)

ios - SLComposeViewController setInitialText not showing up in View

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!!!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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 ! You 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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...