码迷,mamicode.com
首页 > 其他好文 > 详细

相册选原图倒置解决方案

时间:2015-04-30 19:53:54      阅读:139      评论:0      收藏:0      [点我收藏+]

标签:

 

相册选原图倒置解决方案

- (void)addMediaToUploadQueue:(ALAsset *)media {
    @autoreleasepool {
        ALAssetRepresentation *defaultRepresentation = [media defaultRepresentation];
        CGImageRef fullResolutionImage = [defaultRepresentation fullResolutionImage];

        // Return if the user is trying to upload an image which has already been uploaded
        CGFloat scale = [defaultRepresentation scale];
        UIImageOrientation orientation = [defaultRepresentation orientation];

        UIImage *i = [UIImage imageWithCGImage:fullResolutionImage scale:scale orientation:orientation];
        if (![self isImageUnique:i]) return;

        NSDictionary *imageDictionary = [self dictionaryForAsset:media withImage:i];

        dispatch_async(self.background_queue, ^{
            NSManagedObjectContext *ctx = [APPDELEGATE createManagedObjectContextForThread];
            [ctx setUndoManager:nil];

            [ctx performBlock:^{
                ImageEntity *newImage = [NSEntityDescription insertNewObjectForEntityForName:@"ImageEntity"
                                                                    inManagedObjectContext:ctx];

                [newImage updateWithDictionary:imageDictionary
                         inManagedObjectContext:ctx];

                [ctx save:nil];

                [APPDELEGATE saveContext];

                dispatch_async(dispatch_get_main_queue(), ^{
                    [self.fetchedResultsController performFetch:nil];
                });

                    if (!currentlyUploading) {
                        currentlyUploading = YES;
                        [self uploadImage:newImage];
                    }
            }];
        });
    }
}

 

相册选原图倒置解决方案

标签:

原文地址:http://www.cnblogs.com/nonato/p/4469568.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!