Skip to content

Commit

Permalink
fix crash when uploading
Browse files Browse the repository at this point in the history
  • Loading branch information
lilthree committed Jan 26, 2018
1 parent f84fbe4 commit 50fae8f
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 29 deletions.
6 changes: 1 addition & 5 deletions Pod/Classes/SeafUploadFile.m
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
50 changes: 26 additions & 24 deletions Pod/Classes/Utils.m
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 50fae8f

Please sign in to comment.