Skip to content

Commit 229e326

Browse files
authored
Merge pull request #1629 from NYPL-Simplified/IOS-631/publicationBaseURL-crash
IOS-631 Fix crash when Publication::baseURL is nil
2 parents 2ab69ef + 0be29ae commit 229e326

File tree

14 files changed

+67
-46
lines changed

14 files changed

+67
-46
lines changed

Simplified.xcodeproj/project.pbxproj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5014,7 +5014,7 @@
50145014
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES_ERROR;
50155015
CODE_SIGN_ENTITLEMENTS = Simplified/SimplyE.entitlements;
50165016
CODE_SIGN_IDENTITY = "iPhone Developer";
5017-
CURRENT_PROJECT_VERSION = 4;
5017+
CURRENT_PROJECT_VERSION = 0;
50185018
DEVELOPMENT_TEAM = 7262U6ST2R;
50195019
"EXCLUDED_ARCHS[sdk=iphonesimulator*]" = arm64;
50205020
GCC_PRECOMPILE_PREFIX_HEADER = YES;
@@ -5034,7 +5034,7 @@
50345034
"$(inherited)",
50355035
"@executable_path/Frameworks",
50365036
);
5037-
MARKETING_VERSION = 3.9.5;
5037+
MARKETING_VERSION = 3.9.6;
50385038
OTHER_LDFLAGS = (
50395039
"$(inherited)",
50405040
"-ld_classic",
@@ -5068,7 +5068,7 @@
50685068
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES_ERROR;
50695069
CODE_SIGN_ENTITLEMENTS = Simplified/SimplyE.entitlements;
50705070
CODE_SIGN_IDENTITY = "iPhone Distribution";
5071-
CURRENT_PROJECT_VERSION = 4;
5071+
CURRENT_PROJECT_VERSION = 0;
50725072
DEVELOPMENT_TEAM = 7262U6ST2R;
50735073
GCC_PRECOMPILE_PREFIX_HEADER = YES;
50745074
GCC_PREFIX_HEADER = "Simplified/AppInfrastructure/Simplified-Prefix.pch";
@@ -5087,7 +5087,7 @@
50875087
"$(inherited)",
50885088
"@executable_path/Frameworks",
50895089
);
5090-
MARKETING_VERSION = 3.9.5;
5090+
MARKETING_VERSION = 3.9.6;
50915091
OTHER_LDFLAGS = (
50925092
"$(inherited)",
50935093
"-ld_classic",

Simplified/Book/UI/NYPLBookButtonsView.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88

99
- (void)didSelectReturnForBook:(NYPLBook *)book;
1010
- (void)didSelectDownloadForBook:(NYPLBook *)book;
11-
- (void)didSelectReadForBook:(NYPLBook *)book successCompletion:(void(^)(void))completion;
11+
- (void)didSelectReadForBook:(NYPLBook *)book
12+
completion:(void(^)(BOOL success))completion;
1213

1314
@end
1415

Simplified/Book/UI/NYPLBookButtonsView.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,7 @@ - (void)didSelectRead
434434
self.activityIndicator.center = self.readButton.center;
435435
[self updateProcessingState:YES];
436436
[self.delegate didSelectReadForBook:self.book
437-
successCompletion:^{
437+
completion:^(__unused BOOL success) {
438438
[self updateProcessingState];
439439
}];
440440
}

Simplified/Book/UI/NYPLBookCellDelegate.m

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@ - (void)didSelectDownloadForBook:(NYPLBook *)book
6363
[[NYPLMyBooksDownloadCenter sharedDownloadCenter] startDownloadForBook:book];
6464
}
6565

66-
- (void)didSelectReadForBook:(NYPLBook *)book successCompletion:(void(^)(void))successCompletion
66+
- (void)didSelectReadForBook:(NYPLBook *)book
67+
completion:(void(^)(BOOL success))completion
6768
{
6869
#if FEATURE_DRM_CONNECTOR
6970
// Try to prevent blank books bug
@@ -81,37 +82,40 @@ - (void)didSelectReadForBook:(NYPLBook *)book successCompletion:(void(^)(void))s
8182
completion:^(BOOL isSignedIn) {
8283
if (isSignedIn) {
8384
dispatch_async(dispatch_get_main_queue(), ^{
84-
[self openBook:book successCompletion:successCompletion];
85+
[self openBook:book completion:completion];
8586
// with ARC, retain the reauthenticator until we're done, then release it
8687
reauthenticator = nil;
8788
});
8889
}
8990
}];
9091
} else {
91-
[self openBook:book successCompletion:successCompletion];
92+
[self openBook:book completion:completion];
9293
}
9394
#else
94-
[self openBook:book successCompletion:successCompletion];
95+
[self openBook:book completion:completion];
9596
#endif//FEATURE_DRM_CONNECTOR
9697
}
9798

98-
- (void)openBook:(NYPLBook *)book successCompletion:(void(^)(void))successCompletion
99+
- (void)openBook:(NYPLBook *)book completion:(void(^)(BOOL success))completion
99100
{
100101
[NYPLCirculationAnalytics postEvent:@"open_book" withBook:book];
101102

102103
switch (book.defaultBookContentType) {
103104
case NYPLBookContentTypeEPUB:
104-
[[[NYPLEPUBOpener alloc] init] open:book successCompletion:successCompletion];
105+
[[[NYPLEPUBOpener alloc] init] open:book completion:completion];
105106
break;
106107
case NYPLBookContentTypePDF:
107108
[self openPDF:book];
108109
break;
109110
#if FEATURE_AUDIOBOOKS
110-
case NYPLBookContentTypeAudiobook:
111-
[self openAudiobook:book successCompletion:successCompletion];
111+
case NYPLBookContentTypeAudiobook: {
112+
[self openAudiobook:book successCompletion:^{
113+
completion(YES);
114+
}];
112115
break;
116+
}
113117
#endif
114-
default:
118+
case NYPLBookContentTypeUnsupported:
115119
[self presentUnsupportedItemError];
116120
break;
117121
}
@@ -181,7 +185,7 @@ - (void)didSelectCancelForBookDownloadingCell:(NYPLBookDownloadingCell *const)ce
181185

182186
- (void)didSelectListenForBookDownloadingCell:(NYPLBookDownloadingCell *)cell
183187
{
184-
[self didSelectReadForBook:cell.book successCompletion:nil];
188+
[self didSelectReadForBook:cell.book completion:nil];
185189
}
186190

187191
@end

Simplified/Book/UI/NYPLBookDetailViewController.m

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -139,15 +139,17 @@ - (void)didSelectDownloadForBook:(NYPLBook *)book
139139
}
140140

141141
- (void)didSelectReadForBook:(NYPLBook *)book
142-
successCompletion:(__unused void(^)(void))successCompletion
142+
completion:(void(^)(BOOL success))completion
143143
{
144144
[[NYPLBookCellDelegate sharedDelegate] didSelectReadForBook:book
145-
successCompletion:^{
145+
completion:^(BOOL success) {
146146
// dismiss ourselves if we were presented, since we want to show the ereader
147147
if (self.modalPresentationStyle == UIModalPresentationFormSheet) {
148-
[self dismissViewControllerAnimated:true completion:successCompletion];
148+
[self dismissViewControllerAnimated:true completion:^{
149+
completion(success);
150+
}];
149151
} else {
150-
successCompletion();
152+
completion(success);
151153
}
152154
}];
153155
}

Simplified/Book/UI/NYPLEPUBOpener.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import Foundation
1010

1111
class NYPLEPUBOpener: NSObject {
1212
@objc
13-
func open(_ book: NYPLBook, successCompletion: @escaping () -> Void) {
13+
func open(_ book: NYPLBook, completion: @escaping (_ success: Bool) -> Void) {
1414

1515
let url = NYPLMyBooksDownloadCenter.shared()?
1616
.fileURL(forBookIndentifier: book.identifier)
@@ -21,8 +21,8 @@ class NYPLEPUBOpener: NSObject {
2121
rootTabController?.presentBook(book,
2222
fromFileURL: url,
2323
syncPermission: syncPermission,
24-
successCompletion: successCompletion)
25-
24+
completion: completion)
25+
2626
rootTabController?.annotationsSynchronizer?
2727
.checkServerSyncStatus(settings: NYPLSettings.shared,
2828
syncPermissionGranted: syncPermission) { enableSync, error in

Simplified/Reader2/ReaderPresentation/NYPLRootTabBarController+R2.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import Foundation
1212
func presentBook(_ book: NYPLBook,
1313
fromFileURL fileURL: URL?,
1414
syncPermission: Bool,
15-
successCompletion: (() -> Void)?) {
15+
completion: ((_ success: Bool) -> Void)?) {
1616
guard let libraryService = r2Owner?.libraryService, let readerModule = r2Owner?.readerModule else {
1717
return
1818
}
@@ -30,7 +30,7 @@ import Foundation
3030
syncPermission: syncPermission,
3131
deviceID: drmDeviceID,
3232
in: navVC,
33-
successCompletion: successCompletion)
33+
completion: completion)
3434
case .cancelled:
3535
// .cancelled is returned when publication has restricted access to its resources and can't be rendered
3636
NYPLErrorLogger.logError(nil, summary: "Error accessing book resources", metadata: [

Simplified/Reader2/ReaderPresentation/ReaderError.swift

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,16 @@ import Foundation
1414

1515
enum ReaderError: LocalizedError {
1616
case formatNotSupported
17-
case epubNotValid
18-
17+
case epubNotValid(String)
18+
1919
var errorDescription: String? {
2020
switch self {
2121
case .formatNotSupported:
2222
return NSLocalizedString("The book you were trying to read is in an unsupported format.", comment: "Error message when trying to read a publication with a unsupported format")
23-
case .epubNotValid:
24-
return NSLocalizedString("The book you were trying to read is corrupted. Please try downloading it again.", comment: "Error message when trying to read an EPUB that is invalid")
23+
case .epubNotValid(let errorCause):
24+
return String.localizedStringWithFormat(
25+
NSLocalizedString("The book you were trying to read is corrupted (%@). Please try downloading it again.", comment: "Error message when trying to read an EPUB that is invalid"),
26+
errorCause)
2527
}
2628
}
27-
2829
}

Simplified/Reader2/ReaderPresentation/ReaderModule.swift

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ protocol ReaderModuleAPI {
4141
syncPermission: Bool,
4242
deviceID: String?,
4343
in navigationController: UINavigationController,
44-
successCompletion: (() -> Void)?)
44+
completion: ((_ success: Bool) -> Void)?)
4545

4646
}
4747

@@ -82,7 +82,7 @@ final class ReaderModule: ReaderModuleAPI {
8282
syncPermission: Bool,
8383
deviceID: String?,
8484
in navigationController: UINavigationController,
85-
successCompletion: (() -> Void)?) {
85+
completion: ((_ success: Bool) -> Void)?) {
8686
if delegate == nil {
8787
NYPLErrorLogger.logError(nil, summary: "ReaderModule delegate is not set")
8888
}
@@ -102,7 +102,7 @@ final class ReaderModule: ReaderModuleAPI {
102102
formatModule: formatModule,
103103
positioningAt: initialLocator,
104104
in: navigationController,
105-
successCompletion: successCompletion)
105+
completion: completion)
106106
}
107107
}
108108

@@ -112,7 +112,7 @@ final class ReaderModule: ReaderModuleAPI {
112112
formatModule: ReaderFormatModule,
113113
positioningAt initialLocator: Locator?,
114114
in navigationController: UINavigationController,
115-
successCompletion: (() -> Void)?) {
115+
completion: ((_ success: Bool) -> Void)?) {
116116
do {
117117
let readerVC = try formatModule.makeReaderViewController(
118118
for: publication,
@@ -126,9 +126,10 @@ final class ReaderModule: ReaderModuleAPI {
126126
readerVC.hidesBottomBarWhenPushed = true
127127
navigationController.pushViewController(readerVC, animated: true)
128128

129-
successCompletion?()
129+
completion?(true)
130130
} catch {
131131
delegate?.presentError(error, from: navigationController)
132+
completion?(false)
132133
}
133134
}
134135
}

Simplified/Reader2/ReaderPresentation/ReadingFormats/EPUBModule.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,13 @@ final class EPUBModule: ReaderFormatModule {
3939
initialLocation: Locator?) throws -> UIViewController {
4040

4141
guard publication.metadata.identifier != nil else {
42-
throw ReaderError.epubNotValid
42+
throw ReaderError.epubNotValid("nil metadata id")
4343
}
4444

45+
guard publication.baseURL != nil else {
46+
throw ReaderError.epubNotValid("nil baseURL")
47+
}
48+
4549
let epubVC = NYPLEPUBViewController(publication: publication,
4650
book: book,
4751
initialLocation: initialLocation,

0 commit comments

Comments
 (0)