diff --git a/TWRDownloadManager.m b/TWRDownloadManager.m index 5c45a24..3e7621f 100644 --- a/TWRDownloadManager.m +++ b/TWRDownloadManager.m @@ -8,7 +8,9 @@ #import "TWRDownloadManager.h" #import "TWRDownloadObject.h" +#if TARGET_OS_IPHONE #import +#endif @interface TWRDownloadManager () @@ -39,11 +41,19 @@ - (instancetype)init { // Background session NSURLSessionConfiguration *backgroundConfiguration = nil; +#ifdef TARGET_OS_IPHONE +#ifndef TARGET_OS_WATCH if (floor(NSFoundationVersionNumber) > NSFoundationVersionNumber_iOS_7_1) { backgroundConfiguration = [NSURLSessionConfiguration backgroundSessionConfigurationWithIdentifier:[[NSBundle mainBundle] bundleIdentifier]]; } else { +#endif +#endif backgroundConfiguration = [NSURLSessionConfiguration backgroundSessionConfiguration:@"re.touchwa.downloadmanager"]; +#ifdef TARGET_OS_IPHONE +#ifndef TARGET_OS_WATCH } +#endif +#endif self.backgroundSession = [NSURLSession sessionWithConfiguration:backgroundConfiguration delegate:self delegateQueue:nil]; @@ -57,7 +67,6 @@ - (instancetype)init { - (void)downloadFileForURL:(NSString *)urlString withName:(NSString *)fileName inDirectoryNamed:(NSString *)directory - friendlyName:(NSString *)friendlyName progressBlock:(void(^)(CGFloat progress))progressBlock remainingTime:(void(^)(NSUInteger seconds))remainingTimeBlock completionBlock:(void(^)(BOOL completed))completionBlock @@ -66,11 +75,7 @@ - (void)downloadFileForURL:(NSString *)urlString if (!fileName) { fileName = [urlString lastPathComponent]; } - - if (!friendlyName) { - friendlyName = fileName; - } - + if (![self fileDownloadCompletedForUrl:urlString]) { NSLog(@"File is downloading!"); } else if (![self fileExistsWithName:fileName inDirectory:directory]) { @@ -84,7 +89,6 @@ - (void)downloadFileForURL:(NSString *)urlString TWRDownloadObject *downloadObject = [[TWRDownloadObject alloc] initWithDownloadTask:downloadTask progressBlock:progressBlock remainingTime:remainingTimeBlock completionBlock:completionBlock]; downloadObject.startDate = [NSDate date]; downloadObject.fileName = fileName; - downloadObject.friendlyName = friendlyName; downloadObject.directoryName = directory; [self.downloads addEntriesFromDictionary:@{urlString:downloadObject}]; [downloadTask resume]; @@ -93,16 +97,6 @@ - (void)downloadFileForURL:(NSString *)urlString } } -- (void)downloadFileForURL:(NSString *)urlString - withName:(NSString *)fileName - inDirectoryNamed:(NSString *)directory - progressBlock:(void(^)(CGFloat progress))progressBlock - remainingTime:(void(^)(NSUInteger seconds))remainingTimeBlock - completionBlock:(void(^)(BOOL completed))completionBlock - enableBackgroundMode:(BOOL)backgroundMode { - -} - - (void)downloadFileForURL:(NSString *)url inDirectoryNamed:(NSString *)directory progressBlock:(void(^)(CGFloat progress))progressBlock @@ -139,11 +133,11 @@ - (void)downloadFileForURL:(NSString *)urlString completionBlock:(void(^)(BOOL completed))completionBlock enableBackgroundMode:(BOOL)backgroundMode { [self downloadFileForURL:urlString - withName:fileName - inDirectoryNamed:directory - progressBlock:progressBlock - remainingTime:nil - completionBlock:completionBlock + withName:fileName + inDirectoryNamed:directory + progressBlock:progressBlock + remainingTime:nil + completionBlock:completionBlock enableBackgroundMode:backgroundMode]; } @@ -280,10 +274,14 @@ - (void)URLSession:(NSURLSession *)session downloadTask:(NSURLSessionDownloadTas [self.downloads removeObjectForKey:fileIdentifier]; dispatch_async(dispatch_get_main_queue(), ^{ +#ifdef TARGET_OS_IPHONE +#ifndef TARGET_OS_WATCH // Show a local notification when download is over. UILocalNotification *localNotification = [[UILocalNotification alloc] init]; localNotification.alertBody = [NSString stringWithFormat:@"%@ has been downloaded", download.friendlyName]; [[UIApplication sharedApplication] presentLocalNotificationNow:localNotification]; +#endif +#endif }); } @@ -486,10 +484,14 @@ - (void)URLSessionDidFinishEventsForBackgroundURLSession:(NSURLSession *)session // Call the completion handler to tell the system that there are no other background transfers. completionHandler(); +#ifdef TARGET_OS_IPHONE +#ifndef TARGET_OS_WATCH // Show a local notification when all downloads are over. UILocalNotification *localNotification = [[UILocalNotification alloc] init]; localNotification.alertBody = @"All files have been downloaded!"; [[UIApplication sharedApplication] presentLocalNotificationNow:localNotification]; +#endif +#endif }]; // Make nil the backgroundTransferCompletionHandler. diff --git a/TWRDownloadManager.podspec b/TWRDownloadManager.podspec index b8c0929..70d2227 100644 --- a/TWRDownloadManager.podspec +++ b/TWRDownloadManager.podspec @@ -21,7 +21,11 @@ Pod::Spec.new do |s| :tag => "1.2.0" } - s.platform = :ios, '7.0' + s.ios.deployment_target = '7.0' + s.osx.deployment_target = '10.8' + s.watchos.deployment_target = '3.0' + s.tvos.deployment_target = '10.0' + s.source_files = '*.{h,m}' s.requires_arc = true