سؤال

Due to cryptography export regulations, it is possible to use this library? or which one could I use to compress/decompress files?

هل كانت مفيدة؟

المحلول

I don't know if SSZipArchive is allowed to use in distributed apps, but the library I am using is Objective-Zip.

It can be easily integrated into any project.

Sample code for zipping:

// create a zip file for writing
ZipFile *zipFile= [[ZipFile alloc] initWithFileName:pathOfTheFileToBeZipped mode:ZipFileModeCreate];

// Add a file, write to its stream and close it
ZipWriteStream *stream1= [zipFile writeFileInZipWithName:@"abc.txt" fileDate:[NSDate dateWithTimeIntervalSinceNow:-86400.0] compressionLevel:ZipCompressionLevelBest];
NSString *text= @"abc";
[stream1 writeData:[text dataUsingEncoding:NSUTF8StringEncoding]];
[stream1 finishedWriting];

// Add another file, write to its stream and close it
ZipWriteStream *stream2= [zipFile writeFileInZipWithName:@"x/y/z/xyz.txt" compressionLevel:ZipCompressionLevelNone];
NSString *text2= @"XYZ";
[stream2 writeData:[text2 dataUsingEncoding:NSUTF8StringEncoding]];
[stream2 finishedWriting];

// Close the zip file
[zipFile close];

Sample code for unzipping:

// open the zip file for reading
ZipFile *unzipFile = [[ZipFile alloc] initWithFileName:pathOfTheFileToBeUnzipped mode:ZipFileModeUnzip];

// retrieve the info of the files inside
NSArray *infos= [unzipFile listFileInZipInfos];

// iterate over files
for (FileInZipInfo *info in infos) {        
    // locate the file in the zip
    [unzipFile locateFileInZip:info.name];

    // expand the file in memory
    ZipReadStream *read= [unzipFile readCurrentFileInZip];
    NSData *data = [read readDataOfLength:info.length];
    [read finishedReading];

    // construct the folder/file path structure
    NSString *unzipPathFilename = [unzipPath stringByAppendingPathComponent:info.name];
    NSString *unzipPathFoldername = [[unzipPathFilename stringByDeletingLastPathComponent] copy];
    NSError *errorw;

    // write the unzipped files, with some consistency checks
    NSRange range = [unzipPathFoldername rangeOfString:@"__MACOSX"];

    if (range.location == NSNotFound) {
        if ([fileManager createDirectoryAtPath:unzipPathFoldername withIntermediateDirectories:YES attributes:nil error:&errorw]) {
            if (![[unzipPathFilename pathExtension] isEqualToString:@""] && ![[[unzipPathFilename lastPathComponent] substringToIndex:1] isEqualToString:@"." ]) {
                [data writeToFile:unzipPathFilename atomically:NO];
            }
        }
        else {
            NSLog(@"Directory Fail: %@", errorw);
        }
    }
}

// close the zip file
[unzipFile close];

نصائح أخرى

Actually you are allowed to have encryption in iOS application. You just have to submit application to NSA who you are and what kind of encryption do have in app. Respond with your reg number usually comes in 30 minutes. It is automatic or semi-automatic. They just collect information about developers.

It is simpler then register as iOS developer.

My opinion:-

If you do not use encryption in ZIP library then you should submit any application. Linker will remove that code after optimization. That code is not used. But if you use encryption even that comes with iOS then you should apply. e.g. UIWebView if it opens https:// URLs (e.g. Facebook) but if you use UIWebView to open non secure pages then you should not apply.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top