Skip to content

Commit bc78734

Browse files
Add macOS Compatibility (#332)
1 parent e488155 commit bc78734

File tree

7 files changed

+348
-8
lines changed

7 files changed

+348
-8
lines changed

OptimizelySwiftSDK.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ Pod::Spec.new do |s|
88
s.author = { "Optimizely" => "support@optimizely.com" }
99
s.ios.deployment_target = "10.0"
1010
s.tvos.deployment_target = "10.0"
11+
s.osx.deployment_target = "10.14"
1112
s.source = {
1213
:git => "https://github.com/optimizely/swift-sdk.git",
1314
:tag => "v"+s.version.to_s
@@ -18,4 +19,3 @@ Pod::Spec.new do |s|
1819
s.requires_arc = true
1920
s.xcconfig = { 'GCC_PREPROCESSOR_DEFINITIONS' => "OPTIMIZELY_SDK_VERSION=@\\\"#{s.version}\\\"" }
2021
end
21-

OptimizelySwiftSDK.xcodeproj/project.pbxproj

Lines changed: 246 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<Scheme
3+
LastUpgradeVersion = "1130"
4+
version = "1.3">
5+
<BuildAction
6+
parallelizeBuildables = "YES"
7+
buildImplicitDependencies = "YES">
8+
<BuildActionEntries>
9+
<BuildActionEntry
10+
buildForTesting = "YES"
11+
buildForRunning = "YES"
12+
buildForProfiling = "YES"
13+
buildForArchiving = "YES"
14+
buildForAnalyzing = "YES">
15+
<BuildableReference
16+
BuildableIdentifier = "primary"
17+
BlueprintIdentifier = "BD64853A2491474500F30986"
18+
BuildableName = "Optimizely.framework"
19+
BlueprintName = "OptimizelySwiftSDK-macOS"
20+
ReferencedContainer = "container:OptimizelySwiftSDK.xcodeproj">
21+
</BuildableReference>
22+
</BuildActionEntry>
23+
</BuildActionEntries>
24+
</BuildAction>
25+
<TestAction
26+
buildConfiguration = "Debug"
27+
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
28+
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
29+
shouldUseLaunchSchemeArgsEnv = "YES">
30+
<Testables>
31+
</Testables>
32+
</TestAction>
33+
<LaunchAction
34+
buildConfiguration = "Debug"
35+
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
36+
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
37+
launchStyle = "0"
38+
useCustomWorkingDirectory = "NO"
39+
ignoresPersistentStateOnLaunch = "NO"
40+
debugDocumentVersioning = "YES"
41+
debugServiceExtension = "internal"
42+
allowLocationSimulation = "YES">
43+
<MacroExpansion>
44+
<BuildableReference
45+
BuildableIdentifier = "primary"
46+
BlueprintIdentifier = "BD64853A2491474500F30986"
47+
BuildableName = "Optimizely.framework"
48+
BlueprintName = "OptimizelySwiftSDK-macOS"
49+
ReferencedContainer = "container:OptimizelySwiftSDK.xcodeproj">
50+
</BuildableReference>
51+
</MacroExpansion>
52+
</LaunchAction>
53+
<ProfileAction
54+
buildConfiguration = "Release"
55+
shouldUseLaunchSchemeArgsEnv = "YES"
56+
savedToolIdentifier = ""
57+
useCustomWorkingDirectory = "NO"
58+
debugDocumentVersioning = "YES">
59+
<MacroExpansion>
60+
<BuildableReference
61+
BuildableIdentifier = "primary"
62+
BlueprintIdentifier = "BD64853A2491474500F30986"
63+
BuildableName = "Optimizely.framework"
64+
BlueprintName = "OptimizelySwiftSDK-macOS"
65+
ReferencedContainer = "container:OptimizelySwiftSDK.xcodeproj">
66+
</BuildableReference>
67+
</MacroExpansion>
68+
</ProfileAction>
69+
<AnalyzeAction
70+
buildConfiguration = "Debug">
71+
</AnalyzeAction>
72+
<ArchiveAction
73+
buildConfiguration = "Release"
74+
revealArchiveInOrganizer = "YES">
75+
</ArchiveAction>
76+
</Scheme>
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
33
<plist version="1.0">
4-
<dict/>
4+
<dict>
5+
<key>PreviewsEnabled</key>
6+
<false/>
7+
</dict>
58
</plist>

Package.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ let package = Package(
55
name: "Optimizely",
66
platforms: [
77
.iOS(.v10),
8-
.tvOS(.v10)
8+
.tvOS(.v10),
9+
.macOS(.v10_14)
910
],
1011
products: [
1112
.library(name: "Optimizely",

Sources/Protocols/BackgroundingCallbacks.swift

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,23 +15,37 @@
1515
***************************************************************************/
1616

1717
import Foundation
18+
#if os(macOS)
19+
import Cocoa
20+
#else // iOS, tvOS
1821
import UIKit
22+
#endif
1923

2024
@objc protocol BackgroundingCallbacks {
2125
func applicationDidEnterBackground()
2226
func applicationDidBecomeActive()
2327
}
2428

29+
private extension NSNotification.Name {
30+
#if os(macOS)
31+
static let didEnterBackground = NSApplication.didResignActiveNotification
32+
static let didBecomeActive = NSApplication.didBecomeActiveNotification
33+
#else // iOS, tvOS
34+
static let didEnterBackground = UIApplication.didEnterBackgroundNotification
35+
static let didBecomeActive = UIApplication.didBecomeActiveNotification
36+
#endif
37+
}
38+
2539
extension BackgroundingCallbacks {
2640
func subscribe() {
2741
// swift4.2+
28-
NotificationCenter.default.addObserver(self, selector: #selector(applicationDidEnterBackground), name: UIApplication.didEnterBackgroundNotification, object: nil)
29-
NotificationCenter.default.addObserver(self, selector: #selector(applicationDidBecomeActive), name: UIApplication.didBecomeActiveNotification, object: nil)
42+
NotificationCenter.default.addObserver(self, selector: #selector(applicationDidEnterBackground), name: .didEnterBackground, object: nil)
43+
NotificationCenter.default.addObserver(self, selector: #selector(applicationDidBecomeActive), name: .didBecomeActive, object: nil)
3044
}
3145

3246
func unsubscribe() {
3347
// swift4.2+
34-
NotificationCenter.default.removeObserver(self, name: UIApplication.didEnterBackgroundNotification, object: nil)
35-
NotificationCenter.default.removeObserver(self, name: UIApplication.didBecomeActiveNotification, object: nil)
48+
NotificationCenter.default.removeObserver(self, name: .didEnterBackground, object: nil)
49+
NotificationCenter.default.removeObserver(self, name: .didBecomeActive, object: nil)
3650
}
3751
}

Sources/Supporting Files/Optimizely.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* limitations under the License. *
1515
***************************************************************************/
1616

17-
#import <UIKit/UIKit.h>
17+
@import Foundation;
1818

1919
//! Project version number for Optimizely.
2020
FOUNDATION_EXPORT double OptimizelyVersionNumber;

0 commit comments

Comments
 (0)