|
2 | 2 |
|
3 | 3 | All migration steps necessary in reading apps to upgrade to major versions of the Swift Readium toolkit will be documented in this file.
|
4 | 4 |
|
| 5 | +## Unreleased |
| 6 | + |
| 7 | +### R2 prefix dropped |
| 8 | + |
| 9 | +The `R2` prefix is now deprecated. The `R2Shared`, `R2Streamer` and `R2Navigator` packages were renamed as `ReadiumShared`, `ReadiumStreamer` and `ReadiumNavigator`. |
| 10 | + |
| 11 | +You will need to update your imports, as well as the dependencies you include in your project: |
| 12 | + |
| 13 | +* Swift Package Manager: There's nothing to do. |
| 14 | +* Carthage: |
| 15 | + * Update the Carthage dependencies and make sure the new `ReadiumShared.xcframework`, `ReadiumStreamer.xcframework` and `ReadiumNavigator.xcframework` were built. |
| 16 | + * Replace the old frameworks with the new ones in your project. |
| 17 | +* CocoaPods: |
| 18 | + * Update the `pod` statements in your `Podfile` with the following, before running `pod install`: |
| 19 | + ``` |
| 20 | + pod 'ReadiumShared', podspec: 'https://raw.githubusercontent.com/readium/swift-toolkit/3.0.0/Support/CocoaPods/ReadiumShared.podspec' |
| 21 | + pod 'ReadiumStreamer', podspec: 'https://raw.githubusercontent.com/readium/swift-toolkit/3.0.0/Support/CocoaPods/ReadiumStreamer.podspec' |
| 22 | + pod 'ReadiumNavigator', podspec: 'https://raw.githubusercontent.com/readium/swift-toolkit/3.0.0/Support/CocoaPods/ReadiumNavigator.podspec' |
| 23 | + ``` |
| 24 | + |
| 25 | +### Migration of HREFs and Locators (bookmarks, annotations, etc.) |
| 26 | + |
| 27 | + :warning: This requires a database migration in your application, if you were persisting `Locator` objects. |
| 28 | + |
| 29 | + In Readium v2.x, a `Link` or `Locator`'s `href` could be either: |
| 30 | + |
| 31 | + * a valid absolute URL for a streamed publication, e.g. `https://domain.com/isbn/dir/my%20chapter.html`, |
| 32 | + * a percent-decoded path for a local archive such as an EPUB, e.g. `/dir/my chapter.html`. |
| 33 | + * Note that it was relative to the root of the archive (`/`). |
| 34 | + |
| 35 | + To improve the interoperability with other Readium toolkits (in particular the Readium Web Toolkits, which only work in a streaming context) **Readium v3 now generates and expects valid URLs** for `Locator` and `Link`'s `href`. |
| 36 | + |
| 37 | + * `https://domain.com/isbn/dir/my%20chapter.html` is left unchanged, as it was already a valid URL. |
| 38 | + * `/dir/my chapter.html` becomes the relative URL path `dir/my%20chapter.html` |
| 39 | + * We dropped the `/` prefix to avoid issues when resolving to a base URL. |
| 40 | + * Special characters are percent-encoded. |
| 41 | + |
| 42 | + **You must migrate the HREFs or Locators stored in your database** when upgrading to Readium 3. To assist you, two helpers are provided: `AnyURL(legacyHREF:)` and `Locator(legacyJSONString:)`. |
| 43 | + |
| 44 | + Here's an example of a [GRDB migration](https://swiftpackageindex.com/groue/grdb.swift/master/documentation/grdb/migrations) that can serve as inspiration: |
| 45 | + |
| 46 | + ```swift |
| 47 | + migrator.registerMigration("normalizeHREFs") { db in |
| 48 | + let normalizedRows: [(id: Int, href: String, locator: String)] = |
| 49 | + try Row.fetchAll(db, sql: "SELECT id, href, locator FROM bookmarks") |
| 50 | + .compactMap { row in |
| 51 | + guard |
| 52 | + let normalizedHREF = AnyURL(legacyHREF: row["href"])?.string, |
| 53 | + let normalizedLocator = try Locator(legacyJSONString: row["locator"])?.jsonString |
| 54 | + else { |
| 55 | + return nil |
| 56 | + } |
| 57 | + return (row["id"], normalizedHREF, normalizedLocator) |
| 58 | + } |
| 59 | + |
| 60 | + let updateStmt = try db.makeStatement(sql: "UPDATE bookmarks SET href = :href, locator = :locator WHERE id = :id") |
| 61 | + for (id, href, locator) in normalizedRows { |
| 62 | + try updateStmt.execute(arguments: [ |
| 63 | + "id": id, |
| 64 | + "href": href |
| 65 | + "locator": locator |
| 66 | + ]) |
| 67 | + } |
| 68 | +} |
| 69 | +``` |
| 70 | + |
| 71 | + |
5 | 72 | ## 2.7.0
|
6 | 73 |
|
7 | 74 | ### `AudioNavigator` is now stable
|
@@ -56,7 +123,7 @@ Instead, the EPUB, PDF and CBZ navigators expect an instance of `HTTPServer` upo
|
56 | 123 | You can implement your own HTTP server using a third-party library. But the easiest way to migrate is to use the one provided in the new Readium package `ReadiumAdapterGCDWebServer`.
|
57 | 124 |
|
58 | 125 | ```swift
|
59 |
| -import R2Navigator |
| 126 | +import ReadiumNavigator |
60 | 127 | import ReadiumAdapterGCDWebServer
|
61 | 128 |
|
62 | 129 | let navigator = try EPUBNavigatorViewController(
|
@@ -167,15 +234,15 @@ Then, rebuild the libraries using `carthage update --platform ios --use-xcframew
|
167 | 234 | If you are using CocoaPods, you will need to update the URL to the Podspecs in your `Podfile`:
|
168 | 235 |
|
169 | 236 | ```diff
|
170 |
| -+ pod 'R2Shared', podspec: 'https://raw.githubusercontent.com/readium/swift-toolkit/2.2.0/Support/CocoaPods/ReadiumShared.podspec' |
171 |
| -+ pod 'R2Streamer', podspec: 'https://raw.githubusercontent.com/readium/swift-toolkit/2.2.0/Support/CocoaPods/ReadiumStreamer.podspec' |
172 |
| -+ pod 'R2Navigator', podspec: 'https://raw.githubusercontent.com/readium/swift-toolkit/2.2.0/Support/CocoaPods/ReadiumNavigator.podspec' |
| 237 | ++ pod 'ReadiumShared', podspec: 'https://raw.githubusercontent.com/readium/swift-toolkit/2.2.0/Support/CocoaPods/ReadiumShared.podspec' |
| 238 | ++ pod 'ReadiumStreamer', podspec: 'https://raw.githubusercontent.com/readium/swift-toolkit/2.2.0/Support/CocoaPods/ReadiumStreamer.podspec' |
| 239 | ++ pod 'ReadiumNavigator', podspec: 'https://raw.githubusercontent.com/readium/swift-toolkit/2.2.0/Support/CocoaPods/ReadiumNavigator.podspec' |
173 | 240 | + pod 'ReadiumOPDS', podspec: 'https://raw.githubusercontent.com/readium/swift-toolkit/2.2.0/Support/CocoaPods/ReadiumOPDS.podspec'
|
174 | 241 | + pod 'ReadiumLCP', podspec: 'https://raw.githubusercontent.com/readium/swift-toolkit/2.2.0/Support/CocoaPods/ReadiumLCP.podspec'
|
175 | 242 |
|
176 |
| -- pod 'R2Shared', podspec: 'https://raw.githubusercontent.com/readium/r2-shared-swift/2.2.0/R2Shared.podspec' |
177 |
| -- pod 'R2Streamer', podspec: 'https://raw.githubusercontent.com/readium/r2-streamer-swift/2.2.0/R2Streamer.podspec' |
178 |
| -- pod 'R2Navigator', podspec: 'https://raw.githubusercontent.com/readium/r2-navigator-swift/2.2.0/R2Navigator.podspec' |
| 243 | +- pod 'ReadiumShared', podspec: 'https://raw.githubusercontent.com/readium/r2-shared-swift/2.2.0/ReadiumShared.podspec' |
| 244 | +- pod 'ReadiumStreamer', podspec: 'https://raw.githubusercontent.com/readium/r2-streamer-swift/2.2.0/ReadiumStreamer.podspec' |
| 245 | +- pod 'ReadiumNavigator', podspec: 'https://raw.githubusercontent.com/readium/r2-navigator-swift/2.2.0/ReadiumNavigator.podspec' |
179 | 246 | - pod 'ReadiumOPDS', podspec: 'https://raw.githubusercontent.com/readium/r2-opds-swift/2.2.0/ReadiumOPDS.podspec'
|
180 | 247 | - pod 'ReadiumLCP', podspec: 'https://raw.githubusercontent.com/readium/r2-lcp-swift/2.2.0/ReadiumLCP.podspec'
|
181 | 248 | ```
|
@@ -275,7 +342,7 @@ Migrating a project to XCFrameworks is [explained on Carthage's repository](http
|
275 | 342 |
|
276 | 343 | #### Troubleshooting
|
277 | 344 |
|
278 |
| -If after migrating to XCFrameworks you experience some build issues like **Could not find module 'R2Shared' for target 'X'**, try building the `r2-shared-swift` target with Xcode manually, before building your app. If you know of a better way to handle this, [please share it with the community](https://github.com/readium/r2-testapp-swift/issues/new). |
| 345 | +If after migrating to XCFrameworks you experience some build issues like **Could not find module 'ReadiumShared' for target 'X'**, try building the `r2-shared-swift` target with Xcode manually, before building your app. If you know of a better way to handle this, [please share it with the community](https://github.com/readium/r2-testapp-swift/issues/new). |
279 | 346 |
|
280 | 347 | ### LCP
|
281 | 348 |
|
|
0 commit comments