Nick Ginanto
Nick Ginanto

Reputation: 32130

Sending image + url in UIActivityViewController in Facebook Messenger

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)?

Upvotes: 22

Views: 4550

Answers (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 :)

Upvotes: 1

Related Questions