如何在iOS应用程序上分享viber,Facebook messenger和Instagram上的文本?

时间:2015-06-04 05:46:57

标签: ios objective-c nsurl uiapplication

如果有人知道如何与viber Facebook Messenger和Instagram共享文本,请提供一些参考。

我尝试使用viber和Facebook-messenger的defult canOpenURL方法,如下所示:

代码:

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.")
}

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

等待专家提供的有用指南.. :)

2 个答案:

答案 0 :(得分:1)

尝试下面的代码,它会解决,如果你有任何问题通知我

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

    }

答案 1 :(得分:0)

For Viber:

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

For Instagram: you have to share Image with text, Only text you cant share.

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 ];
}