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

Nick Ginanto
  • 31,090
  • 47
  • 134
  • 244
  • It might be a bug. Can you [report it here](https://developers.facebook.com/bugs/)? Please include your Messenger version and stack trace. – amudi May 25 '15 at 05:02
  • https://developers.facebook.com/bugs/949486035103197/?search_id looks likes its widespread from at least 2 versions ago... – Nick Ginanto May 25 '15 at 08:41
  • Change your NSURL to an NSString and it should work fine. – rmp May 27 '15 at 22:53
  • @rmp then it won't be sharing a url, but a regular nsstring... – Nick Ginanto May 28 '15 at 15:26
  • 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];` – rmp May 28 '15 at 15:46
  • 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. – Abhishek May 29 '15 at 10:30

1 Answers1

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