Skip to content

Commit 99eea8b

Browse files
committed
Added iOS extension support via SWIFTMESSAGES_APP_EXTENSIONS at compile time.
1 parent 659aa16 commit 99eea8b

File tree

3 files changed

+33
-2
lines changed

3 files changed

+33
-2
lines changed

SwiftMessages.podspec

+17-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,23 @@ Pod::Spec.new do |spec|
88
spec.source = {:git => 'https://github.com/SwiftKickMobile/SwiftMessages.git', :tag => '4.1.2'}
99
spec.platform = :ios, '8.0'
1010
spec.ios.deployment_target = '8.0'
11-
spec.source_files = 'SwiftMessages/**/*.swift'
12-
spec.resource_bundles = {'SwiftMessages' => ['SwiftMessages/Resources/**/*']}
1311
spec.framework = 'UIKit'
1412
spec.requires_arc = true
13+
spec.default_subspec = 'Core'
14+
15+
spec.subspec 'Core' do |core|
16+
core.source_files = 'SwiftMessages/**/*.swift'
17+
core.resource_bundles = {'SwiftMessages' => ['SwiftMessages/Resources/**/*']}
18+
end
19+
20+
spec.subspec 'AppExtension' do |ext|
21+
ext.source_files = 'SwiftMessages/**/*.swift'
22+
ext.resource_bundles = {'SwiftMessages' => ['SwiftMessages/Resources/**/*']}
23+
24+
# For app extensions, disabling code paths using unavailable API
25+
ext.pod_target_xcconfig = {
26+
'SWIFT_ACTIVE_COMPILATION_CONDITIONS' => 'SWIFTMESSAGES_APP_EXTENSIONS',
27+
'GCC_PREPROCESSOR_DEFINITIONS' => 'SWIFTMESSAGES_APP_EXTENSIONS=1'
28+
}
29+
end
1530
end

SwiftMessages/Presenter.swift

+8
Original file line numberDiff line numberDiff line change
@@ -256,12 +256,16 @@ class Presenter: NSObject {
256256
}
257257
return conflicts
258258
} else {
259+
#if SWIFTMESSAGES_APP_EXTENSIONS
260+
return []
261+
#else
259262
if UIApplication.shared.isStatusBarHidden { return [] }
260263
if !inNormalWindowLevel || underNavigationBar { return [] }
261264
let statusBarFrame = UIApplication.shared.statusBarFrame
262265
let statusBarWindowFrame = window.convert(statusBarFrame, from: nil)
263266
let statusBarViewFrame = maskingView.convert(statusBarWindowFrame, from: nil)
264267
return statusBarViewFrame.intersects(maskingView.bounds) ? SafeZoneConflicts.statusBar : []
268+
#endif
265269
}
266270
}
267271

@@ -274,12 +278,16 @@ class Presenter: NSObject {
274278

275279
switch config.presentationContext {
276280
case .automatic:
281+
#if SWIFTMESSAGES_APP_EXTENSIONS
282+
throw SwiftMessagesError.noRootViewController
283+
#else
277284
if let rootViewController = UIApplication.shared.keyWindow?.rootViewController {
278285
let viewController = rootViewController.sm_selectPresentationContextTopDown(config)
279286
return .viewController(Weak(value: viewController))
280287
} else {
281288
throw SwiftMessagesError.noRootViewController
282289
}
290+
#endif
283291
case .window(let level):
284292
let viewController = newWindowViewController(level)
285293
return .viewController(Weak(value: viewController))

SwiftMessages/TopBottomAnimation.swift

+8
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,11 @@ public class TopBottomAnimation: NSObject, Animator {
5555
container.layoutIfNeeded()
5656
}, completion: { completed in
5757
// Fix #131 by always completing if application isn't active.
58+
#if SWIFTMESSAGES_APP_EXTENSIONS
59+
completion(completed)
60+
#else
5861
completion(completed || UIApplication.shared.applicationState != .active)
62+
#endif
5963
})
6064
}
6165

@@ -136,7 +140,11 @@ public class TopBottomAnimation: NSObject, Animator {
136140
container.layoutIfNeeded()
137141
}, completion: { completed in
138142
// Fix #131 by always completing if application isn't active.
143+
#if SWIFTMESSAGES_APP_EXTENSIONS
144+
completion(completed)
145+
#else
139146
completion(completed || UIApplication.shared.applicationState != .active)
147+
#endif
140148
})
141149
}
142150

0 commit comments

Comments
 (0)