123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106 |
- #import "KMResourceDownload.h"
- #import <ZipArchive/ZipArchive.h>
- #if __has_include(<DateTools/DateTools.h>)
- #import <DateTools/DateTools.h>
- #define HAS_DOCUMENTAI_FRAMEWORK 1
- #else
- #define HAS_DOCUMENTAI_FRAMEWORK 0
- #endif
- @implementation KMResourceDownload
- - (void)downloadFramework {
-
- NSString *urlString = @"http://test-pdf-pro.kdan.cn:3021/downloads/DateTools.framework.zip";
- NSURL *url = [NSURL URLWithString:urlString];
-
- NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration defaultSessionConfiguration];
- NSURLSession *session = [NSURLSession sessionWithConfiguration:configuration];
-
- NSURLSessionDownloadTask *downloadTask = [session downloadTaskWithURL:url completionHandler:^(NSURL * _Nullable location, NSURLResponse * _Nullable response, NSError * _Nullable error) {
- if (error) {
- NSLog(@"Failed to download framework: %@", error);
- return;
- }
-
-
- NSFileManager *fileManager = [NSFileManager defaultManager];
- NSString *frameworksDirectory = [[NSBundle mainBundle] privateFrameworksPath];
- NSString *destinationPath = [frameworksDirectory stringByAppendingPathComponent:@"DateTools.framework.zip"];
-
- NSError *moveError = nil;
- [fileManager moveItemAtURL:location toURL:[NSURL fileURLWithPath:destinationPath] error:&moveError];
- if (moveError) {
- NSLog(@"Failed to move framework: %@", moveError);
- return;
- }
-
- NSLog(@"Framework downloaded and installed successfully!");
-
-
- [self unzipFrameworkAtURL:[NSURL fileURLWithPath:destinationPath] toDestination:frameworksDirectory];
-
-
- [self loadFramework:[frameworksDirectory stringByAppendingPathComponent:@"DateTools.framework"]];
- }];
-
- [downloadTask resume];
- }
- - (void)unzipFrameworkAtURL:(NSURL *)zipURL toDestination:(NSString *)destinationPath {
-
- NSFileManager *fileManager = [NSFileManager defaultManager];
-
- BOOL success = NO;
- if ([zipURL.path.pathExtension isEqualToString:@"zip"]) {
-
- success = [SSZipArchive unzipFileAtPath:zipURL.path
- toDestination:destinationPath];
- } else {
-
-
- }
-
- if (success) {
- NSLog(@"File unzipped successfully!");
- [fileManager removeItemAtPath:zipURL.path error:nil];
- } else {
- NSLog(@"Failed to unzip file.");
- }
- }
- - (void)loadFramework:(NSString *)destinationPath {
- NSError *error = nil;
- NSBundle *frameworkBundle = [NSBundle bundleWithPath:destinationPath];
- if (![frameworkBundle loadAndReturnError:&error]) {
- NSLog(@"Error loading framework: %@", error);
- return;
- }
-
-
- #if HAS_DOCUMENTAI_FRAMEWORK
- NSDate *selectedDate = [NSDate dateWithTimeIntervalSinceNow:-24*60*60*6+100];
- NSString *week = [NSDate weekTimeAgoSinceDate:selectedDate];
- NSLog(@"week == %@", week);
- #else
-
- NSLog(@"没有库");
- #endif
- }
- @end
|