如何从 iOS 应用程序在 viber、Facebook Messenger 和 Instagram 上分享文本?

How to share Text on viber , Facebook messenger and Instagram from iOS application?

如果有人知道如何将文本分享到 viber Facebook Messenger 和 instagram,请提供一些参考。

我已经尝试使用默认的canOpenURL viber 和 Facebook-messenger 方法如下:

代码:

NSURL *fbURL = [NSURL URLWithString:@"fb-messenger://user-thread/USER-ID/"];
if ([[UIApplication sharedApplication] canOpenURL: fbURL]) {
    [[UIApplication sharedApplication] openURL: fbURL];
}
 NSString * urlViber = [NSString stringWithFormat:@"viber://send?  Text=text"];
NSURL * viberURL = [NSURL URLWithString:[urlViber stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
if ([[UIApplication sharedApplication] canOpenURL: viberURL]) {
    [[UIApplication sharedApplication] openURL: viberURL];
} else {
    Alert(@"Viber not installed.", @"Your device has no Viber installed.")
}

但上面的代码只是重定向到应用程序。它不会将文本传递到应用程序文本字段。

等待专家提供有用的指导。:)

试试下面的代码,伙计,它会成功的,如果你有任何问题,请告诉我

NSString *string = [NSString stringWithFormat:@"%@  \n\n%@ %@ \n\n%@", @"Hey !" ,Str_Moretext,Str_caption,@""];

    NSURL *URL =[NSURL URLWithString:Str_ServerUrl];
     //UIImage *image=[UIImage imageNamed:@"ReferUsers.png"];

    @try {
         UIActivityViewController *activityViewController = [[UIActivityViewController alloc] initWithActivityItems:@[string, URL] applicationActivities:nil];
        [self presentViewController:activityViewController animated:YES completion:^{
        }];
    } @catch (id theException) {
        NSLog(@"Received error %@",theException);

    }

对于 Viber:

[NSURL URLWithString:@"viber://forward?text=sdlmfkkanfj"]

对于 Instagram: 你必须分享带文字的图片,只能分享你不能分享的文字。

NSURL *instagramURL = [NSURL URLWithString:@"instagram://app"];

if ([[UIApplication sharedApplication] canOpenURL:instagramURL])
{       
    NSString  *jpgPath = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/image.igo"];
    NSString *urlString = [[NSString alloc] initWithFormat:@"file://%@", jpgPath];        
    NSURL *imageUrl = [[NSURL alloc] initWithString: urlString];

    self.docController = [self setupControllerWithURL:imageUrl usingDelegate:self];
    self.docController.UTI = @"com.instagram.exclusivegram";
    self.docController.annotation = [NSDictionary dictionaryWithObject:@"I_want_to_share_this_text" forKey:@"InstagramCaption"];

    [self.docController presentOpenInMenuFromRect: self.view.frame inView: self.view animated: YES ];
}