Sending image + url in UIActivityViewController in Facebook Messenger
Asked Answered
E

1

22

using a simple UIActivityViewController

-(void)share{

    NSString *textToShare = _mytext;
NSURL *url = [NSURL URLWithString:@"http://www.google.com"];
    UIImage *imageToShare = _myimage;
    NSArray *activityItems = @[textToShare, url,  imageToShare];
    UIActivityViewController *activityVC =
    [[UIActivityViewController alloc] initWithActivityItems:activityItems
                                      applicationActivities:nil];

    [self presentViewController:activityVC animated:YES completion:nil];
}

I want to share a text, url and image where appropriate.

So if the user chooses mail, everything appears. Etc with the rest of the apps (pinterest, facebook, twitter)

On Facebook Messenger - If a url and an image is shared, the share screen crashes. Is this a known issue (can't send image with a url)?

Expedition answered 18/5, 2015 at 11:50 Comment(6)
It might be a bug. Can you report it here? Please include your Messenger version and stack trace.Prosector
developers.facebook.com/bugs/949486035103197/?search_id looks likes its widespread from at least 2 versions ago...Expedition
Change your NSURL to an NSString and it should work fine.Fissionable
@Fissionable then it won't be sharing a url, but a regular nsstring...Expedition
That is correct but FB will usually translate it into a link when posted. It is best to use NSURL but it can be flaky. I have also found that creating the activity array like this seems to work better, not sure why but it does. [NSArray arrayWithObjects:textToShare,url,nil];Fissionable
I am sharing text and Image to FB-messenger with UiActivitycController but it is opening only Image and text part is empty, I tried sharing only text and then UIActivityControl not showing FB-messenger share option. Seems like something related with same messenger bug.Raychel
D
1

* EDIT: Updated to the latest SDK

FBSDKShareLinkContent *content = [[FBSDKShareLinkContent alloc] init];
content.contentTitle = @"Your title";
content.contentDescription = @"Some description text maybe...";
content.contentURL = [NSURL URLWithString:@"http://yourlink.com"];
content.imageURL = [NSURL URLWithString:@"http://yourlink.com/theImage.png"];

[FBSDKMessageDialog showWithContent:content delegate:self];


// Delegate
- (void)sharer: (id<FBSDKSharing>)sharer didCompleteWithResults: (NSDictionary *)results 
{
    BOOL complete = [[results valueForKeyPath:@"didComplete"] boolValue];
    NSString *completionGesture = [results valueForKeyPath:@"completionGesture"];
    if (completionGesture && [completionGesture isEqualToString:@"cancel"]) {
        // action was canceled by the user
    }

    if (complete) {
        // the message/link/image was sent
    }
}

- (void) sharer:(id<FBSDKSharing>)sharer didFailWithError:(NSError *)error
{
    // handle error...
}

You can give it a try :)

Diehl answered 27/5, 2015 at 12:43 Comment(2)
that is facebook, not messenger and not in uiactivitycontrollerExpedition
This is not UIActivityViewController.Bournemouth

© 2022 - 2024 — McMap. All rights reserved.