How to share text to viber, Facebook messenger and Instagram from iOS app?

If anyone has any idea on how to share text with venger Facebook messenger and instagram please give some link.

I tried defult method canOpenURL

for viber and Facebook-messenger as below:

Code:

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

      

But the above code is just redirecting the application. It does not pass text to the application text box.

Waiting for helpful guidance from experts .. :)

+3


source to share


2 answers


For Viber:

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

      



For Instagram: you must share an image with text, only text that you cannot 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 ];
}

      

0


source


Try using below code, it will work, if you have any problem please let me know



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


source







All Articles