Skip to content
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
16 changes: 2 additions & 14 deletions EmbedFramework/AdaWebHostViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,8 @@ import WebKit

class AdaWebHostViewController: UIViewController {
static func createWebController(with webView: WKWebView) -> AdaWebHostViewController {
let bundle = Bundle(for: AdaWebHostViewController.self)

var storyboard:UIStoryboard

// Loads the resource_bundle if available (Cocoapod)
if (bundle.path(forResource: "AdaEmbedFramework", ofType: "bundle") != nil){
let frameworkBundlePath = bundle.path(forResource: "AdaEmbedFramework", ofType: "bundle")!
let frameworkBundle = Bundle(path: frameworkBundlePath)
storyboard = UIStoryboard(name: "AdaWebHostViewController", bundle: frameworkBundle)
} else {
// Used for if SDK was manually imported
storyboard = UIStoryboard(name: "AdaWebHostViewController", bundle: bundle)
}

let storyboard = UIStoryboard(name: "AdaWebHostViewController", bundle: .ada)

guard let viewController = storyboard.instantiateInitialViewController() as? AdaWebHostViewController else { fatalError("This should never, ever happen.") }
viewController.webView = webView
return viewController
Expand Down
39 changes: 39 additions & 0 deletions EmbedFramework/Bundle+Ada.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
//
// Bundle+Ada.swift
// EmbedFramework
//
// Resolves the bundle that holds AdaEmbedFramework's resources
// (storyboard, asset catalog) across every integration method:
// Swift Package Manager, CocoaPods, Carthage, and manual import.
//

import Foundation

extension Bundle {
/// The bundle containing AdaEmbedFramework's resources.
///
/// - Under SPM, resources live in the generated `Bundle.module`.
/// - Under CocoaPods/Carthage, they live in a nested
/// `AdaEmbedFramework.bundle` inside the framework bundle.
/// - When manually imported, they sit directly in the framework bundle.
static let ada: Bundle = {
#if SWIFT_PACKAGE
return Bundle.module
#else
let moduleName = String(reflecting: BundleToken.self)
.components(separatedBy: ".")
.first
let bundle = Bundle(for: BundleToken.self)
guard
let moduleName = moduleName,
let path = bundle.path(forResource: moduleName, ofType: "bundle"),
let subbundle = Bundle(path: path)
else { return bundle }
return subbundle
#endif
}()
}

// MARK: -

private final class BundleToken {}
14 changes: 1 addition & 13 deletions EmbedFramework/OfflineViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,7 @@ class OfflineViewController: UIViewController {
var retryBlock: (() -> Void)?

static func create() -> OfflineViewController? {
let bundle = Bundle(for: OfflineViewController.self)

var storyboard:UIStoryboard

// Loads the resource_bundle if available (Cocoapod)
if (bundle.path(forResource: "AdaEmbedFramework", ofType: "bundle") != nil){
let frameworkBundlePath = bundle.path(forResource: "AdaEmbedFramework", ofType: "bundle")!
let frameworkBundle = Bundle(path: frameworkBundlePath)
storyboard = UIStoryboard(name: "AdaWebHostViewController", bundle: frameworkBundle)
} else {
// Used for if SDK was manually imported
storyboard = UIStoryboard(name: "AdaWebHostViewController", bundle: bundle)
}
let storyboard = UIStoryboard(name: "AdaWebHostViewController", bundle: .ada)
return storyboard.instantiateViewController(withIdentifier: "OfflineViewController") as? OfflineViewController
}

Expand Down
44 changes: 44 additions & 0 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// swift-tools-version:5.5
import PackageDescription

// Generated from AdaEmbedFramework.podspec (version 1.8.0).
// The target is named "AdaEmbedFramework" so it matches the
// customModule="AdaEmbedFramework" references inside the storyboard.
let package = Package(
name: "AdaEmbedFramework",
// podspec declares ios 10.0; SPM resource bundles are only reliable on iOS 11+.
platforms: [
.iOS(.v11)
],
products: [
.library(
name: "AdaEmbedFramework",
targets: ["AdaEmbedFramework"]
)
],
targets: [
.target(
name: "AdaEmbedFramework",
// Mirrors podspec source_files = "EmbedFramework/**/*.swift"
path: "EmbedFramework",
// Non-Swift files that are not part of the shipped resources.
exclude: [
"Info.plist",
"EmbedFramework.h",
"AdaEmbed.html",
"EmbedTest.html",
"EmbedView.xib",
"OfflineView.xib",
"View.xib",
"en.lproj"
],
// Mirrors podspec resource_bundles (xcassets + storyboard).
resources: [
.process("Assets.xcassets"),
.process("AdaWebHostViewController.storyboard")
]
// Swift 5 language mode (podspec swift_version = '5.0') is the
// default for swift-tools-version:5.5, so no extra setting is needed.
)
]
)