Skip to content

Commit

Permalink
Added "Low Power Mode" example.
Browse files Browse the repository at this point in the history
  • Loading branch information
shu223 committed Sep 9, 2015
1 parent bb3b3c3 commit dda0c41
Show file tree
Hide file tree
Showing 7 changed files with 156 additions and 4 deletions.
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,17 @@ Example for Content Blocker Extensions.
Attributes viewer for **41 new filters** of CIFilter.

<img src="ResourcesForREADME/filterattributes.jpg" width="405">


###Low Power Mode

Detect changes of \"Low Power Mode\" setting.


##watchOS-2-Sampler

You can check the **examples for watchOS 2** features on [watchOS-2-Sampler](https://github.com/shu223/watchOS-2-Sampler)!!

<a href="https://github.com/shu223/watchOS-2-Sampler"><img src="ResourcesForREADME/watchos2sampler.jpg" width="200"></a>

- https://github.com/shu223/watchOS-2-Sampler
Binary file added ResourcesForREADME/watchos2sampler.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 16 additions & 0 deletions iOS9Sampler.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
8ADBD9FA1B8F675E00BB46D8 /* RootViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8ADBD9F91B8F675E00BB46D8 /* RootViewCell.swift */; };
8AF73F9A1BA0237E00E3783E /* SpeechViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8AF73F991BA0237E00E3783E /* SpeechViewController.swift */; settings = {ASSET_TAGS = (); }; };
8AF73F9C1BA0238900E3783E /* Speech.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 8AF73F9B1BA0238900E3783E /* Speech.storyboard */; settings = {ASSET_TAGS = (); }; };
8AF73FA51BA03C8900E3783E /* LowPowerMode.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 8AF73FA41BA03C8900E3783E /* LowPowerMode.storyboard */; settings = {ASSET_TAGS = (); }; };
8AF73FA71BA03C9600E3783E /* LowPowerModeViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8AF73FA61BA03C9600E3783E /* LowPowerModeViewController.swift */; settings = {ASSET_TAGS = (); }; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand Down Expand Up @@ -127,6 +129,8 @@
8ADBD9F91B8F675E00BB46D8 /* RootViewCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RootViewCell.swift; sourceTree = "<group>"; };
8AF73F991BA0237E00E3783E /* SpeechViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SpeechViewController.swift; sourceTree = "<group>"; };
8AF73F9B1BA0238900E3783E /* Speech.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; path = Speech.storyboard; sourceTree = "<group>"; };
8AF73FA41BA03C8900E3783E /* LowPowerMode.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; path = LowPowerMode.storyboard; sourceTree = "<group>"; };
8AF73FA61BA03C9600E3783E /* LowPowerModeViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LowPowerModeViewController.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -178,6 +182,7 @@
8A78588C1B8DDDEF00F93493 /* MapCustomizations */,
8A9078DD1B949B79000518C3 /* ContentBlocker */,
8AF73F9D1BA02C2E00E3783E /* SpeechVoices */,
8AF73FA81BA0432300E3783E /* LowPowerMode */,
);
path = SampleViewControllers;
sourceTree = "<group>";
Expand Down Expand Up @@ -366,6 +371,15 @@
name = SpeechVoices;
sourceTree = "<group>";
};
8AF73FA81BA0432300E3783E /* LowPowerMode */ = {
isa = PBXGroup;
children = (
8AF73FA61BA03C9600E3783E /* LowPowerModeViewController.swift */,
8AF73FA41BA03C8900E3783E /* LowPowerMode.storyboard */,
);
name = LowPowerMode;
sourceTree = "<group>";
};
/* End PBXGroup section */

/* Begin PBXNativeTarget section */
Expand Down Expand Up @@ -541,6 +555,7 @@
8A78588B1B8DDDD100F93493 /* MapCustomizations.storyboard in Resources */,
8A3588261B33CCD400D4D32C /* TextDetect.storyboard in Resources */,
8AD5D75C1B295E8C001924F0 /* Main.storyboard in Resources */,
8AF73FA51BA03C8900E3783E /* LowPowerMode.storyboard in Resources */,
8AF73F9C1BA0238900E3783E /* Speech.storyboard in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down Expand Up @@ -593,6 +608,7 @@
8A35882F1B33EC7A00D4D32C /* FiltersViewController.swift in Sources */,
8A3A32151B35DAD10016C4CE /* AudioUnitComponentManagerViewController.swift in Sources */,
8AD5D7571B295E8C001924F0 /* AppDelegate.swift in Sources */,
8AF73FA71BA03C9600E3783E /* LowPowerModeViewController.swift in Sources */,
8A3588351B3424E100D4D32C /* StillImageFiltersViewController.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down
5 changes: 5 additions & 0 deletions iOS9Sampler/RootViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ class RootViewController: UITableViewController {
kItemKeyDetail: "Attributes viewer for new filters of CIFilter.",
kItemKeyClassPrefix: "Filters"
],
[
kItemKeyTitle: "Low Power Mode",
kItemKeyDetail: "Detect changes of \"Low Power Mode\" setting.",
kItemKeyClassPrefix: "LowPowerMode"
],
]
}

Expand Down
8 changes: 4 additions & 4 deletions iOS9Sampler/SampleViewControllers/ContentBlocker.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,19 @@
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" textAlignment="natural" lineBreakMode="tailTruncation" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="68D-4U-vAA">
<rect key="frame" x="20" y="16" width="560" height="232.5"/>
<rect key="frame" x="20" y="16" width="560" height="205"/>
<string key="text">How to try

1. Go to [Settings] &gt; [Safari] &gt; [Content Blockers]

2. Turn following Content Blockers on/off.

 - TwitterHeaderBlocker
 - TwitterImageBlocker

3. Tap the following button to open Safari.</string>
<fontDescription key="fontDescription" name="AvenirNext-Regular" family="Avenir Next" pointSize="17"/>
<fontDescription key="fontDescription" name="AvenirNext-Regular" family="Avenir Next" pointSize="15"/>
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
<nil key="highlightedColor"/>
</label>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="RQ2-D1-9Kr">
<rect key="frame" x="36" y="312.5" width="528" height="60"/>
<rect key="frame" x="36" y="285" width="528" height="60"/>
<color key="backgroundColor" red="0.20000000300000001" green="0.60000002379999995" blue="0.80000001190000003" alpha="1" colorSpace="calibratedRGB"/>
<constraints>
<constraint firstAttribute="height" constant="60" id="sen-yT-Joy"/>
</constraints>
<fontDescription key="fontDescription" name="AvenirNext-Regular" family="Avenir Next" pointSize="15"/>
<fontDescription key="fontDescription" name="AvenirNext-Regular" family="Avenir Next" pointSize="17"/>
<state key="normal" title="Show Twitter in Safari">
<color key="titleColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
</state>
Expand Down
57 changes: 57 additions & 0 deletions iOS9Sampler/SampleViewControllers/LowPowerMode.storyboard
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] &gt; [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 iOS9Sampler/SampleViewControllers/LowPowerModeViewController.swift
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)"
}
}

0 comments on commit dda0c41

Please sign in to comment.