当前位置: 首页 > 面试题库 >

将Instagram添加到UIActivityViewController

高宏峻
2023-03-14
问题内容

我正在尝试使用standard共享图像UIActivityViewController,可以使用以下代码在 Facebook
TwitterSave Image 共享:

let firstActivityItem = "foo text"
let secondActivityItem : UIImage = image!

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

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

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

我还需要一件事, Instagram

If UIApplication.sharedApplication().canOpenURL(instagramURL!) {
            // Success
            var img = image!

            var savePath: String = NSHomeDirectory().stringByAppendingPathComponent("Documents/Test.igo")
            UIImageJPEGRepresentation(img, 1).writeToFile(savePath, atomically: true)
            var imgURL = NSURL(string: NSString(format: "file://%@", savePath) as! String)
            docController = UIDocumentInteractionController(URL: imgURL!) // 1
            docController.UTI = "com.instagram.exclusivegram" // 2
            docController.delegate = self
            docController.annotation = ["InstagramCaption":"testsss"] // 3
            docController.presentOpenInMenuFromRect(self.view.frame, inView: self.view, animated: true) // 4
        } else {
            // Error
        }

这两个代码分别工作正常,如何将 Instagram 添加到UIActivityViewController?有可能吗?


问题答案:

我认为将其他社交共享添加到您为Instagram编写的代码中会更加容易。“
.igo”扩展名是Instagram专有的,因此其他应用程序将不支持它。只需将此扩展名从“ .igo”更改为“ .ig”,其他应用程序就会读取它:

var savePath: String = NSHomeDirectory().stringByAppendingPathComponent("Documents/Test.ig")

但是Instagram还具有专有的UTI,可避免其他应用程序出现在同一文档交互视图中。因此,您还需要将其从“独占图”更改为“照片”:

docController.UTI = "com.instagram.photo"

我有一个具有类似功能的应用,这是我的原始代码:

@IBAction func shareOnIntagram(sender: UIButton) {

        let finalImage: UIImage = UIImage.imageWithView(photoView)
        let instagramURL = NSURL(string: "instagram://app")
        if (UIApplication.sharedApplication().canOpenURL(instagramURL!)) {

            let imageData = UIImageJPEGRepresentation(finalImage, 1)
            let captionString = "caption"
            let writePath = (NSTemporaryDirectory() as NSString).stringByAppendingPathComponent("instagram.ig")
            if imageData?.writeToFile(writePath, atomically: true) == false {

                return

            } else {

                let fileURL = NSURL(fileURLWithPath: writePath)
                self.documentController = UIDocumentInteractionController(URL: fileURL)
                self.documentController.delegate = self
                self.documentController.UTI = "com.instagram.photo"
                self.documentController.annotation = NSDictionary(object: captionString, forKey: "InstagramCaption")
                self.documentController.presentOpenInMenuFromRect(self.view.frame, inView: self.view, animated: true)
            }

        } else {
            print(" Instagram is not installed ")
        }
    }

为了使此代码正常工作,请不要忘记添加UIDocumentInteractionControllerDelegateUIViewController类。



 类似资料:
  • 问题内容: RelativeLayout layout = new RelativeLayout(this); AndroidApplicationConfiguration config = new AndroidApplicationConfiguration(); View gameView = initializeForView(new MainGame(), config); 什么也没显

  • 问题内容: 现在,我正在通过jquery加载iframe: 我有一个自定义样式表,希望将其应用于该页面。iframe中的页面不在同一域中,这就是为什么它很棘手的原因。我找到了允许您添加单个标签但不能添加整个样式表的解决方案。 编辑: 有问题的页面通过Mobile Safari 加载,因此跨域策略不适用。 问题答案: 基于解决方案您已经找到了如何将CSS应用于iframe?: 或更多jqueryis

  • 问题内容: 我有一个gui,它的Panel包含一系列标签和TextField,并使用spring布局(这是mainPanel),而另一个Panel仅包含button(buttonPanel)。我正在尝试使我的mainPanel也具有垂直滚动条。我想实现我的GUI,以便在JFrame中有2个面板。mainPanel出现在框架的顶部,而buttonPanel出现在mainPanel的下方。 我的问题是

  • 问题内容: 我今天在这个主题上搜索了很多。但是我找不到它,如何将JSONArray添加到JSONObject? 因为每次执行此操作都会收到此错误:Stackoverflow 我收到此错误: 我想要的JSON:只有最后一个JsonArray出问题了: ,“ vloer”:[{formaat:’vierkant10x15’tegels:[{naam:’‘,imgThumb:’/bla/bla.png’

  • 我正在尝试将此 JPanel 添加到 JFrame 中,但我看不到他。当我创建新的 java 类并自己制作这个框架时,一切都很好。 来自JFrame表单的代码。 来自 JPanel 的代码: 来自Java类的代码。 我想不出区别在哪里。有人能帮我吗?