Skip to content

Commit f61b7d8

Browse files
authored
Merge pull request SwiftKickMobile#183 from amagrude/master
Added iOS app extension support at compile time.
2 parents 2f8de41 + 247a296 commit f61b7d8

File tree

10 files changed

+335
-273
lines changed

10 files changed

+335
-273
lines changed

Demo/Podfile.lock

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
PODS:
2-
- SwiftMessages (4.1.2)
2+
- SwiftMessages (4.1.3):
3+
- SwiftMessages/App (= 4.1.3)
4+
- SwiftMessages/App (4.1.3)
35

46
DEPENDENCIES:
57
- SwiftMessages (from `../`)
@@ -9,8 +11,8 @@ EXTERNAL SOURCES:
911
:path: "../"
1012

1113
SPEC CHECKSUMS:
12-
SwiftMessages: 7f883c0b717808e9557e9b385f8956418dddd1cb
14+
SwiftMessages: dea7e8f42d8c166bc7ca6ded4e5bd45300f36bf0
1315

1416
PODFILE CHECKSUM: 6431c980c9207084d738b6ba87b2101dd9eb5097
1517

16-
COCOAPODS: 1.5.0
18+
COCOAPODS: 1.5.2

Demo/Pods/Local Podspecs/SwiftMessages.podspec.json

+28-9
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Demo/Pods/Manifest.lock

+5-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Demo/Pods/Pods.xcodeproj/project.pbxproj

+261-253
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Demo/Pods/Target Support Files/Pods-Demo/Pods-Demo-resources.sh

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Demo/Pods/Target Support Files/SwiftMessages/Info.plist

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Demo/Pods/Target Support Files/SwiftMessages/ResourceBundle-SwiftMessages-Info.plist

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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.3'}
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 = 'App'
14+
15+
spec.subspec 'App' do |app|
16+
app.source_files = 'SwiftMessages/**/*.swift'
17+
app.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
@@ -265,12 +265,16 @@ class Presenter: NSObject {
265265
}
266266
return conflicts
267267
} else {
268+
#if SWIFTMESSAGES_APP_EXTENSIONS
269+
return []
270+
#else
268271
if UIApplication.shared.isStatusBarHidden { return [] }
269272
if (windowLevel > UIWindowLevelNormal) || underNavigationBar { return [] }
270273
let statusBarFrame = UIApplication.shared.statusBarFrame
271274
let statusBarWindowFrame = window.convert(statusBarFrame, from: nil)
272275
let statusBarViewFrame = maskingView.convert(statusBarWindowFrame, from: nil)
273276
return statusBarViewFrame.intersects(maskingView.bounds) ? SafeZoneConflicts.statusBar : []
277+
#endif
274278
}
275279
}
276280

@@ -283,12 +287,16 @@ class Presenter: NSObject {
283287

284288
switch config.presentationContext {
285289
case .automatic:
290+
#if SWIFTMESSAGES_APP_EXTENSIONS
291+
throw SwiftMessagesError.noRootViewController
292+
#else
286293
if let rootViewController = UIApplication.shared.keyWindow?.rootViewController {
287294
let viewController = rootViewController.sm_selectPresentationContextTopDown(config)
288295
return .viewController(Weak(value: viewController))
289296
} else {
290297
throw SwiftMessagesError.noRootViewController
291298
}
299+
#endif
292300
case .window(let level):
293301
let viewController = newWindowViewController(level)
294302
return .viewController(Weak(value: viewController))

SwiftMessages/TopBottomAnimation.swift

+8
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,12 @@ public class TopBottomAnimation: NSObject, Animator {
5454
self.translationConstraint.constant -= size.height
5555
container.layoutIfNeeded()
5656
}, completion: { completed in
57+
#if SWIFTMESSAGES_APP_EXTENSIONS
58+
completion(completed)
59+
#else
5760
// Fix #131 by always completing if application isn't active.
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)