我可以从 UIActivityViewController 和本机 UIActivityTypePostToTwitter 发送动画 GIF 吗? [英] Can I tweet an animated GIF from a UIActivityViewController and the native UIActivityTypePostToTwitter yet?

查看:20
本文介绍了我可以从 UIActivityViewController 和本机 UIActivityTypePostToTwitter 发送动画 GIF 吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 UIActivityViewController 共享一个对象

  • 符合UIActivityItemSource协议和
  • 通过在适当的方法中返回 .gif 文件的 NSURLCFBridgingRelease(kUTTypeGIF) 来提供动画 GIF 文件.

如果我在新邮件消息中共享我的一个对象,我会看到 GIF 在模拟器中移动.如果我尝试在推特上发布相同的内容,则推文会附加一帧图像,但它会作为静止图像上传.

我是否需要等待 Apple 在未来的 iOS 版本中更新 UIActivityTypePostToTwitter,或者我是否错过了您在某处看到的解决方法?(我意识到这个案例没有使用列表中的任何内容Twitter.com、Android 和 iPhone [应用]".这可能是徒劳的请求.)

作业已经完成:

  • 我知道Twitter 活动类型也可以与 ALAsset 对象一起使用,并且人们通过将他们的数据保存在 ALAssets 中来将动画 gif 输入和输出保存的照片,但我希望能够发布这些 gif如果可能,不要触摸相机胶卷.
  • 我检查了 NSHipster.
  • 根据 Lyndsey 关于 Twitter API 的提示,我尝试为我的本地 .gif 文件返回 NSData 对象而不是 NSURL.没有变化.
  • Twitter API 文档:

    <块引用><块引用>

    传递的图像应该是图像的原始二进制或二进制 base64 编码,只要 Content-Type 设置适当,就不需要以其他方式编码或转义内容(如有疑问:application/octet-stream").

    但是我的推文中没有出现任何图像.

谢谢!

解决方案

遇到了类似的问题,google了很多,还是没有一个完美的解决方案,我想到的最好的就是这里:

使用 UIActivityItemProvider 并扩展 - (id)item {} 用于不同的 UIActivityType:

Twitter:默认的 UIActivityViewController Twitter 共享还不支持它,它将缩小"它作为静止的 JPG.但是不知何故它适用于小于 100kb 的 GIF(在 iOS 9 中测试),我不知道为什么.因此,我必须按照 此处.当 SLRequest 完成并返回时,关闭 UIActivityViewController.缺点是没有预览共享表,用户无法再输入自己的消息.

- (id)item{if ([self.activityType isEqualToString:UIActivityTypePostToFacebook]) {//上传到 Giphy...返回 [NSURL URLWithString:giphyURL];}如果 ([self.activityType isEqualToString:UIActivityTypePostToTwitter]) {//使用 SLRequest 来共享...//关闭 UIActivityViewController(我使用的是 Unity)[UnityGetGLViewController()dismissViewControllerAnimated:NO 完成: NULL];返回零;}}

完整代码在我的 GitHub 中,我实际上是 iOS 新手,所以请一些专家纠正我并如果可能的话,代码

I have a UIActivityViewController sharing an object that

  • conforms to the UIActivityItemSource protocol and
  • offers an animated GIF file by returning an NSURL of a .gif file and CFBridgingRelease(kUTTypeGIF) in the appropriate methods.

I see the GIF moving in the Simulator if I share one of my objects in a new Mail message. If I try tweeting the same thing, a frame of the image is attached to the tweet, but it's uploaded as a still image.

Do I need to wait for Apple to update UIActivityTypePostToTwitter in a future iOS version, or have I missed a workaround you've seen somewhere? (I realize this case isn't using anything from the list "Twitter.com, Android and iPhone [app]". This is probably a futile plea.)

Homework already done:

  • I know that the Twitter activity type can also work with an ALAsset object, and people get animated gifs into and out of Saved Photos by keeping their data wrapped up in ALAssets, but I want to be able to tweet these gifs without touching the Camera Roll, if possible.
  • I checked NSHipster.
  • I tried returning an NSData object instead of an NSURL for my local .gif file on a tip from Lyndsey about the Twitter API. No change.
  • I tried returning kUTTypeData instead of kUTTypeGIF as the dataTypeIdentifierForActivityType after seeing this in the Twitter API docs:

    The image passed should be the raw binary of the image or binary base64 encoded, no need to otherwise encode or escape the contents as long as the Content-Type is set appropriately (when in doubt: "application/octet-stream").

    but then no image appeared in my tweet.

Thanks!

解决方案

Encountered the similar problem and Googled a lot but still not a perfect solution, the best I came up is here:

Use UIActivityItemProvider and extend - (id)item {} for different UIActivityType:

Twitter: The default UIActivityViewController Twitter share doesn't support it yet which it will "scale down" it as a still JPG. However somehow it works for GIF less than 100kb (tested in iOS 9) and I don't know why. Therefore, I have to use SLRequest to upload the GIF as taught in here. When the SLRequest is done and return, dismiss the UIActivityViewController. The downside of that is no preview share sheet and users cannot type their own message anymore.

- (id)item
{    
    if ([self.activityType isEqualToString:UIActivityTypePostToFacebook]) {
        // Upload to Giphy
        ...
        return [NSURL URLWithString:giphyURL];
    }
    if ([self.activityType isEqualToString:UIActivityTypePostToTwitter]) {
        // Use SLRequest to share instead
        ...
        // Dismiss the UIActivityViewController (I am using Unity)
        [UnityGetGLViewController() dismissViewControllerAnimated:NO completion: NULL];
        return nil;
    }
}

full code is in my GitHub, I am actually a iOS newb so some experts please correct me and the code if possible

这篇关于我可以从 UIActivityViewController 和本机 UIActivityTypePostToTwitter 发送动画 GIF 吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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