From b622cb07150ee75b61d71868a33751751da79f13 Mon Sep 17 00:00:00 2001 From: Perry Poon Date: Wed, 1 Jun 2016 23:32:49 +0800 Subject: [PATCH] add error checker --- RNZipArchive.m | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/RNZipArchive.m b/RNZipArchive.m index 99c22a1..2d67ffc 100644 --- a/RNZipArchive.m +++ b/RNZipArchive.m @@ -20,22 +20,26 @@ @implementation RNZipArchive RCT_EXPORT_METHOD(unzip:(NSString *)zipPath destinationPath:(NSString *)destinationPath callback:(RCTResponseSenderBlock)callback) { [self zipArchiveProgressEvent:0 total:1]; // force 0% - - [SSZipArchive unzipFileAtPath:zipPath toDestination:destinationPath delegate:self]; - + + BOOL success = [SSZipArchive unzipFileAtPath:zipPath toDestination:destinationPath delegate:self]; + [self zipArchiveProgressEvent:1 total:1]; // force 100% - - callback(@[[NSNull null]]); + + if (success) { + callback(@[[NSNull null]]); + } else { + callback(@[@"unzip error"]); + } } - (void)zipArchiveProgressEvent:(NSInteger)loaded total:(NSInteger)total { if (total == 0) { return; } - + // TODO: should send the filename, just like the Android version [self.bridge.eventDispatcher sendAppEventWithName:@"zipArchiveProgressEvent" body:@{ - @"progress": @( (float)loaded / (float)total ) + @"progress": @( (float)loaded / (float)total ) }]; }