SLServiceTypeFacebook setInitialText is not working
Asked Answered
P

3

46

I am trying to share a text on Facebook with SLServiceTypeFacebook on IOS 8.3. But the popup text box displayed empty. I want it to be displayed with text in it. Below you can see the code I use for that.

 if([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook]) 
 {
       SLComposeViewController *controller = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];

       [controller setInitialText:@"First post from my iPhone app"];
       [self presentViewController:controller animated:YES completion:Nil];
  }
Pepita answered 28/4, 2015 at 17:13 Comment(6)
Does setInitialText return YES or NO?Bonaparte
This is a known issue on iOS 8.3: "Greg Pierce (@agiletortoise) 4/27/15, 11:22 AM UIKit folks: New iOS 8.3 problem with [SLComposeViewController setInitialText]. rdar://20709403 openradar.appspot.com/radar?id=50611…Overside
@deanware can you please send the link for that? Do you suggest me to wait new iOS version?Pepita
OpenRadar: openradar.appspot.com/radar?id=5061141176778752Bonaparte
possible duplicate of SLComposeViewController setInitialText not showing up in ViewGeranium
As others have already mentioned, Facebook does not allow for prefilling anymore, rendering "setInitialText" of a SLComposeViewController for the SLServiceTypeFacebook useless. What was very useful for me, however, is to realize that adding an url or an image is still perfectly possible and in line with the Facebook terms of service. If you have the resources to do it, e.g. a webserver to host the post on - just add a link to the webpage you want the user to see. Facebook will prefetch the summary of this page and display it embedded anyway. Better than trying to comment on the user's behalf.Replevy
B
32

It seems to be a problem having installed the latest Facebook app update (v29). Removing it "fixes" the problem.

https://developers.facebook.com/bugs/1632385646995079/ https://developers.facebook.com/bugs/962985360399542/

Update (Jun. 3, 2015)

Well. It seems that the new Facebook policy says that prefilling a message through setInitialText: is a prefill violation.

https://developers.facebook.com/docs/apps/review/prefill

So I guess the only way to share content from now on is the FBSDKShareDialog

https://developers.facebook.com/docs/sharing/ios

Breckenridge answered 29/4, 2015 at 14:11 Comment(8)
It does seem strange that installing a 3rd party app (Facebook) can break a native SLComposeViewController. But I can confirm this is actually happening, even with the latest app update (v30).Decalcify
Same problem is generated in Facebook v31 as well. Please give me some suggestion in this.Putnem
I don't think apple is going to deprecate that SLComposeViewController. Some proper solution for this is still in wait. I don't personally want to implement FBSDKShareDialog as it will incur lots of hours, like, configuration, initialization of code, integration of SDK, etc. SLCompose...Controller only requires 4-5 lines of code.Manganite
It is correct that Apple with new iOS 9 has new Facebook sdk in which setInitialText is deprecated. Same thing is with Instagram. You cannot add pre-defined comments in both of these apps programatically.Carolinian
Deprecated, in iOS9? Where do you see that? In the current docs, it does not say deprecated. While it still doesn't work. I'm with @Mobihunterz here - this is just a real pain in the ants.Pirn
setInitialText is NOT deprecated for iOS 9 because it still works for Twitter and other Social framework services. As for a "Apple . . . has new Facebook sdk . . .", that is not true either. They are still using the Social framework. And this "sudden" change of heart from Facebook inconveniences me too. :/ EDIT: Personal experience with Facebook's own SDK has not been fun... and I don't recommend it if you ONLY need sharing support.Clive
@ErikBean I think it should be possible to make your own custom view based on SLComposeViewController which uses the Social framework, thus allowing you to pre-fill text. The only problem I can see with that, is that it requires an API key from Facebook and they will reject the API key when they see you app can pre-fill text :(Novation
No, Facebook automatically considers it a violation of it's T&C and ALL Dev Ops with FB are terminated. Your FB page can also be terminated as well if you used it in testing since you used your page to violate the T&C. Apple also will reject your app for violating section 8.5 of the App Store Review procedure.Clive
B
1

Gotta love the efficiencies of Facebook. Am a bit late on this but may help someone out.

#import <FBSDKShareKit/FBSDKShareKit.h>

FBSDKShareLinkContent  *content = [[FBSDKShareLinkContent alloc] init];
content.contentURL = self.urlForSocialMedia;
content.contentDescription = self.textForFB;
content.contentTitle = @"Results.";

[FBSDKShareDialog showFromViewController:self
                             withContent:content
                                delegate:self];
Brushwood answered 28/8, 2015 at 4:32 Comment(3)
Why you create a dialog and afterwards don't use it?!? In the end you are using the FBSDKShareDialog showFromViewController to create and show the dialog.Tarpaulin
I would imagine that the FBSDKShareDialog should just be dialog at the end.Bul
The three dots at the beginning of this post will get me almost the same amount of time I spent to create the app itself!Innate
L
0

Before setInitialText add # before this test. Code below. It is working for me

SLComposeViewController *mySLComposerSheet = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];

    [mySLComposerSheet setInitialText:@"#myInitialTextIsHere"];
    [mySLComposerSheet addURL:[NSURL URLWithString:strURL]];

    [mySLComposerSheet setCompletionHandler:^(SLComposeViewControllerResult result) {

        switch (result) {
            case SLComposeViewControllerResultCancelled:
                NSLog(@"Post Canceled");
                break;
            case SLComposeViewControllerResultDone:
                NSLog(@"Post Sucessful");
                break;

            default:
                break;
        }
    }];

    [self presentViewController:mySLComposerSheet animated:YES completion:nil];
Loosejointed answered 7/5, 2018 at 8:34 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.