Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix using image assets and Swift with CocoaPods #40

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Classes/Document/CGPDFDocument.m
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ CGPDFDocumentRef CGPDFDocumentCreate(NSURL *url, NSString *password)
}
//Failed to unlock the document. Cleanup.
if (CGPDFDocumentIsUnlocked(docRef) == FALSE) {
CGPDFDocumentRelease(docRef), docRef = NULL;
CGPDFDocumentRelease(docRef);
docRef = NULL;
}
}
} else {
Expand Down
10 changes: 6 additions & 4 deletions Classes/View/PDFKBasicPDFViewer.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,19 @@ typedef void (^PDFKBasicPDFViewerPageChangeBlock)(NSUInteger page);
*/
- (void)displayPage:(NSUInteger)page;

+ (NSBundle*)getResourcesBundle;

/**@name Properties*/

@property (nonatomic, strong) PDFKBasicPDFViewerPageChangeBlock pageChangeBlock;

@property (nonatomic, strong, readonly) PDFKDocument *document;

/**@name Features*/
/**
Wether or not to allow showing the thumbs button.
*/
@property (nonatomic, assign) BOOL enableThumbs;
/**
Wether or not to allow bookmarking of pages.
*/
Expand Down Expand Up @@ -92,10 +98,6 @@ typedef void (^PDFKBasicPDFViewerPageChangeBlock)(NSUInteger page);
The slider at the bottom of the screen to show the thumbnails.
*/
@property (nonatomic, retain, readonly) UIToolbar *thumbnailSlider;
/**
The popover controller to share the document on the iPad.
*/
@property (nonatomic, strong, readonly) UIPopoverController *activityPopoverController;
/**
The share button.
*/
Expand Down
52 changes: 32 additions & 20 deletions Classes/View/PDFKBasicPDFViewer.m
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ @interface PDFKBasicPDFViewer () <UIToolbarDelegate, UIDocumentInteractionContro

@property (nonatomic, retain, readwrite) UIToolbar *navigationToolbar;
@property (nonatomic, retain, readwrite) UIToolbar *thumbnailSlider;
@property (nonatomic, strong, readwrite) UIPopoverController *activityPopoverController;
@property (nonatomic, strong, readwrite) UIBarButtonItem *shareItem;
@property (nonatomic, strong, readwrite) UIBarButtonItem *bookmarkItem;
@property (nonatomic, strong, readwrite) PDFKPageScrubber *pageScrubber;
Expand Down Expand Up @@ -255,12 +254,15 @@ - (void)resetNavigationToolbar
[buttonsArray addObject:space];
}

//Add list
UIBarButtonItem *listItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"Thumbs"] landscapeImagePhone:[UIImage imageNamed:@"Thumbs"] style:UIBarButtonItemStylePlain target:self action:@selector(list)];
[buttonsArray addObject:listItem];

//Flexible space
[buttonsArray addObject:[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil]];
if(_enableThumbs == YES)
{
//Add list
UIBarButtonItem *listItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"Thumbs" inBundle:[PDFKBasicPDFViewer getResourcesBundle] compatibleWithTraitCollection:nil] landscapeImagePhone:[UIImage imageNamed:@"Thumbs" inBundle:[PDFKBasicPDFViewer getResourcesBundle] compatibleWithTraitCollection:nil] style:UIBarButtonItemStylePlain target:self action:@selector(list)];
[buttonsArray addObject:listItem];

//Flexible space
[buttonsArray addObject:[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil]];
}

//Bookmark Button
if (_enableBookmarks) {
Expand All @@ -271,9 +273,9 @@ - (void)resetNavigationToolbar
//Add bookmarks
//Change image based on wether or not the page is bookmarked
if (![_document.bookmarks containsIndex:_document.currentPage]) {
_bookmarkItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"Bookmark"] style:UIBarButtonItemStylePlain target:self action:@selector(bookmark)];
_bookmarkItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"Bookmark" inBundle:[PDFKBasicPDFViewer getResourcesBundle] compatibleWithTraitCollection:nil] style:UIBarButtonItemStylePlain target:self action:@selector(bookmark)];
} else {
_bookmarkItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"Bookmarked"] style:UIBarButtonItemStylePlain target:self action:@selector(bookmark)];
_bookmarkItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"Bookmarked" inBundle:[PDFKBasicPDFViewer getResourcesBundle] compatibleWithTraitCollection:nil] style:UIBarButtonItemStylePlain target:self action:@selector(bookmark)];
}

[buttonsArray addObject:_bookmarkItem];
Expand Down Expand Up @@ -314,7 +316,12 @@ - (void)resetNavigationToolbar
[buttonsArray addObject:[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil]];

//Bookmarks
UISegmentedControl *control = [[UISegmentedControl alloc] initWithItems:@[[UIImage imageNamed:@"Thumbs"], [UIImage imageNamed:@"Bookmark"]]];


UIImage *thumbsImage = [UIImage imageNamed:@"Thumbs" inBundle:[PDFKBasicPDFViewer getResourcesBundle] compatibleWithTraitCollection:nil];
UIImage *bookmarkImage = [UIImage imageNamed:@"Bookmark" inBundle:[PDFKBasicPDFViewer getResourcesBundle] compatibleWithTraitCollection:nil];

UISegmentedControl *control = [[UISegmentedControl alloc] initWithItems:@[thumbsImage, bookmarkImage]];
[control setSelectedSegmentIndex:(!_showingBookmarks ? 0 : 1)];
[control sizeToFit];
[control addTarget:self action:@selector(toggleShowBookmarks:) forControlEvents:UIControlEventValueChanged];
Expand Down Expand Up @@ -357,21 +364,15 @@ - (void)send
}

if([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPhone){
// Store reference to superview (UIActionSheet) to allow dismissal
if (openInAppActivity) {
openInAppActivity.superViewController = activityViewController;
}
// Show UIActivityViewController
[self presentViewController:activityViewController animated:YES completion:NULL];
} else {
// Create pop up
self.activityPopoverController = [[UIPopoverController alloc] initWithContentViewController:activityViewController];
// Store reference to superview (UIPopoverController) to allow dismissal
if (openInAppActivity) {
openInAppActivity.superViewController = self.activityPopoverController;
}
activityViewController.modalPresentationStyle = UIModalPresentationPopover;
// Show UIActivityViewController in popup
[self.activityPopoverController presentPopoverFromBarButtonItem:_shareItem permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
activityViewController.popoverPresentationController.sourceView = (UIView*)_shareItem;

[self presentViewController:activityViewController animated:YES completion:nil];
}
}

Expand Down Expand Up @@ -613,5 +614,16 @@ - (void)toggleSinglePageView
}
}

#pragma mark - Static methods

+ (NSBundle*)getResourcesBundle
{
NSBundle *frameworkBundle = [NSBundle bundleForClass:[self class]];
NSURL *frameworkResourcesBundleUrl = [frameworkBundle URLForResource:@"M13PDFKitResources" withExtension:@"bundle"];
NSBundle *frameworkResourcesBundle = [NSBundle bundleWithURL:frameworkResourcesBundleUrl];

return frameworkResourcesBundle;
}

@end

3 changes: 2 additions & 1 deletion Classes/View/PDFKBasicPDFViewerThumbsCollectionView.m
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#import "PDFKThumbView.h"
#import "PDFKThumbRequest.h"
#import "PDFKThumbCache.h"
#import "PDFKBasicPDFViewer.h"
#import <QuartzCore/QuartzCore.h>

@interface PDFKBasicPDFViewerThumbsCollectionView () <UICollectionViewDataSource, UICollectionViewDelegate, UICollectionViewDelegateFlowLayout>
Expand Down Expand Up @@ -228,7 +229,7 @@ - (void)showBookmark:(BOOL)show
if (!show) {
_bookmarkView.image = nil;
} else {
_bookmarkView.image = [[UIImage imageNamed:@"Bookmarked"] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
_bookmarkView.image = [[UIImage imageNamed:@"Bookmarked" inBundle:[PDFKBasicPDFViewer getResourcesBundle] compatibleWithTraitCollection:nil] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
}
}

Expand Down
9 changes: 6 additions & 3 deletions Classes/View/PDFKPageContent.m
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,8 @@ - (id)annotationLinkTarget:(CGPDFDictionaryRef)annotationDictionary
//Destination URI string
const char *uri = (const char *)CGPDFStringGetBytePtr(uriString);
NSString *target = [NSString stringWithCString:uri encoding:NSUTF8StringEncoding];
linkTarget = [NSURL URLWithString:[target stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];

linkTarget = [NSURL URLWithString:[target stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLHostAllowedCharacterSet]]];
//Debug check
#if DEBUG
if (linkTarget == nil) NSLog(@"%s Bad URI '%@'", __FUNCTION__, target);
Expand Down Expand Up @@ -543,8 +544,10 @@ - (void)removeFromSuperview

- (void)dealloc
{
CGPDFPageRelease(_PDFPageRef), _PDFPageRef = NULL;
CGPDFDocumentRelease(_PDFDocRef), _PDFDocRef = NULL;
CGPDFPageRelease(_PDFPageRef);
_PDFPageRef = NULL;
CGPDFDocumentRelease(_PDFDocRef);
_PDFDocRef = NULL;
}

#pragma mark CATiledLayer delegate methods
Expand Down
1 change: 0 additions & 1 deletion Classes/View/PDFKPageContentView.m
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,6 @@ - (void)setBounds:(CGRect)bounds
//On the third page, the bounds size get set to 0 by autolayout for all pages that are created next.
//No idea why...
//EXPLAIN!!! EXPLAIN!!! EXPLAIN!!! Explain yourself doctor...
#warning EXPLAIN!!!
if (bounds.size.width != 0 && bounds.size.height != 0) {
[super setBounds: bounds];
}
Expand Down
19 changes: 14 additions & 5 deletions M13PDFKit.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@
CAF2562A1A1CFF0000F0EA4F /* Project object */ = {
isa = PBXProject;
attributes = {
LastUpgradeCheck = 0610;
LastUpgradeCheck = 0810;
ORGANIZATIONNAME = BrandonMcQuilkin;
TargetAttributes = {
CAF256311A1CFF0000F0EA4F = {
Expand Down Expand Up @@ -517,15 +517,19 @@
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";
COPY_PHASE_STRIP = NO;
ENABLE_STRICT_OBJC_MSGSEND = YES;
ENABLE_TESTABILITY = YES;
GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_DYNAMIC_NO_PIC = NO;
GCC_NO_COMMON_BLOCKS = YES;
GCC_OPTIMIZATION_LEVEL = 0;
GCC_PREPROCESSOR_DEFINITIONS = (
"DEBUG=1",
Expand All @@ -538,7 +542,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 8.1;
IPHONEOS_DEPLOYMENT_TARGET = 9.3;
MTL_ENABLE_DEBUG_INFO = YES;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = iphoneos;
Expand All @@ -559,22 +563,25 @@
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";
COPY_PHASE_STRIP = YES;
ENABLE_NS_ASSERTIONS = NO;
ENABLE_STRICT_OBJC_MSGSEND = YES;
GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_NO_COMMON_BLOCKS = YES;
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
GCC_WARN_UNDECLARED_SELECTOR = YES;
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 8.1;
IPHONEOS_DEPLOYMENT_TARGET = 9.3;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
TARGETED_DEVICE_FAMILY = "1,2";
Expand All @@ -590,8 +597,8 @@
ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = LaunchImage;
CODE_SIGN_RESOURCE_RULES_PATH = "$(SDKROOT)/ResourceRules.plist";
INFOPLIST_FILE = M13PDFKit/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "com.BrandonMcQuilkin.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
};
name = Debug;
Expand All @@ -604,8 +611,8 @@
ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = LaunchImage;
CODE_SIGN_RESOURCE_RULES_PATH = "$(SDKROOT)/ResourceRules.plist";
INFOPLIST_FILE = M13PDFKit/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "com.BrandonMcQuilkin.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
};
name = Release;
Expand All @@ -624,6 +631,7 @@
);
INFOPLIST_FILE = M13PDFKitTests/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "com.BrandonMcQuilkin.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/M13PDFKit.app/M13PDFKit";
};
Expand All @@ -639,6 +647,7 @@
);
INFOPLIST_FILE = M13PDFKitTests/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "com.BrandonMcQuilkin.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/M13PDFKit.app/M13PDFKit";
};
Expand Down
13 changes: 8 additions & 5 deletions M13PDFKit.xcodeproj/xcshareddata/xcschemes/M13PDFKit.xcscheme
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0610"
LastUpgradeVersion = "0810"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down Expand Up @@ -37,10 +37,10 @@
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES"
buildConfiguration = "Debug">
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
<TestableReference
skipped = "NO">
Expand All @@ -62,15 +62,18 @@
ReferencedContainer = "container:M13PDFKit.xcodeproj">
</BuildableReference>
</MacroExpansion>
<AdditionalOptions>
</AdditionalOptions>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
buildConfiguration = "Debug"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
Expand All @@ -86,10 +89,10 @@
</AdditionalOptions>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
buildConfiguration = "Release"
debugDocumentVersioning = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
Expand Down
25 changes: 25 additions & 0 deletions M13PDFKit/Images.xcassets/AppIcon.appiconset/Contents.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
{
"images" : [
{
"idiom" : "iphone",
"size" : "20x20",
"scale" : "2x"
},
{
"idiom" : "iphone",
"size" : "20x20",
"scale" : "3x"
},
{
"size" : "29x29",
"idiom" : "iphone",
Expand Down Expand Up @@ -36,6 +46,16 @@
"filename" : "[email protected]",
"scale" : "3x"
},
{
"idiom" : "ipad",
"size" : "20x20",
"scale" : "1x"
},
{
"idiom" : "ipad",
"size" : "20x20",
"scale" : "2x"
},
{
"size" : "29x29",
"idiom" : "ipad",
Expand Down Expand Up @@ -71,6 +91,11 @@
"idiom" : "ipad",
"filename" : "[email protected]",
"scale" : "2x"
},
{
"idiom" : "ipad",
"size" : "83.5x83.5",
"scale" : "2x"
}
],
"info" : {
Expand Down
2 changes: 1 addition & 1 deletion M13PDFKit/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>com.BrandonMcQuilkin.$(PRODUCT_NAME:rfc1034identifier)</string>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
Expand Down
Loading