有没有办法获取设备上已安装应用程序的列表,该应用程序能够共享和接收文本数据

Is there way to get list of installed app on device, which is able to share and receive text data

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

有 UIActivityViewController 列出所有应用程序,您可以在其中共享您的文本。您可以通过那里的 "More" 选项自定义列表。具有共享扩展名的应用程序也会自动在此处列出。

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

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

或者您也可以创建自定义 UIActivity。 在您的自定义 UIActivity 子类中,您只需重写一个方法:

+ (UIActivityCategory)activityCategory
{
   return UIActivityCategoryShare;
}