Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xcode/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/user-interface/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Xcode swift将gif动画发布到twitter_Xcode_Swift_Animation_Twitter_Uiimage - Fatal编程技术网

Xcode swift将gif动画发布到twitter

Xcode swift将gif动画发布到twitter,xcode,swift,animation,twitter,uiimage,Xcode,Swift,Animation,Twitter,Uiimage,使用swift语言,我试图将创建的gif动画发布到twitter上,但是该界面仅支持addImage-发布普通图像。当我将gif保存到照片时,使用 let data = NSData(contentsOfURL: url) var library : ALAssetsLibrary = ALAssetsLibrary() library.writeImageDataToSavedPhotosAlbum(data, metadata: nil, c

使用swift语言,我试图将创建的gif动画发布到twitter上,但是该界面仅支持addImage-发布普通图像。当我将gif保存到照片时,使用

let data = NSData(contentsOfURL: url)
            var library : ALAssetsLibrary = ALAssetsLibrary()

            library.writeImageDataToSavedPhotosAlbum(data, metadata: nil, completionBlock:{
                (assetURL: NSURL!, error: NSError!) -> Void in
            })
它工作得很好,可以从照片中发布gif动画,但是,在twitter界面中没有这样的东西可以从应用程序中发布

有一些建议,如创建带图像的动画图像:

 let im = UIImage.animatedImageWithImages(imga, duration: 0.1)
                tweetSheet.addImage(im)
但id也不起作用,发布静态图像


还有其他选择吗?

Twitter现在支持动画GIF,所以不确定您是否已经解决了问题。我已经用动画GIF测试了这段代码

func tweetWithImage(data:NSData)
{

    let account = ACAccountStore()
    let accountType = account.accountTypeWithAccountTypeIdentifier(
        ACAccountTypeIdentifierTwitter)

    account.requestAccessToAccountsWithType(accountType, options: nil,
        completion: {(success: Bool, error: NSError!) -> Void in
            if success {
                let arrayOfAccounts =
                account.accountsWithAccountType(accountType)

                if arrayOfAccounts.count > 0 {
                    let twitterAccount = arrayOfAccounts.first as! ACAccount
                    var message = Dictionary<String, AnyObject>()
                    message["status"] = "Test Tweet with image"

                    let requestURL = NSURL(string:
                        "https://api.twitter.com/1.1/statuses/update.json")
                    let postRequest = SLRequest(forServiceType:
                        SLServiceTypeTwitter,
                        requestMethod: SLRequestMethod.POST,
                        URL: requestURL,
                        parameters: message)

                    postRequest.account = twitterAccount
                    postRequest.addMultipartData(data, withName: "media", type: nil, filename: nil)

                    postRequest.performRequestWithHandler({
                        (responseData: NSData!,
                        urlResponse: NSHTTPURLResponse!,
                        error: NSError!) -> Void in
                        if let err = error {
                            println("Error : \(err.localizedDescription)")
                        }
                        println("Twitter HTTP response \(urlResponse.statusCode)")

                    })
                }
            }
            else
            {
                // do what you want here

            }
    })
}
我在我的博客上放了一个教程,其中包含GitHub中相应的项目,说明了如何使用SLRequest,以便支持动画GIF…您可以在这里看到:

注意:这个答案中的博客代码和代码片段是通过使用update_with_media来更新请求URL的,因为后者在Twitter API中已被弃用