forked from shu223/iOS-9-Sampler
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
156 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<?xml version="1.0" encoding="UTF-8" standalone="no"?> | ||
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="8187.4" systemVersion="14F27" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="Zw3-Q4-WsS"> | ||
<dependencies> | ||
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="8151.3"/> | ||
<capability name="Constraints to layout margins" minToolsVersion="6.0"/> | ||
</dependencies> | ||
<customFonts key="customFonts"> | ||
<mutableArray key="AvenirNext.ttc"> | ||
<string>AvenirNext-Regular</string> | ||
</mutableArray> | ||
</customFonts> | ||
<scenes> | ||
<!--Low Power Mode View Controller--> | ||
<scene sceneID="gmn-nN-Tag"> | ||
<objects> | ||
<viewController id="Zw3-Q4-WsS" customClass="LowPowerModeViewController" customModule="iOS9Sampler" customModuleProvider="target" sceneMemberID="viewController"> | ||
<layoutGuides> | ||
<viewControllerLayoutGuide type="top" id="2Fv-4E-TrW"/> | ||
<viewControllerLayoutGuide type="bottom" id="81P-Cm-eq4"/> | ||
</layoutGuides> | ||
<view key="view" contentMode="scaleToFill" id="YMR-f6-JY3"> | ||
<rect key="frame" x="0.0" y="0.0" width="600" height="600"/> | ||
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/> | ||
<subviews> | ||
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Label" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="VLT-bA-4ju"> | ||
<rect key="frame" x="278" y="288" width="43" height="23.5"/> | ||
<fontDescription key="fontDescription" name="AvenirNext-Medium" family="Avenir Next" pointSize="17"/> | ||
<color key="textColor" red="0.20000000000000001" green="0.59999999999999998" blue="0.80000000000000004" alpha="1" colorSpace="calibratedRGB"/> | ||
<nil key="highlightedColor"/> | ||
</label> | ||
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" textAlignment="natural" lineBreakMode="tailTruncation" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="u7i-o0-uc3"> | ||
<rect key="frame" x="20" y="28" width="560" height="160"/> | ||
<string key="text">How to try 1. Go to [Settings] > [Battery] 2. Turn [Low Power Mode] on/off. 3. Reopen this example. "NSProcessInfoPowerStateDidChangeNotification" is posted and observed by this example.</string> | ||
<fontDescription key="fontDescription" name="AvenirNext-Regular" family="Avenir Next" pointSize="13"/> | ||
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/> | ||
<nil key="highlightedColor"/> | ||
</label> | ||
</subviews> | ||
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/> | ||
<constraints> | ||
<constraint firstItem="u7i-o0-uc3" firstAttribute="top" secondItem="2Fv-4E-TrW" secondAttribute="bottom" constant="8" id="N0v-oO-sZL"/> | ||
<constraint firstItem="VLT-bA-4ju" firstAttribute="centerY" secondItem="YMR-f6-JY3" secondAttribute="centerY" id="eMg-Ad-5An"/> | ||
<constraint firstAttribute="trailingMargin" secondItem="u7i-o0-uc3" secondAttribute="trailing" id="kwf-fa-d86"/> | ||
<constraint firstItem="VLT-bA-4ju" firstAttribute="centerX" secondItem="YMR-f6-JY3" secondAttribute="centerX" id="pRK-aW-ogO"/> | ||
<constraint firstItem="u7i-o0-uc3" firstAttribute="leading" secondItem="YMR-f6-JY3" secondAttribute="leadingMargin" id="sxZ-q7-nQf"/> | ||
</constraints> | ||
</view> | ||
<connections> | ||
<outlet property="stateLabel" destination="VLT-bA-4ju" id="GeX-bd-G4l"/> | ||
</connections> | ||
</viewController> | ||
<placeholder placeholderIdentifier="IBFirstResponder" id="q4h-Q8-VHb" userLabel="First Responder" sceneMemberID="firstResponder"/> | ||
</objects> | ||
<point key="canvasLocation" x="-16" y="-794"/> | ||
</scene> | ||
</scenes> | ||
</document> |
60 changes: 60 additions & 0 deletions
60
iOS9Sampler/SampleViewControllers/LowPowerModeViewController.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
// | ||
// LowPowerModeViewController.swift | ||
// iOS9Sampler | ||
// | ||
// Created by Shuichi Tsutsumi on 9/9/15. | ||
// Copyright © 2015 Shuichi Tsutsumi. All rights reserved. | ||
// | ||
|
||
import UIKit | ||
|
||
class LowPowerModeViewController: UIViewController { | ||
|
||
|
||
@IBOutlet weak var stateLabel: UILabel! | ||
|
||
|
||
override func viewDidLoad() { | ||
super.viewDidLoad() | ||
|
||
|
||
self.updateStateLabel() | ||
|
||
|
||
NSNotificationCenter.defaultCenter().addObserverForName( | ||
NSProcessInfoPowerStateDidChangeNotification, | ||
object: nil, | ||
queue: nil) { (notification: NSNotification) -> Void in | ||
|
||
// A NSProcessInfo object can be retrieved from `object` property. | ||
let processInfo = notification.object as! NSProcessInfo | ||
|
||
dispatch_async(dispatch_get_main_queue(), { | ||
|
||
let alert = UIAlertController( | ||
title: "Power State has been changed.", | ||
message: "Current \"Low Power Mode\" setting: \(processInfo.lowPowerModeEnabled)", | ||
preferredStyle: UIAlertControllerStyle.Alert) | ||
let okAction = UIAlertAction( | ||
title: "OK", | ||
style: UIAlertActionStyle.Cancel, | ||
handler: nil) | ||
alert.addAction(okAction) | ||
self.presentViewController(alert, animated: true, completion: nil) | ||
|
||
self.updateStateLabel() | ||
}) | ||
} | ||
} | ||
|
||
override func didReceiveMemoryWarning() { | ||
super.didReceiveMemoryWarning() | ||
// Dispose of any resources that can be recreated. | ||
} | ||
|
||
|
||
private func updateStateLabel() { | ||
|
||
stateLabel.text = "lowPowerModeEnabled: \(NSProcessInfo().lowPowerModeEnabled)" | ||
} | ||
} |