Manos Chorianopoulos

Fix SPM bundle loading issue

Showing 15 changed files with 67 additions and 40 deletions
......@@ -1405,7 +1405,7 @@ public final class WarplySDK {
showDialog(controller, "Δεν υπάρχει σύνδεση", "Αυτή τη στιγμή βρίσκεσαι εκτός σύνδεσης. Παρακαλούμε βεβαιώσου ότι είσαι συνδεδεμένος στο διαδίκτυο και προσπάθησε ξανά.")
} else {
let tempCampaign = CampaignItemModel()
let storyboard = UIStoryboard(name: "Main", bundle: Bundle(for: MyEmptyClass.self))
let storyboard = UIStoryboard(name: "Main", bundle: Bundle.frameworkBundle)
let vc = storyboard.instantiateViewController(withIdentifier: "CampaignViewController") as! SwiftWarplyFramework.CampaignViewController
let url = getMarketPassMapUrl()
let params = constructCampaignParams(campaign: tempCampaign, isMap: true)
......@@ -1431,7 +1431,7 @@ public final class WarplySDK {
showDialog(controller, "Δεν υπάρχει σύνδεση", "Αυτή τη στιγμή βρίσκεσαι εκτός σύνδεσης. Παρακαλούμε βεβαιώσου ότι είσαι συνδεδεμένος στο διαδίκτυο και προσπάθησε ξανά.")
} else {
if let superMarketCampaign = getSupermarketCampaign() {
let storyboard = UIStoryboard(name: "Main", bundle: Bundle(for: MyEmptyClass.self))
let storyboard = UIStoryboard(name: "Main", bundle: Bundle.frameworkBundle)
let vc = storyboard.instantiateViewController(withIdentifier: "CampaignViewController") as! SwiftWarplyFramework.CampaignViewController
let url = constructCampaignUrl(superMarketCampaign)
let params = constructCampaignParams(superMarketCampaign)
......
......@@ -17,6 +17,11 @@ public class MyEmptyClass {
// }
public static func resourceBundle() -> Bundle? {
#if SWIFT_PACKAGE
// For SPM, resources are in Bundle.module
return Bundle.module
#else
// For CocoaPods, use existing logic
let frameworkBundle = Bundle(for: MyEmptyClass.self)
// Try ResourcesBundle.bundle first (for local development)
......@@ -33,6 +38,28 @@ public class MyEmptyClass {
// Final fallback to framework bundle itself
return frameworkBundle
#endif
}
}
// MARK: - Bundle Extensions for SPM Support
extension Bundle {
/// Returns the appropriate bundle for XIB files and storyboards
static var frameworkBundle: Bundle {
#if SWIFT_PACKAGE
return Bundle.module
#else
return Bundle(for: MyEmptyClass.self)
#endif
}
/// Returns the appropriate bundle for resources (images, fonts, etc.)
static var frameworkResourceBundle: Bundle? {
#if SWIFT_PACKAGE
return Bundle.module
#else
return MyEmptyClass.resourceBundle()
#endif
}
}
......
......@@ -50,7 +50,7 @@ extension UIViewController {
let view = UIView(frame: CGRect(x: 0, y: 0, width: 40, height: 40))
let imageView = UIImageView(frame: CGRect(x: 10, y: 12, width: 15, height: 15))
if let imgBackArrow = UIImage(named: icon, in: MyEmptyClass.resourceBundle(), compatibleWith: nil) {
if let imgBackArrow = UIImage(named: icon, in: Bundle.frameworkResourceBundle, compatibleWith: nil) {
imageView.image = imgBackArrow
}
view.addSubview(imageView)
......@@ -115,7 +115,7 @@ extension UIViewController {
let customInfoView = UIView(frame: CGRect(x: 0, y: 0, width: 24, height: 24))
// Create the UIImageView for the custom info image
let infoImageView = UIImageView(image: UIImage(named: "info_icon", in: MyEmptyClass.resourceBundle(), compatibleWith: nil)) // Your custom image
let infoImageView = UIImageView(image: UIImage(named: "info_icon", in: Bundle.frameworkResourceBundle, compatibleWith: nil)) // Your custom image
infoImageView.contentMode = .scaleAspectFit // Adjust to fit the image correctly
infoImageView.frame = customInfoView.bounds // Set the image to fill the view
......
......@@ -16,6 +16,6 @@ import UIKit
}
func configureCell(data: OfferModel) {
backgroundImage.image = UIImage(named: data.bannerImage, in: MyEmptyClass.resourceBundle(), compatibleWith: nil)
backgroundImage.image = UIImage(named: data.bannerImage, in: Bundle.frameworkResourceBundle, compatibleWith: nil)
}
}
......
......@@ -29,7 +29,7 @@ protocol MyRewardsBannerOffersScrollTableViewCellDelegate: AnyObject {
super.awakeFromNib()
// Initialization code
profileImage.image = UIImage(named: "profile_pic_default", in: MyEmptyClass.resourceBundle(), compatibleWith: nil)
profileImage.image = UIImage(named: "profile_pic_default", in: Bundle.frameworkResourceBundle, compatibleWith: nil)
profileButton.addTarget(self, action: #selector(profileButtonTapped), for: .touchUpInside)
......@@ -45,7 +45,7 @@ protocol MyRewardsBannerOffersScrollTableViewCellDelegate: AnyObject {
// Register XIBs for collection view cells
collectionView.register(UINib(nibName: "MyRewardsBannerOfferCollectionViewCell", bundle: Bundle(for: MyEmptyClass.self)), forCellWithReuseIdentifier: "MyRewardsBannerOfferCollectionViewCell")
collectionView.register(UINib(nibName: "MyRewardsBannerOfferCollectionViewCell", bundle: Bundle.frameworkBundle), forCellWithReuseIdentifier: "MyRewardsBannerOfferCollectionViewCell")
// Fix background colors
collectionView.backgroundColor = UIColor.clear
......
......@@ -32,8 +32,8 @@ import UIKit
}
func configureCell(data: OfferModel) {
bannerImage.image = UIImage(named: data.bannerImage, in: MyEmptyClass.resourceBundle(), compatibleWith: nil)
favoriteImage.image = UIImage(named: data.isFavorite ? "favorite_filled" : "favorite_empty", in: MyEmptyClass.resourceBundle(), compatibleWith: nil)
bannerImage.image = UIImage(named: data.bannerImage, in: Bundle.frameworkResourceBundle, compatibleWith: nil)
favoriteImage.image = UIImage(named: data.isFavorite ? "favorite_filled" : "favorite_empty", in: Bundle.frameworkResourceBundle, compatibleWith: nil)
let discountSymbol =
data.discountType == "percentage" ? "%"
......@@ -61,6 +61,6 @@ import UIKit
expirationLabel.font = UIFont(name: "PingLCG-Regular", size: 13)
expirationLabel.textColor = UIColor(rgb: 0x00111B)
logoImage.image = UIImage(named: data.merchantLogo, in: MyEmptyClass.resourceBundle(), compatibleWith: nil)
logoImage.image = UIImage(named: data.merchantLogo, in: Bundle.frameworkResourceBundle, compatibleWith: nil)
}
}
......
......@@ -37,7 +37,7 @@ protocol MyRewardsOffersScrollTableViewCellDelegate: AnyObject {
allButtonLabel.frame.size.height = allButtonLabel.intrinsicContentSize.height
// Register XIBs for collection view cells
collectionView.register(UINib(nibName: "MyRewardsOfferCollectionViewCell", bundle: Bundle(for: MyEmptyClass.self)), forCellWithReuseIdentifier: "MyRewardsOfferCollectionViewCell")
collectionView.register(UINib(nibName: "MyRewardsOfferCollectionViewCell", bundle: Bundle.frameworkBundle), forCellWithReuseIdentifier: "MyRewardsOfferCollectionViewCell")
// Fix background colors
collectionView.backgroundColor = UIColor.clear
......
......@@ -28,7 +28,7 @@ protocol ProfileCouponFiltersTableViewCellDelegate: AnyObject {
titleLabel.text = "Τα κουπόνια μου"
// Register XIBs for collection view cells
collectionView.register(UINib(nibName: "ProfileFilterCollectionViewCell", bundle: Bundle(for: MyEmptyClass.self)), forCellWithReuseIdentifier: "ProfileFilterCollectionViewCell")
collectionView.register(UINib(nibName: "ProfileFilterCollectionViewCell", bundle: Bundle.frameworkBundle), forCellWithReuseIdentifier: "ProfileFilterCollectionViewCell")
// Fix background colors
// collectionView.backgroundColor = UIColor.clear
......
......@@ -32,8 +32,8 @@ import UIKit
}
func configureCell(data: OfferModel) {
bannerImage.image = UIImage(named: data.bannerImage, in: MyEmptyClass.resourceBundle(), compatibleWith: nil)
favoriteImage.image = UIImage(named: data.isFavorite ? "favorite_filled" : "favorite_empty", in: MyEmptyClass.resourceBundle(), compatibleWith: nil)
bannerImage.image = UIImage(named: data.bannerImage, in: Bundle.frameworkResourceBundle, compatibleWith: nil)
favoriteImage.image = UIImage(named: data.isFavorite ? "favorite_filled" : "favorite_empty", in: Bundle.frameworkResourceBundle, compatibleWith: nil)
let discountSymbol =
data.discountType == "percentage" ? "%"
......@@ -61,7 +61,7 @@ import UIKit
expirationLabel.font = UIFont(name: "PingLCG-Regular", size: 13)
expirationLabel.textColor = UIColor(rgb: 0x00111B)
logoImage.image = UIImage(named: data.merchantLogo, in: MyEmptyClass.resourceBundle(), compatibleWith: nil)
logoImage.image = UIImage(named: data.merchantLogo, in: Bundle.frameworkResourceBundle, compatibleWith: nil)
}
public override func setSelected(_ selected: Bool, animated: Bool) {
......
......@@ -17,7 +17,7 @@ import UIKit
public override func awakeFromNib() {
super.awakeFromNib()
profileImage.image = UIImage(named: "profile_pic_default", in: MyEmptyClass.resourceBundle(), compatibleWith: nil)
profileImage.image = UIImage(named: "profile_pic_default", in: Bundle.frameworkResourceBundle, compatibleWith: nil)
tagView1.backgroundColor = UIColor(rgb: 0x09914E)
tagView1.layer.cornerRadius = 4.0
......
......@@ -13,7 +13,7 @@ import UIKit
public override func awakeFromNib() {
super.awakeFromNib()
questionnaireBannerImage.image = UIImage(named: "questionnaire_banner", in: MyEmptyClass.resourceBundle(), compatibleWith: nil)
questionnaireBannerImage.image = UIImage(named: "questionnaire_banner", in: Bundle.frameworkResourceBundle, compatibleWith: nil)
}
......
......@@ -12,7 +12,7 @@ import UIKit
// MARK: - Initializers
public convenience init() {
self.init(nibName: "CouponViewController", bundle: Bundle(for: MyEmptyClass.self))
self.init(nibName: "CouponViewController", bundle: Bundle.frameworkBundle)
}
public override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?) {
......@@ -99,13 +99,13 @@ import UIKit
infoView.layer.borderWidth = 1.0
infoView.layer.borderColor = UIColor(red: 0.01, green: 0.05, blue: 0.11, alpha: 0.19).cgColor
infoImage.image = UIImage(named: "info", in: MyEmptyClass.resourceBundle(), compatibleWith: nil)
shareImage.image = UIImage(named: "share", in: MyEmptyClass.resourceBundle(), compatibleWith: nil)
couponCodeArrowImage.image = UIImage(named: "arrow_down", in: MyEmptyClass.resourceBundle(), compatibleWith: nil)
copyButtonImage.image = UIImage(named: "copy", in: MyEmptyClass.resourceBundle(), compatibleWith: nil)
couponQRArrowImage.image = UIImage(named: "arrow_down", in: MyEmptyClass.resourceBundle(), compatibleWith: nil)
couponQRImage.image = UIImage(named: "barcode", in: MyEmptyClass.resourceBundle(), compatibleWith: nil)
termsButtonArrowImage.image = UIImage(named: "arrow_down", in: MyEmptyClass.resourceBundle(), compatibleWith: nil)
infoImage.image = UIImage(named: "info", in: Bundle.frameworkResourceBundle, compatibleWith: nil)
shareImage.image = UIImage(named: "share", in: Bundle.frameworkResourceBundle, compatibleWith: nil)
couponCodeArrowImage.image = UIImage(named: "arrow_down", in: Bundle.frameworkResourceBundle, compatibleWith: nil)
copyButtonImage.image = UIImage(named: "copy", in: Bundle.frameworkResourceBundle, compatibleWith: nil)
couponQRArrowImage.image = UIImage(named: "arrow_down", in: Bundle.frameworkResourceBundle, compatibleWith: nil)
couponQRImage.image = UIImage(named: "barcode", in: Bundle.frameworkResourceBundle, compatibleWith: nil)
termsButtonArrowImage.image = UIImage(named: "arrow_down", in: Bundle.frameworkResourceBundle, compatibleWith: nil)
infoLabel.font = UIFont(name: "PingLCG-Regular", size: 13)
infoLabel.textColor = UIColor(rgb: 0x020E1C)
......@@ -154,8 +154,8 @@ import UIKit
}
private func setupUI(with coupon: OfferModel) {
couponImage.image = UIImage(named: coupon.bannerImage, in: MyEmptyClass.resourceBundle(), compatibleWith: nil)
favoriteImage.image = UIImage(named: coupon.isFavorite ? "favorite2_filled" : "favorite2_empty", in: MyEmptyClass.resourceBundle(), compatibleWith: nil)
couponImage.image = UIImage(named: coupon.bannerImage, in: Bundle.frameworkResourceBundle, compatibleWith: nil)
favoriteImage.image = UIImage(named: coupon.isFavorite ? "favorite2_filled" : "favorite2_empty", in: Bundle.frameworkResourceBundle, compatibleWith: nil)
titleLabel.font = UIFont(name: "PingLCG-Bold", size: 24)
titleLabel.textColor = UIColor(rgb: 0xF2709D)
......
......@@ -13,7 +13,7 @@ import UIKit
// MARK: - Initializers
public convenience init() {
self.init(nibName: "MyRewardsViewController", bundle: Bundle(for: MyEmptyClass.self))
self.init(nibName: "MyRewardsViewController", bundle: Bundle.frameworkBundle)
}
public override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?) {
......@@ -310,8 +310,8 @@ import UIKit
// self.navigationController?.setNavigationBarHidden(true, animated: false)
// Register XIBs for table view cells
tableView.register(UINib(nibName: "MyRewardsBannerOffersScrollTableViewCell", bundle: Bundle(for: MyEmptyClass.self)), forCellReuseIdentifier: "MyRewardsBannerOffersScrollTableViewCell")
tableView.register(UINib(nibName: "MyRewardsOffersScrollTableViewCell", bundle: Bundle(for: MyEmptyClass.self)), forCellReuseIdentifier: "MyRewardsOffersScrollTableViewCell")
tableView.register(UINib(nibName: "MyRewardsBannerOffersScrollTableViewCell", bundle: Bundle.frameworkBundle), forCellReuseIdentifier: "MyRewardsBannerOffersScrollTableViewCell")
tableView.register(UINib(nibName: "MyRewardsOffersScrollTableViewCell", bundle: Bundle.frameworkBundle), forCellReuseIdentifier: "MyRewardsOffersScrollTableViewCell")
// Set up table view
tableView.delegate = self
......@@ -417,7 +417,7 @@ import UIKit
private func openCampaignViewController(with index: Int) {
let storyboard = UIStoryboard(name: "Main", bundle: Bundle(for: MyEmptyClass.self))
let storyboard = UIStoryboard(name: "Main", bundle: Bundle.frameworkBundle)
if let vc = storyboard.instantiateViewController(withIdentifier: "CampaignViewController") as? SwiftWarplyFramework.CampaignViewController {
// vc.campaignUrl = "https://warply.s3.amazonaws.com/dei/campaigns/DehEasterContest_stage/index.html"
vc.campaignUrl = contestUrls[index]
......@@ -428,14 +428,14 @@ import UIKit
}
private func openCouponViewController(with offer: OfferModel) {
let vc = SwiftWarplyFramework.CouponViewController(nibName: "CouponViewController", bundle: Bundle(for: MyEmptyClass.self))
let vc = SwiftWarplyFramework.CouponViewController(nibName: "CouponViewController", bundle: Bundle.frameworkBundle)
vc.coupon = offer
self.navigationController?.pushViewController(vc, animated: true)
}
private func openProfileViewController() {
let vc = SwiftWarplyFramework.ProfileViewController(nibName: "ProfileViewController", bundle: Bundle(for: MyEmptyClass.self))
let vc = SwiftWarplyFramework.ProfileViewController(nibName: "ProfileViewController", bundle: Bundle.frameworkBundle)
self.navigationController?.pushViewController(vc, animated: true)
}
......
......@@ -12,7 +12,7 @@ import UIKit
// MARK: - Initializers
public convenience init() {
self.init(nibName: "ProfileViewController", bundle: Bundle(for: MyEmptyClass.self))
self.init(nibName: "ProfileViewController", bundle: Bundle.frameworkBundle)
}
public override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?) {
......@@ -208,11 +208,11 @@ import UIKit
setNavigationTitle("Το προφίλ μου")
// Register XIBs for table view cells
tableView.register(UINib(nibName: "ProfileHeaderTableViewCell", bundle: Bundle(for: MyEmptyClass.self)), forCellReuseIdentifier: "ProfileHeaderTableViewCell")
tableView.register(UINib(nibName: "ProfileQuestionnaireTableViewCell", bundle: Bundle(for: MyEmptyClass.self)), forCellReuseIdentifier: "ProfileQuestionnaireTableViewCell")
tableView.register(UINib(nibName: "MyRewardsOffersScrollTableViewCell", bundle: Bundle(for: MyEmptyClass.self)), forCellReuseIdentifier: "MyRewardsOffersScrollTableViewCell")
tableView.register(UINib(nibName: "ProfileCouponFiltersTableViewCell", bundle: Bundle(for: MyEmptyClass.self)), forCellReuseIdentifier: "ProfileCouponFiltersTableViewCell")
tableView.register(UINib(nibName: "ProfileCouponTableViewCell", bundle: Bundle(for: MyEmptyClass.self)), forCellReuseIdentifier: "ProfileCouponTableViewCell")
tableView.register(UINib(nibName: "ProfileHeaderTableViewCell", bundle: Bundle.frameworkBundle), forCellReuseIdentifier: "ProfileHeaderTableViewCell")
tableView.register(UINib(nibName: "ProfileQuestionnaireTableViewCell", bundle: Bundle.frameworkBundle), forCellReuseIdentifier: "ProfileQuestionnaireTableViewCell")
tableView.register(UINib(nibName: "MyRewardsOffersScrollTableViewCell", bundle: Bundle.frameworkBundle), forCellReuseIdentifier: "MyRewardsOffersScrollTableViewCell")
tableView.register(UINib(nibName: "ProfileCouponFiltersTableViewCell", bundle: Bundle.frameworkBundle), forCellReuseIdentifier: "ProfileCouponFiltersTableViewCell")
tableView.register(UINib(nibName: "ProfileCouponTableViewCell", bundle: Bundle.frameworkBundle), forCellReuseIdentifier: "ProfileCouponTableViewCell")
// Set up table view
tableView.delegate = self
......@@ -264,7 +264,7 @@ import UIKit
}
private func openCouponViewController(with offer: OfferModel) {
let vc = SwiftWarplyFramework.CouponViewController(nibName: "CouponViewController", bundle: Bundle(for: MyEmptyClass.self))
let vc = SwiftWarplyFramework.CouponViewController(nibName: "CouponViewController", bundle: Bundle.frameworkBundle)
vc.coupon = offer
self.navigationController?.pushViewController(vc, animated: true)
......