UIActivityViewController for Facebook not Showing Default Text

C6Silver picture C6Silver · Apr 24, 2015 · Viewed 24.4k times · Source

I am using a UIActivityViewController which provides some default text and a link. With all social mediums (sms, email, twitter) the default text and URL are shown. However, with FB while the URL image is shown, the default text is not showing (it is just blank). Below is the code:

    NSString *shareStr = [NSString stringWithFormat:@""some text"];
    NSURL *website = [NSURL URLWithString:@"website"];
    NSArray *shareAray = @[shareStr,website];

    [self viewWillDisappear:YES];

    UIActivityViewController *activityController = [[UIActivityViewController alloc]initWithActivityItems:shareAray
                                                                                    applicationActivities:nil];

    if([activityController respondsToSelector:@selector(popoverPresentationController)] )
        activityController.popoverPresentationController.barButtonItem = self.shareButton;


    [self presentViewController:activityController
                       animated:YES completion:nil];

    [activityController setCompletionHandler:^(NSString *activityType, BOOL completed){
        if (!activityType || UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
        {
            [self viewWillAppear:YES];
        }
    }];

Update: As noted in what others said below, FB no longer allows pre-fill. Here is another link to a video that gives examples of what is allowed and what isn't: https://developers.facebook.com/docs/apps/review/prefill

Answer

DeepFriedTwinkie picture DeepFriedTwinkie · May 4, 2015

It would seem Facebook no longer wants developers to pre-fill posts with text. From https://developers.facebook.com/docs/sharing/ios#ios-integration:

Use of the iOS share sheet is subject to Facebook Platform Policy, including section 2.3 which states that apps may not pre-fill. In the context of the share sheet, this means apps may not pre-fill the share sheet's initialText field with content that wasn't entered by people earlier in their use of the app.

Seems they would prefer devs to use the SDK:

While you can use the iOS native view controller API (share sheet) directly, there are several reasons to use the native iOS Share dialog provided by the Facebook SDK. Using the native Share dialog provides a quick way to test that people have signed into Facebook on their iOS 6+ devices. This API also uses the same style block as other parts of the Facebook SDK.