Skip to content

Commit 395321b

Browse files
authored
SDK-290 Fix iOS SDK Header Exports for Objective-C++ Compatibility (#1002)
1 parent 2b3fde2 commit 395321b

5 files changed

Lines changed: 46 additions & 7 deletions

File tree

Iterable-iOS-SDK.podspec

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,13 @@ Pod::Spec.new do |s|
2020
s.documentation_url = "https://support.iterable.com/hc/en-us/articles/360035018152-Iterable-s-iOS-SDK"
2121

2222
s.pod_target_xcconfig = {
23-
'SWIFT_VERSION' => '5.3'
23+
'SWIFT_VERSION' => '5.3',
24+
'DEFINES_MODULE' => 'YES',
2425
}
2526

2627
s.swift_version = '5.3'
2728

28-
s.resource_bundles = {'Resources' => 'swift-sdk/Resources/**/*.{storyboard,xib,xcassets,xcdatamodeld}' }
29+
s.resource_bundles = {'IterableSDKResources' => 'swift-sdk/Resources/**/*.{storyboard,xib,xcassets,xcdatamodeld}' }
2930

3031
s.header_dir = 'IterableSDK'
3132
end

notification-extension/IterableAppExtensions.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77

88
#import <UIKit/UIKit.h>
99

10+
#ifdef __cplusplus
11+
extern "C" {
12+
#endif
13+
1014
//! Project version number for swift_sdk.
1115
FOUNDATION_EXPORT double swift_sdkVersionNumber;
1216

@@ -15,4 +19,8 @@ FOUNDATION_EXPORT const unsigned char swift_sdkVersionString[];
1519

1620
// In this header, you should import all the public headers of your framework using statements like #import <swift_sdk/PublicHeader.h>
1721

22+
#ifdef __cplusplus
23+
}
24+
#endif
25+
1826
#endif /* IterableAppExtensions_h */

swift-sdk/Internal/Utilities/ResourceHelper.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,13 @@ struct ResourceHelper {
1818

1919
private static let spmPackageName = "IterableSDK"
2020
private static let spmLibraryName = "IterableSDK"
21-
private static let cocoaPodsResourceBundleName = "Resources"
21+
static let cocoaPodsResourceBundleName = "IterableSDKResources"
22+
private static let legacyCocoaPodsResourceBundleName = "Resources"
2223

2324
private static let possibleSubBundleNames = [
2425
"\(spmPackageName)_\(spmLibraryName)",
25-
"\(cocoaPodsResourceBundleName)"
26+
"\(cocoaPodsResourceBundleName)",
27+
"\(legacyCocoaPodsResourceBundleName)"
2628
]
2729

2830
private static func findSubBundle(forBundle bundle: Bundle) -> Bundle? {

swift-sdk/IterableSDK.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44

55
#import <UIKit/UIKit.h>
66

7+
#ifdef __cplusplus
8+
extern "C" {
9+
#endif
10+
711
//! Project version number for swift_sdk.
812
FOUNDATION_EXPORT double swift_sdkVersionNumber;
913

@@ -12,3 +16,7 @@ FOUNDATION_EXPORT const unsigned char swift_sdkVersionString[];
1216

1317
// In this header, you should import all the public headers of your framework using statements like #import <swift_sdk/PublicHeader.h>
1418

19+
#ifdef __cplusplus
20+
}
21+
#endif
22+

swift-sdk/ui-components/uikit/IterableEmbeddedView.swift

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -207,8 +207,11 @@ public class IterableEmbeddedView: UIView {
207207
func loadViewFromNib() -> UIView? {
208208
var nib: UINib
209209
#if COCOAPODS
210-
let bundle = Bundle(path: Bundle(for: IterableEmbeddedView.self).path(forResource: "Resources", ofType: "bundle")!)
211-
nib = UINib(nibName: "IterableEmbeddedView", bundle: bundle)
210+
if let bundle = Self.findCocoaPodsResourceBundle() {
211+
nib = UINib(nibName: "IterableEmbeddedView", bundle: bundle)
212+
} else {
213+
nib = UINib(nibName: "IterableEmbeddedView", bundle: Bundle.main)
214+
}
212215
#else
213216
#if SWIFT_PACKAGE
214217
nib = UINib(nibName: "IterableEmbeddedView", bundle: Bundle.module)
@@ -222,7 +225,24 @@ public class IterableEmbeddedView: UIView {
222225
return view
223226
}
224227

225-
228+
private static let cocoaPodsResourceBundleNames = [
229+
ResourceHelper.cocoaPodsResourceBundleName,
230+
"Resources" // legacy name for cached pod builds
231+
]
232+
233+
private static func findCocoaPodsResourceBundle() -> Bundle? {
234+
let searchBundles = [Bundle.main, Bundle(for: IterableEmbeddedView.self)]
235+
for name in cocoaPodsResourceBundleNames {
236+
for parent in searchBundles {
237+
if let path = parent.path(forResource: name, ofType: "bundle"),
238+
let bundle = Bundle(path: path) {
239+
return bundle
240+
}
241+
}
242+
}
243+
return nil
244+
}
245+
226246
public func configure(message: IterableEmbeddedMessage, viewType: IterableEmbeddedViewType, config: IterableEmbeddedViewConfig?) {
227247

228248
self.message = message

0 commit comments

Comments
 (0)