Skip to content

Commit

Permalink
Release 1.0.1 with trigger.
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Rupérez committed May 24, 2017
1 parent 9af0557 commit 1964c66
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 11 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# Release 1.0.1

- [x] LaunchScreenSnapshot.Trigger enum.

# Release 0.2.0

- [x] LaunchScreenSnapshot.Animation struct.
Expand Down
2 changes: 1 addition & 1 deletion LaunchScreenSnapshot.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'LaunchScreenSnapshot'
s.version = '0.2.0'
s.version = '1.0.1'
s.summary = 'Protects sensitive data in your app snapshot.'

s.homepage = 'https://github.com/alexruperez/LaunchScreenSnapshot'
Expand Down
8 changes: 4 additions & 4 deletions LaunchScreenSnapshot.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -488,8 +488,8 @@
CURRENT_PROJECT_VERSION = "${DYLIB_CURRENT_VERSION}";
DEBUG_INFORMATION_FORMAT = dwarf;
DEVELOPMENT_TEAM = Q6BEQCNWYM;
DYLIB_COMPATIBILITY_VERSION = 0.2.0;
DYLIB_CURRENT_VERSION = 0.2.0;
DYLIB_COMPATIBILITY_VERSION = 1.0.1;
DYLIB_CURRENT_VERSION = 1.0.1;
ENABLE_STRICT_OBJC_MSGSEND = YES;
ENABLE_TESTABILITY = YES;
GCC_C_LANGUAGE_STANDARD = gnu99;
Expand Down Expand Up @@ -566,8 +566,8 @@
CURRENT_PROJECT_VERSION = "${DYLIB_CURRENT_VERSION}";
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
DEVELOPMENT_TEAM = Q6BEQCNWYM;
DYLIB_COMPATIBILITY_VERSION = 0.2.0;
DYLIB_CURRENT_VERSION = 0.2.0;
DYLIB_COMPATIBILITY_VERSION = 1.0.1;
DYLIB_CURRENT_VERSION = 1.0.1;
ENABLE_NS_ASSERTIONS = NO;
ENABLE_STRICT_OBJC_MSGSEND = YES;
GCC_C_LANGUAGE_STANDARD = gnu99;
Expand Down
29 changes: 24 additions & 5 deletions LaunchScreenSnapshot/LaunchScreenSnapshot.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,21 @@ public class LaunchScreenSnapshot {
}
}

/// Protection trigger.
public enum Trigger {
/// Protect when app will resign active.
case willResignActive
/// Protect when app did enter background.
case didEnterBackground
}

/// Shared LaunchScreenSnapshot instance with default configuration.
public static let shared = LaunchScreenSnapshot()
/// UIWindow where your custom snapshot will be added.
public var window: UIWindow?
fileprivate let application: UIApplication
fileprivate var view: UIView?
fileprivate var trigger = Trigger.willResignActive
fileprivate var animation = Animation()
fileprivate var force = false
private let notificationCenter: NotificationCenter
Expand All @@ -65,9 +74,9 @@ public class LaunchScreenSnapshot {
- Returns: Shared LaunchScreenSnapshot instance with default configuration.
*/
@discardableResult public static func protect(with view: UIView? = nil, animation: Animation = Animation(), force: Bool = false) -> LaunchScreenSnapshot {
@discardableResult public static func protect(with view: UIView? = nil, trigger: Trigger = .willResignActive, animation: Animation = Animation(), force: Bool = false) -> LaunchScreenSnapshot {
let launchScreenSnapshot = LaunchScreenSnapshot.shared
launchScreenSnapshot.protect(with: view, animation: animation, force: force)
launchScreenSnapshot.protect(with: view, trigger: trigger, animation: animation, force: force)
return launchScreenSnapshot
}

Expand Down Expand Up @@ -97,6 +106,7 @@ public class LaunchScreenSnapshot {
self.notificationCenter = notificationCenter
self.bundle = bundle
notificationCenter.addObserver(self, selector: #selector(applicationWillResignActive), name: .UIApplicationWillResignActive, object: nil)
notificationCenter.addObserver(self, selector: #selector(applicationDidEnterBackground), name: .UIApplicationDidEnterBackground, object: nil)
notificationCenter.addObserver(self, selector: #selector(applicationWillEnterForeground), name: .UIApplicationWillEnterForeground, object: nil)
notificationCenter.addObserver(self, selector: #selector(applicationDidBecomeActive), name: .UIApplicationDidBecomeActive, object: nil)
}
Expand All @@ -115,7 +125,7 @@ public class LaunchScreenSnapshot {
- Returns: true if your app snapshot has been protected.
*/
@discardableResult public func protect(with view: UIView? = nil, animation: Animation = Animation(), force: Bool = false) -> Bool {
@discardableResult public func protect(with view: UIView? = nil, trigger: Trigger = .willResignActive, animation: Animation = Animation(), force: Bool = false) -> Bool {
self.view = view
if self.view == nil {
if let launchStoryboardName = bundle.object(forInfoDictionaryKey: "UILaunchStoryboardName") as? String {
Expand All @@ -124,6 +134,7 @@ public class LaunchScreenSnapshot {
self.view = viewFromStoryboard(name: launchStoryboardName, bundle: bundle)
}
}
self.trigger = trigger
self.animation = animation
assert(animation.dampingRatio > 0, "LaunchScreenSnapshot: dampingRatio must be greater than 0.")
self.force = force
Expand All @@ -146,8 +157,15 @@ public class LaunchScreenSnapshot {
private extension LaunchScreenSnapshot {

@objc func applicationWillResignActive(_ notification: Notification) {
application.ignoreSnapshotOnNextApplicationLaunch()
addView()
if trigger == .willResignActive {
addView()
}
}

@objc func applicationDidEnterBackground(_ notification: Notification) {
if trigger == .didEnterBackground {
addView()
}
}

@objc func applicationWillEnterForeground(_ notification: Notification) {
Expand All @@ -163,6 +181,7 @@ private extension LaunchScreenSnapshot {
}

func addView() {
application.ignoreSnapshotOnNextApplicationLaunch()
if let view = view {
view.alpha = 0
window?.addSubview(view)
Expand Down
12 changes: 12 additions & 0 deletions LaunchScreenSnapshotTests/LaunchScreenSnapshotTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,18 @@ class LaunchScreenSnapshotTests: XCTestCase {
XCTAssertTrue(window.subviews.contains(view))
}

func testApplicationDidEnterBackground() {
let window = UIWindow()
let view = UIView()
let notificationCenter = NotificationCenter.default
let launchScreenSnapshot = LaunchScreenSnapshot(notificationCenter: notificationCenter)
launchScreenSnapshot.window = window
launchScreenSnapshot.protect(with: view, trigger: .didEnterBackground)
XCTAssertFalse(window.subviews.contains(view))
notificationCenter.post(name: .UIApplicationDidEnterBackground, object: nil)
XCTAssertTrue(window.subviews.contains(view))
}

func testApplicationDidBecomeActive() {
let window = UIWindow()
let view = UIView()
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ let launchScreenSnapshot = LaunchScreenSnapshot(application: UIApplication, noti

```swift
let animationOptions = LaunchScreenSnapshot.Animation(duration: TimeInterval, delay: TimeInterval, dampingRatio: CGFloat, velocity: CGFloat, options: UIViewAnimationOptions)
launchScreenSnapshot.protect(with: UIView?, animation: animationOptions, force: Bool)
launchScreenSnapshot.protect(with: UIView?, trigger: LaunchScreenSnapshot.Trigger, animation: animationOptions, force: Bool)
```

## Etc.
Expand Down

0 comments on commit 1964c66

Please sign in to comment.