从系统相册中选择GIF图片上传到服务器

-(void)assetPickerController:(ZYQAssetPickerController *)picker didFinishPickingAssets:(NSArray *)assets
{
    for (int i = 0; i < assets.count; i ++) {
        ALAsset *asset = assets[i];
        ALAssetRepresentation *rep = [asset defaultRepresentation]; 
       
        if ([rep.UTI hasSuffix:@"gif"]) {//选中的是gif
       
            //拼接gif的文件路径
            NSString *document = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];
            NSString *filePath = [document stringByAppendingPathComponent:rep.filename];
     
            BOOL fileExist = [[NSFileManager defaultManager] fileExistsAtPath:filePath];
            if (!fileExist) {//选中的gif还未写入到沙盒
               
                //把选中的gif写入到沙盒中
                Byte *imageBuffer = (Byte*)malloc(rep.size);
                NSUInteger bufferSize = [rep getBytes:imageBuffer fromOffset:0.0 length:rep.size error:nil];
                NSData *imageData = [NSData dataWithBytesNoCopy:imageBuffer length:bufferSize freeWhenDone:YES];
                [imageData writeToFile:filePath atomically:YES];
            }
            [_selectImages addObject:filePath];
        }
    }
}

//然后根据写入到沙盒中的GIF图片的路径来上传

posted @ 2015-05-25 17:29  2014_4_30  阅读(538)  评论(0编辑  收藏  举报