Gif animation to video wrong converting


Hi all,

there is a strange behavior of twitter, while trying to post gif animation to twitter, created by iOS application:

all preview at browsers and mail play the animation the proper way, however, after I post it to twitter (both from browser and iOS device) it shows several frames at once, shifts some frames respectively one another etc

what can cause this strange behavior ?
I create this gif animation by the following code:

 func createGIF(with images: [UIImage], loopCount: Int = 0, frameDelay: Double) {
        let fileProperties = [kCGImagePropertyGIFDictionary as String: [kCGImagePropertyGIFLoopCount as String: loopCount]]
        let frameProperties = [kCGImagePropertyGIFDictionary as String: [kCGImagePropertyGIFDelayTime as String: frameDelay]]
        let documentsDirectory = NSTemporaryDirectory()
        let url = NSURL(fileURLWithPath: documentsDirectory)?.URLByAppendingPathComponent("animated.gif")
        if let url = url {
            let destination = CGImageDestinationCreateWithURL(url, kUTTypeGIF, UInt(images.count), nil)
            CGImageDestinationSetProperties(destination, fileProperties)
            for i in 0..<images.count {
                CGImageDestinationAddImage(destination, images[i].CGImage, frameProperties)
            if CGImageDestinationFinalize(destination) {
                let data = NSData(contentsOfURL: url)
                //println("success \(url)")
                let library = ALAssetsLibrary()
                library.writeImageDataToSavedPhotosAlbum(data, metadata: nil, completionBlock:{
                    (assetURL: NSURL!, error: NSError!) -> Void in
            else {

it seems, there are some special requirements for gif animation, for their proper transformation to video by twitter

The preview at twitter (small square area, where I can preview the animation) plays the animation correctly.

PS I wasn’t sure what category is that