-1

喜欢与 Whatsapp 代码共享文本数据如下。我想知道设备上所有已安装的能够获取文本数据的应用程序,如下面提到的代码。

 NSString * msg = @"YOUR MSG"; NSString * urlWhats = [NSString stringWithFormat:@"whatsapp://send?text=%@",msg]; NSURL * whatsappURL = [NSURL URLWithString:[urlWhats stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]; if ([[UIApplication sharedApplication] canOpenURL: whatsappURL]) {
        [[UIApplication sharedApplication] openURL: whatsappURL]; } else {
        UIAlertView * alert = [[UIAlertView alloc] initWithTitle:@"WhatsApp not installed." message:@"Your device has no WhatsApp installed." delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
        [alert show]; }
4

2 回答 2

3

与 twitter/facebook 以外的其他社交应用程序共享文本、数据。你可以试试下面的代码:

NSString *shareString = @"text...";
UIImage *shareImage = [UIImage imageNamed:@"image.png"];
NSURL *shareUrl = [NSURL URLWithString:@"http://www.test.com"];

NSArray *activityItems = [NSArray arrayWithObjects:shareString, shareImage, shareUrl, nil];

UIActivityViewController *activityViewController = [[UIActivityViewController alloc] initWithActivityItems:activityItems applicationActivities:nil];
activityViewController.modalTransitionStyle = UIModalTransitionStyleCoverVertical;

[self presentViewController:activityViewController animated:YES completion:nil];

它将显示显示所有其他文本共享应用程序的活动视图。

或者您也可以创建自定义 UIActivity。在您的自定义 UIActivity 子类中,您必须简单地覆盖一种方法:

+ (UIActivityCategory)activityCategory
{
   return UIActivityCategoryShare;
}
于 2015-06-19T10:42:44.723 回答
0

有 UIActivityViewController 列出所有应用程序,您可以在其中分享您的文本。您可以通过那里的“更多”选项自定义列表。具有共享扩展名的应用程序也会自动在此处列出。在此处输入图像描述

于 2015-06-19T10:27:09.717 回答