From 50fae8fc607c5d693e87e31fd2b379a03d7a1918 Mon Sep 17 00:00:00 2001 From: lilthree <87437904@qq.com> Date: Mon, 22 Jan 2018 21:23:40 +0700 Subject: [PATCH] fix crash when uploading --- Pod/Classes/SeafUploadFile.m | 6 +---- Pod/Classes/Utils.m | 50 +++++++++++++++++++----------------- 2 files changed, 27 insertions(+), 29 deletions(-) diff --git a/Pod/Classes/SeafUploadFile.m b/Pod/Classes/SeafUploadFile.m index f0061ed4..a9851fa7 100644 --- a/Pod/Classes/SeafUploadFile.m +++ b/Pod/Classes/SeafUploadFile.m @@ -491,11 +491,7 @@ - (void)upload:(SeafConnection *)connection repo:(NSString *)repoId path:(NSStri - (BOOL)runable { if (!_udir) return false; - if (_autoSync) { - [self performSelectorInBackground:@selector(checkAsset) withObject:nil]; - } else { - [self checkAsset]; - } + [self checkAsset]; if (![Utils fileExistsAtPath:self.lpath]) return false; if (self.autoSync && _udir->connection.wifiOnly) return [[AFNetworkReachabilityManager sharedManager] isReachableViaWiFi]; diff --git a/Pod/Classes/Utils.m b/Pod/Classes/Utils.m index 4489b901..cf7d5f13 100644 --- a/Pod/Classes/Utils.m +++ b/Pod/Classes/Utils.m @@ -353,31 +353,33 @@ + (BOOL)writeDataToPathNoMeta:(NSString*)filePath andAsset:(ALAsset*)asset + (BOOL)writeDataToPathWithMeta:(NSString*)filePath andAsset:(ALAsset*)asset { - ALAssetRepresentation *defaultRep = asset.defaultRepresentation; - CGImageRef cgimg = [defaultRep CGImageWithOptions:defaultRep.metadata]; - UIImage *image = [UIImage imageWithCGImage:cgimg]; - CGImageSourceRef source = CGImageSourceCreateWithData((CFDataRef)UIImageJPEGRepresentation(image, 1.0), NULL); - - NSURL *url = [[NSURL alloc] initFileURLWithPath:filePath]; - CFStringRef UTI = CGImageSourceGetType(source); //this is the type of image (e.g., public.jpeg) - CGImageDestinationRef destination = CGImageDestinationCreateWithURL((CFURLRef)url, UTI, 1, NULL); - if(!destination) { - Debug("***Could not create image destination ***"); - return false; - } - - //add the image contained in the image source to the destination, overidding the old metadata with our modified metadata - CGImageDestinationAddImageFromSource(destination, source, 0, (CFDictionaryRef)defaultRep.metadata); - - //tell the destination to write the image data and metadata into our data object. - //It will return false if something goes wrong - BOOL success = CGImageDestinationFinalize(destination); - if (!success) { - Debug("***Could not create data from image destination ***"); + @autoreleasepool { + ALAssetRepresentation *defaultRep = asset.defaultRepresentation; + CGImageRef cgimg = [defaultRep CGImageWithOptions:defaultRep.metadata]; + UIImage *image = [UIImage imageWithCGImage:cgimg]; + CGImageSourceRef source = CGImageSourceCreateWithData((CFDataRef)UIImageJPEGRepresentation(image, 1.0), NULL); + + NSURL *url = [[NSURL alloc] initFileURLWithPath:filePath]; + CFStringRef UTI = CGImageSourceGetType(source); //this is the type of image (e.g., public.jpeg) + CGImageDestinationRef destination = CGImageDestinationCreateWithURL((CFURLRef)url, UTI, 1, NULL); + if(!destination) { + Debug("***Could not create image destination ***"); + return false; + } + + //add the image contained in the image source to the destination, overidding the old metadata with our modified metadata + CGImageDestinationAddImageFromSource(destination, source, 0, (CFDictionaryRef)defaultRep.metadata); + + //tell the destination to write the image data and metadata into our data object. + //It will return false if something goes wrong + BOOL success = CGImageDestinationFinalize(destination); + if (!success) { + Debug("***Could not create data from image destination ***"); + } + CFRelease(destination); + CFRelease(source); + return success; } - CFRelease(destination); - CFRelease(source); - return success; } + (BOOL)writeDataToPath:(NSString*)filePath andAsset:(ALAsset*)asset