Skip to content

Commit

Permalink
Version 2.1.0.16264:
Browse files Browse the repository at this point in the history
- Migration to Swift 3 and make it ready for iOS 10
  • Loading branch information
Robin Oster committed Sep 20, 2016
1 parent d486188 commit e44d694
Show file tree
Hide file tree
Showing 12 changed files with 115 additions and 121 deletions.
39 changes: 12 additions & 27 deletions ROThumbnailGenerator.podspec
Original file line number Diff line number Diff line change
@@ -1,38 +1,23 @@
#
# Be sure to run `pod lib lint ROStorageBar.podspec' to ensure this is a
# Be sure to run `pod lib lint ROThumbnailGenerator' to ensure this is a
# valid spec and remove all comments before submitting the spec.
#
# Any lines starting with a # are optional, but encouraged
#
# To learn more about a Podspec see http://guides.cocoapods.org/syntax/podspec.html
#

Pod::Spec.new do |s|
s.name = "ROThumbnailGenerator"
s.version = "2.0.1"
s.summary = "Creates thumbnails of different file types very easily"
s.description = <<-DESC
It does create a thumbnail by the given file url. Creation of PDF, Image and Video thumbnails is per default supported.
With implementing the ROThumbnailGenerator it is very simple to add an additional ThumbnailGenerator for a missing file type.
DESC
s.homepage = "https://github.com/prine/ROThumbnailGenerator"
#s.screenshots = "https://raw.githubusercontent.com/prine/ROThumbnailGenerator/master/Screenshot.png"
s.license = 'MIT'
s.author = { "Robin Oster" => "[email protected]" }
s.source = { :git => "https://github.com/prine/ROThumbnailGenerator.git", :tag => s.version.to_s }
s.social_media_url = 'https://twitter.com/prinedev'

s.platform = :ios, '8.0'
s.requires_arc = true

s.source_files = 'Source/**/*'
s.resource_bundles = {
'ROBarcodeScanner' => ['Pod/Assets/*.png']
}

#s.resources = ["Source/*.Storyboard"]

# s.public_header_files = 'Pod/Classes/**/*.h'
# s.frameworks = 'UIKit', 'MapKit'
# s.dependency 'AFNetworking', '~> 2.3'
Pod::Spec.new do |spec|
spec.name = 'ROThumbnailGenerator'
spec.version = '2.1.0'
spec.license = { :type => 'MIT' }
spec.homepage = 'https://github.com/prine/ROThumbnailGenerator'
spec.authors = { 'Robin Oster' => '[email protected]' }
spec.summary = 'Creates thumbnails of different file types very easily'
spec.source = { :git => 'https://github.com/prine/ROThumbnailGenerator.git', :tag => "2.1.0" }
spec.source_files = 'Source/**/*'
spec.framework = 'SystemConfiguration'
spec.ios.deployment_target = '9.3'
end
33 changes: 22 additions & 11 deletions ROThumbnailGenerator.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -198,14 +198,18 @@
attributes = {
LastSwiftMigration = 0700;
LastSwiftUpdateCheck = 0700;
LastUpgradeCheck = 0700;
LastUpgradeCheck = 0800;
ORGANIZATIONNAME = "Prine Development";
TargetAttributes = {
CB3438741B7B3BAF00EEB5DB = {
CreatedOnToolsVersion = 6.4;
DevelopmentTeam = 39J9X3JBYC;
LastSwiftMigration = 0800;
};
CB3438891B7B3BAF00EEB5DB = {
CreatedOnToolsVersion = 6.4;
DevelopmentTeam = 39J9X3JBYC;
LastSwiftMigration = 0800;
TestTargetID = CB3438741B7B3BAF00EEB5DB;
};
};
Expand Down Expand Up @@ -320,8 +324,10 @@
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
Expand All @@ -344,7 +350,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 8.4;
IPHONEOS_DEPLOYMENT_TARGET = 9.3;
MTL_ENABLE_DEBUG_INFO = YES;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = iphoneos;
Expand All @@ -366,8 +372,10 @@
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
Expand All @@ -383,9 +391,10 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 8.4;
IPHONEOS_DEPLOYMENT_TARGET = 9.3;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
TARGETED_DEVICE_FAMILY = "1,2";
VALIDATE_PRODUCT = YES;
};
Expand All @@ -395,32 +404,34 @@
isa = XCBuildConfiguration;
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
DEVELOPMENT_TEAM = 39J9X3JBYC;
INFOPLIST_FILE = ROThumbnailGenerator/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "ch.prine.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
};
name = Debug;
};
CB3438961B7B3BAF00EEB5DB /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
DEVELOPMENT_TEAM = 39J9X3JBYC;
INFOPLIST_FILE = ROThumbnailGenerator/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "ch.prine.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
};
name = Release;
};
CB3438981B7B3BAF00EEB5DB /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
BUNDLE_LOADER = "$(TEST_HOST)";
FRAMEWORK_SEARCH_PATHS = (
"$(SDKROOT)/Developer/Library/Frameworks",
"$(inherited)",
);
DEVELOPMENT_TEAM = 39J9X3JBYC;
FRAMEWORK_SEARCH_PATHS = "$(inherited)";
GCC_PREPROCESSOR_DEFINITIONS = (
"DEBUG=1",
"$(inherited)",
Expand All @@ -429,6 +440,7 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "ch.prine.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/ROThumbnailGenerator.app/ROThumbnailGenerator";
};
name = Debug;
Expand All @@ -437,14 +449,13 @@
isa = XCBuildConfiguration;
buildSettings = {
BUNDLE_LOADER = "$(TEST_HOST)";
FRAMEWORK_SEARCH_PATHS = (
"$(SDKROOT)/Developer/Library/Frameworks",
"$(inherited)",
);
DEVELOPMENT_TEAM = 39J9X3JBYC;
FRAMEWORK_SEARCH_PATHS = "$(inherited)";
INFOPLIST_FILE = ROThumbnailGeneratorTests/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "ch.prine.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/ROThumbnailGenerator.app/ROThumbnailGenerator";
};
name = Release;
Expand Down
12 changes: 6 additions & 6 deletions ROThumbnailGenerator/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,30 +14,30 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?


func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
return true
}

func applicationWillResignActive(application: UIApplication) {
func applicationWillResignActive(_ application: UIApplication) {
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

func applicationDidEnterBackground(application: UIApplication) {
func applicationDidEnterBackground(_ application: UIApplication) {
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

func applicationWillEnterForeground(application: UIApplication) {
func applicationWillEnterForeground(_ application: UIApplication) {
// Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}

func applicationDidBecomeActive(application: UIApplication) {
func applicationDidBecomeActive(_ application: UIApplication) {
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

func applicationWillTerminate(application: UIApplication) {
func applicationWillTerminate(_ application: UIApplication) {
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

Expand Down
22 changes: 12 additions & 10 deletions ROThumbnailGenerator/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="7706" systemVersion="14E46" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="BYZ-38-t0r">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="11201" systemVersion="15G1004" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="BYZ-38-t0r">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="7703"/>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="11161"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
<!--View Controller-->
Expand All @@ -13,27 +15,27 @@
<viewControllerLayoutGuide type="bottom" id="wfy-db-euE"/>
</layoutGuides>
<view key="view" contentMode="scaleToFill" id="8bC-Xf-vdC">
<rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<imageView userInteractionEnabled="NO" contentMode="scaleAspectFit" horizontalHuggingPriority="251" verticalHuggingPriority="251" translatesAutoresizingMaskIntoConstraints="NO" id="bcL-fe-Q6I">
<rect key="frame" x="244" y="28" width="113" height="125"/>
<imageView userInteractionEnabled="NO" contentMode="scaleAspectFit" horizontalHuggingPriority="251" verticalHuggingPriority="251" misplaced="YES" translatesAutoresizingMaskIntoConstraints="NO" id="bcL-fe-Q6I">
<frame key="frameInset" minX="244" minY="28" width="113" height="125"/>
<constraints>
<constraint firstAttribute="width" constant="113" id="pNu-zV-KKd"/>
<constraint firstAttribute="height" constant="125" id="qLN-Wb-lOP"/>
</constraints>
</imageView>
<imageView userInteractionEnabled="NO" contentMode="scaleAspectFit" horizontalHuggingPriority="251" verticalHuggingPriority="251" translatesAutoresizingMaskIntoConstraints="NO" id="7P5-Nw-W8O">
<rect key="frame" x="244" y="332" width="113" height="125"/>
<imageView userInteractionEnabled="NO" contentMode="scaleAspectFit" horizontalHuggingPriority="251" verticalHuggingPriority="251" misplaced="YES" translatesAutoresizingMaskIntoConstraints="NO" id="7P5-Nw-W8O">
<frame key="frameInset" minX="244" minY="332" width="113" height="125"/>
</imageView>
<imageView userInteractionEnabled="NO" contentMode="scaleAspectFit" horizontalHuggingPriority="251" verticalHuggingPriority="251" translatesAutoresizingMaskIntoConstraints="NO" id="X8h-eJ-Kvl">
<rect key="frame" x="244" y="180" width="113" height="124"/>
<imageView userInteractionEnabled="NO" contentMode="scaleAspectFit" horizontalHuggingPriority="251" verticalHuggingPriority="251" misplaced="YES" translatesAutoresizingMaskIntoConstraints="NO" id="X8h-eJ-Kvl">
<frame key="frameInset" minX="244" minY="180" width="113" height="124"/>
<constraints>
<constraint firstAttribute="height" constant="124" id="8wO-jA-aus"/>
</constraints>
</imageView>
</subviews>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<constraints>
<constraint firstItem="X8h-eJ-Kvl" firstAttribute="leading" secondItem="7P5-Nw-W8O" secondAttribute="leading" id="CS4-77-KKs"/>
<constraint firstItem="bcL-fe-Q6I" firstAttribute="trailing" secondItem="X8h-eJ-Kvl" secondAttribute="trailing" id="CeJ-Ka-roV"/>
Expand Down
6 changes: 3 additions & 3 deletions ROThumbnailGenerator/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ class ViewController: UIViewController {

let thumbnail = ROThumbnail.sharedInstance

let imageURL = NSBundle.mainBundle().URLForResource("TestImage", withExtension: "png")
let imageURL = Bundle.main.url(forResource: "TestImage", withExtension: "png")
testImage.image = thumbnail.getThumbnail(imageURL!)

let documentURL = NSBundle.mainBundle().URLForResource("TestPdf", withExtension: "pdf")
let documentURL = Bundle.main.url(forResource: "TestPdf", withExtension: "pdf")
testPdf.image = thumbnail.getThumbnail(documentURL!)

let movieURL = NSBundle.mainBundle().URLForResource("TestMovie", withExtension: "mov")
let movieURL = Bundle.main.url(forResource: "TestMovie", withExtension: "mov")
testVideo.image = thumbnail.getThumbnail(movieURL!)
}

Expand Down
2 changes: 1 addition & 1 deletion ROThumbnailGeneratorTests/ROThumbnailGeneratorTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class ROThumbnailGeneratorTests: XCTestCase {

func testPerformanceExample() {
// This is an example of a performance test case.
self.measureBlock() {
self.measure() {
// Put the code you want to measure the time of here.
}
}
Expand Down
2 changes: 1 addition & 1 deletion Source/DefaultThumbnailGenerator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class DefaultThumbnailGenerator : ROThumbnailGenerator {

var supportedExtensions:Array<String> = []

func getThumbnail(url: NSURL) -> UIImage {
func getThumbnail(_ url: URL) -> UIImage {
return UIImage(named:"fallbackIcon")!
}
}
4 changes: 2 additions & 2 deletions Source/ImageThumbnailGenerator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class ImageThumbnailGenerator : ROThumbnailGenerator {

var supportedExtensions:Array<String> = ["png", "jpg", "jpeg"]

func getThumbnail(url:NSURL) -> UIImage {
return UIImage(data: NSData(contentsOfURL: url)!) ?? UIImage(named: "Piktogramm_IMAGE")!
func getThumbnail(_ url:URL) -> UIImage {
return UIImage(data: try! Data(contentsOf: url)) ?? UIImage(named: "Piktogramm_IMAGE")!
}
}
38 changes: 19 additions & 19 deletions Source/PDFThumbnailGenerator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,46 +12,46 @@ class PDFThumbnailGenerator : ROThumbnailGenerator {

var supportedExtensions:Array<String> = ["pdf"]

func getThumbnail(url:NSURL, pageNumber:Int, width:CGFloat) -> UIImage {
let pdf:CGPDFDocumentRef = CGPDFDocumentCreateWithURL(url as CFURLRef)!;
func getThumbnail(_ url:URL, pageNumber:Int, width:CGFloat) -> UIImage {
let pdf:CGPDFDocument = CGPDFDocument(url as CFURL)!;

let firstPage = CGPDFDocumentGetPage(pdf, pageNumber)
let firstPage = pdf.page(at: pageNumber)

var pageRect:CGRect = CGPDFPageGetBoxRect(firstPage, CGPDFBox.MediaBox);
var pageRect:CGRect = firstPage!.getBoxRect(CGPDFBox.mediaBox);
let pdfScale:CGFloat = width/pageRect.size.width;
pageRect.size = CGSizeMake(pageRect.size.width*pdfScale, pageRect.size.height*pdfScale);
pageRect.origin = CGPointZero;
pageRect.size = CGSize(width: pageRect.size.width*pdfScale, height: pageRect.size.height*pdfScale);
pageRect.origin = CGPoint.zero;

UIGraphicsBeginImageContext(pageRect.size);

let context:CGContextRef = UIGraphicsGetCurrentContext()!;
let context:CGContext = UIGraphicsGetCurrentContext()!;

// White BG
CGContextSetRGBFillColor(context, 1.0,1.0,1.0,1.0);
CGContextFillRect(context,pageRect);
context.setFillColor(red: 1.0,green: 1.0,blue: 1.0,alpha: 1.0);
context.fill(pageRect);

CGContextSaveGState(context);
context.saveGState();

// Next 3 lines makes the rotations so that the page look in the right direction
CGContextTranslateCTM(context, 0.0, pageRect.size.height);
CGContextScaleCTM(context, 1.0, -1.0);
CGContextConcatCTM(context, CGPDFPageGetDrawingTransform(firstPage, CGPDFBox.MediaBox, pageRect, 0, true));
context.translateBy(x: 0.0, y: pageRect.size.height);
context.scaleBy(x: 1.0, y: -1.0);
context.concatenate((firstPage?.getDrawingTransform(CGPDFBox.mediaBox, rect: pageRect, rotate: 0, preserveAspectRatio: true))!);

CGContextDrawPDFPage(context, firstPage);
CGContextRestoreGState(context);
context.drawPDFPage(firstPage!);
context.restoreGState();

let thm:UIImage = UIGraphicsGetImageFromCurrentImageContext();
let thm:UIImage = UIGraphicsGetImageFromCurrentImageContext()!;

UIGraphicsEndImageContext();
return thm;

}

func getThumbnail(url:NSURL, pageNumber:Int) -> UIImage {
func getThumbnail(_ url:URL, pageNumber:Int) -> UIImage {
return self.getThumbnail(url, pageNumber: pageNumber, width: 240.0)
}

func getThumbnail(url:NSURL) -> UIImage {
func getThumbnail(_ url:URL) -> UIImage {
return self.getThumbnail(url, pageNumber: 1, width: 240.0)
}
}
}
Loading

0 comments on commit e44d694

Please sign in to comment.