在Facebook Messenger中的UIActivityViewController中发送图像+网址

时间:2015-05-18 11:50:48

标签: ios facebook uiactivityviewcontroller facebook-messenger

使用简单的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];
}

我想在适当的时候分享文字,网址和图片。

因此,如果用户选择邮件,则会显示所有内容。与其他应用程序等(pinterest,facebook,twitter)

在Facebook Messenger上 - 如果共享了网址和图片,则共享屏幕会崩溃。这是一个已知问题(无法使用网址发送图片)吗?

1 个答案:

答案 0 :(得分:4)

*编辑:已更新至最新的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...
}

你可以尝试一下:)