在IOS应用程序中共享扩展 [英] Sharing Extensions in IOS Apps

查看:199
本文介绍了在IOS应用程序中共享扩展的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是整个iOS编程的新手 - Swift。我想知道,如果我在xCode6中创建一个项目,然后我想分享一个我从我的项目中获取的图像,例如evernote,google驱动器,消息,电子邮件,facebook,twitter等等。

I am new to the overall iOS Programming - Swift. I am wondering that if I create a project in xCode6 and then I would like to share an image that I took from my project for example to evernote, google drive, messages, email, facebook, twitter,so on and so on.

那么,我该怎么做?是什么,我需要从xcode6为每个共享扩展启用,或者我需要实现swift代码来启用这些共享扩展?

So, how would I do that? Is it something, I need to enable from xcode6 for each sharing extension or I need to implement swift code to enable these sharing extensions?

我可能需要什么样的配置改变以获得共享扩展(如上所述)?或者项目中的代码更改是可能的?是否有任何示例或示例,其中包含我可以查看的说明,并了解它们如何在xcode6中实现。

What kind of configurations I might needs to change to get sharing extensions (mentioned above) enabled? Or what kind of code changes in a project are possible? Are there any examples or samples out there with the instructions that I can look into and see how they implement into xcode6.

我以前从未使用过共享扩展,所以任何可以分享的知识对我来说将是一个很好的资源。提前致谢!

I never work with the sharing extensions before, so any knowledge that can be shared will be a great resource for me. Thanks in advance!

推荐答案

使用Xcode共享模板

有很多在线教程知道如何使用Swift进行共享扩展,这里有一些和一些关于扩展你应该知道的好文章:

There is a lot of tutorials online to know how to make share extensions using Swift, here are some of them and some good articles about extensions you should know too :

即使您也可以通过以下方式在代码中执行此操作:

Even you could do it in code too in the following way:

@IBAction func shareSheet(sender: AnyObject){

    let firstActivityItem = "Hey, check out this mediocre site that sometimes posts about Swift!"

    let secondActivityItem : NSURL = NSURL(fileURLWithPath: "http://www.dvdowns.com/")!

    let activityViewController : UIActivityViewController = UIActivityViewController(
    activityItems: [firstActivityItem, secondActivityItem], applicationActivities: nil)

    activityViewController.excludedActivityTypes = [
      UIActivityTypePostToWeibo,
      UIActivityTypePrint,
      UIActivityTypeAssignToContact,
      UIActivityTypeSaveToCameraRoll,
      UIActivityTypeAddToReadingList,
      UIActivityTypePostToFlickr,
      UIActivityTypePostToVimeo,
      UIActivityTypePostToTencentWeibo
    ]

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

以上代码仅适用于iPhone,因为对于iPad,您需要指定 sourceView 并按以下方式将其显示为弹出窗口:

The above code only works for iPhones because for iPad you need to specify the sourceView and show it as a popover in the following way:

activityViewController.popoverPresentationController?.sourceView = (sender as! UIButton) 

上面的行必须在你初始化 activityViewController 后放入,它应该工作。

The above line must be put in just after you init the activityViewController and it should be work.

我希望这能帮到你。

这篇关于在IOS应用程序中共享扩展的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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