如何与Facebook,Twitter等共享应用程序共享String? [英] How to share a String with sharing apps like Facebook, Twitter, etc.?

查看:78
本文介绍了如何与Facebook,Twitter等共享应用程序共享String?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个应用程序,我想有一个共享按钮,该按钮允许用户从可以共享的列表中选择一个应用程序,然后打开该应用程序或某种允许其发布鸣叫的对话框,短信等.

I'm developing an App and I want to have a Share button that allows users to pick an app from a list that they can share from, which then opens up that app or some sort of dialog that lets them tweet, post, text message, etc.

我已经在Android应用程序上实现了这一目标,因为在其中创建ACTION_SEND意图非常简单,并根据某些模仿类型来筛选要共享的应用程序.

I've achieved this on my Android app because it is extremely simple there to create an ACTION_SEND intent, and filter based on certain mimetypes for what apps to share with.

我想要与iOS8和Swift类似的东西,但在任何地方都找不到如何实现此目的的

I want something similar with iOS8 and Swift but I can't find anywhere how to achieve this.

我不想在我的应用程序中具有用于与Twitter共享或与Facebook共享或……共享的按钮,我只是想对共享资源执行ping操作,以使我成为可以与之共享的应用程序,然后拥有用户选择一个,然后使用我的String进入应用程序.

I don't want to have buttons in my app for sharing with Twitter, or sharing with Facebook, or ... I just want to ping a sharing resource that gets me the apps that are candidates to share with and then have the user choose one, which then proceeds to the app with my String.

更新

因此,我想出了一种方法:

So, I figured out a way to do it:

var sharingItems = [AnyObject]()

sharingItems.append(NSString(string: "Whatever you want to share!"))

let activityViewController = UIActivityViewController(activityItems: sharingItems, applicationActivities: nil)

self.presentViewController(activityViewController, animated: true, completion: nil)

然后电话会确定您可以ping的内容,例如Twitter,Tumblr,Messenger等.

The phone then figures out what you could ping, such as Twitter, Tumblr, Messenger, etc.

很高兴,我发现Facebook不在名单上令我有些惊讶.我也没有尝试这种方法,因为尽管从iOS 8开始不推荐使用Share Sheets,而是使用Application Extensions.

Granted, I was a bit surprised to find Facebook wasn't on the list. I also didn't try this route because I though the Share Sheets were deprecated from iOS 8 in favor of Application Extensions.

如果有更好的方法或另一种方法应该在iOS 8中完成,请告诉我:)

If there is a better way or another way this should be done in iOS 8, let me know please :)

推荐答案

只是为您提供更全面的解决方案(实际上Facebook是一个选择),您可以使用UIActivityViewController exclude 与社交媒体共享(例如与Facebook和Twitter分享)无关的项目,您可以排除其他所有内容,例如:

Just to give you a more comprehensive solution (for which Facebook is in fact an option), you can use a UIActivityViewController and exclude the irrelevant items in order to share to social media, for example to share to Facebook and Twitter you can exclude everything else like so:

let activityViewController = UIActivityViewController(activityItems:
  ["Whatever you want to share!"], applicationActivities: nil)
let excludeActivities = [
    UIActivityTypeMessage,
    UIActivityTypeMail,
    UIActivityTypePrint,
    UIActivityTypeCopyToPasteboard,
    UIActivityTypeAssignToContact,
    UIActivityTypeSaveToCameraRoll,
    UIActivityTypeAddToReadingList,
    UIActivityTypePostToFlickr,
    UIActivityTypePostToTencentWeibo,
    UIActivityTypeAirDrop]
activityViewController.excludedActivityTypes = excludeActivities;

presentViewController(activityViewController, animated: true,
  completion: nil)

查看全文

登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆