PotLoc: Version 1.1, 2016-03-21

Adopt Swift 2.2 language changes.
This commit is contained in:
Liu Lantao 2016-05-15 18:44:06 +08:00
parent df4e0b9742
commit 5f1884e2ed
15 changed files with 160 additions and 137 deletions

View File

@ -1,5 +1,5 @@
/*
Copyright (C) 2015 Apple Inc. All Rights Reserved.
Copyright (C) 2016 Apple Inc. All Rights Reserved.
See LICENSE.txt for this samples licensing information
Abstract:

View File

@ -1,5 +1,5 @@
Sample code project: PotLoc: CoreLocation with iPhone and Apple Watch
Version: 1.0
Version: 1.1
IMPORTANT: This Apple software is supplied to you by Apple
Inc. ("Apple") in consideration of your agreement to the following
@ -39,4 +39,4 @@ AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE),
STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
Copyright (C) 2015 Apple Inc. All Rights Reserved.
Copyright (C) 2016 Apple Inc. All Rights Reserved.

View File

@ -1,8 +1,8 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder.WatchKit.Storyboard" version="3.0" toolsVersion="8121.17" systemVersion="15A178t" targetRuntime="watchKit" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="AgC-eL-Hgc">
<document type="com.apple.InterfaceBuilder.WatchKit.Storyboard" version="3.0" toolsVersion="8152.3" systemVersion="15A214" targetRuntime="watchKit" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="AgC-eL-Hgc">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="8101.14"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBWatchKitPlugin" version="8066.14"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="8124.4"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBWatchKitPlugin" version="8077.2"/>
</dependencies>
<scenes>
<!--Potloc-->
@ -43,7 +43,6 @@
<action selector="requestLocation:" destination="vKN-QW-QSX" id="Sub-nD-iv4"/>
</connections>
</button>
<timer alignment="left" id="qpm-Zg-mhf"/>
<separator alignment="left" id="vK1-9E-kfS"/>
<label alignment="left" text="Label" id="jpF-sQ-sjD"/>
<label alignment="left" text="Label" id="Xry-1x-JDh"/>
@ -51,7 +50,6 @@
<label alignment="left" text="Label" numberOfLines="0" id="WTm-mB-7Kd"/>
</items>
<connections>
<outlet property="displayTimer" destination="qpm-Zg-mhf" id="Xzb-eh-U9S"/>
<outlet property="errorLabel" destination="WTm-mB-7Kd" id="RXk-5s-CYR"/>
<outlet property="latitudeLabel" destination="jpF-sQ-sjD" id="IZU-CZ-aIh"/>
<outlet property="longitudeLabel" destination="Xry-1x-JDh" id="5TX-s5-9RD"/>

View File

@ -1,5 +1,5 @@
/*
Copyright (C) 2015 Apple Inc. All Rights Reserved.
Copyright (C) 2016 Apple Inc. All Rights Reserved.
See LICENSE.txt for this samples licensing information
Abstract:

View File

@ -1,5 +1,5 @@
/*
Copyright (C) 2015 Apple Inc. All Rights Reserved.
Copyright (C) 2016 Apple Inc. All Rights Reserved.
See LICENSE.txt for this samples licensing information
Abstract:

View File

@ -1,5 +1,5 @@
/*
Copyright (C) 2015 Apple Inc. All Rights Reserved.
Copyright (C) 2016 Apple Inc. All Rights Reserved.
See LICENSE.txt for this samples licensing information
*/
@ -20,12 +20,6 @@ import Foundation
*/
class RequestLocationInterfaceController: WKInterfaceController, CLLocationManagerDelegate {
// MARK: Properties
/**
When this timer times out, the labels in the interface reset to a default
state that does not resemble a requestLocation result.
*/
var interfaceResetTimer = NSTimer()
/// Location manager to request authorization and location updates.
let manager = CLLocationManager()
@ -36,9 +30,6 @@ class RequestLocationInterfaceController: WKInterfaceController, CLLocationManag
/// Button to request location. Also allows cancelling the location request.
@IBOutlet var requestLocationButton: WKInterfaceButton!
/// Timer to count down 5 seconds as a visual cue that the interface will reset.
@IBOutlet var displayTimer: WKInterfaceTimer!
/// Label to display the most recent location's latitude.
@IBOutlet var latitudeLabel: WKInterfaceLabel!
@ -70,29 +61,19 @@ class RequestLocationInterfaceController: WKInterfaceController, CLLocationManag
return NSLocalizedString("Unexpected authorization status.", comment: "Text to indicate authorization status is an unexpected value")
}
var latitudeResetText: String {
return NSLocalizedString("<latitude reset>", comment: "String indicating that no latitude is shown to the user due to a timer reset")
}
var longitudeResetText: String {
return NSLocalizedString("<longitude reset>", comment: "String indicating that no longitude is shown to the user due to a timer reset")
}
var errorResetText: String {
return NSLocalizedString("<no error>", comment: "String indicating that no error is shown to the user")
}
// MARK: Interface Controller
override func awakeWithContext(context: AnyObject?) {
super.awakeWithContext(context)
self.setTitle(interfaceTitle)
setTitle(interfaceTitle)
// Remember to set the location manager's delegate.
manager.delegate = self
resetInterface()
latitudeLabel.setAlpha(0)
longitudeLabel.setAlpha(0)
errorLabel.setAlpha(0)
}
/// MARK - Button Actions
@ -127,12 +108,14 @@ class RequestLocationInterfaceController: WKInterfaceController, CLLocationManag
manager.requestLocation()
case .Denied:
errorLabel.setAlpha(1)
errorLabel.setText(deniedText)
restartTimers()
simulateFadeOut(errorLabel)
default:
errorLabel.setAlpha(1)
errorLabel.setText(unexpectedText)
restartTimers()
simulateFadeOut(errorLabel)
}
}
@ -142,21 +125,27 @@ class RequestLocationInterfaceController: WKInterfaceController, CLLocationManag
When the location manager receives new locations, display the latitude and
longitude of the latest location and restart the timers.
*/
func locationManager(manager: CLLocationManager, didUpdateLocations locations: [AnyObject]) {
func locationManager(manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
guard !locations.isEmpty else { return }
dispatch_async(dispatch_get_main_queue()) {
let lastLocationCoordinate = locations.last!.coordinate!
let lastLocationCoordinate = locations.last!.coordinate
self.latitudeLabel.setText(String(lastLocationCoordinate.latitude))
self.longitudeLabel.setText(String(lastLocationCoordinate.longitude))
self.latitudeLabel.setAlpha(1)
self.longitudeLabel.setAlpha(1)
self.isRequestingLocation = false
self.requestLocationButton.setTitle(self.requestLocationTitle)
self.restartTimers()
self.simulateFadeOut(self.latitudeLabel)
self.simulateFadeOut(self.longitudeLabel)
}
}
@ -166,13 +155,15 @@ class RequestLocationInterfaceController: WKInterfaceController, CLLocationManag
*/
func locationManager(manager: CLLocationManager, didFailWithError error: NSError) {
dispatch_async(dispatch_get_main_queue()) {
self.errorLabel.setAlpha(1)
self.errorLabel.setText(String(error.localizedDescription))
self.isRequestingLocation = false
self.requestLocationButton.setTitle(self.requestLocationTitle)
self.restartTimers()
self.simulateFadeOut(self.errorLabel)
}
}
@ -189,16 +180,18 @@ class RequestLocationInterfaceController: WKInterfaceController, CLLocationManag
manager.requestLocation()
case .Denied:
self.errorLabel.setAlpha(1)
self.errorLabel.setText(self.deniedText)
self.isRequestingLocation = false
self.requestLocationButton.setTitle(self.requestLocationTitle)
self.restartTimers()
self.simulateFadeOut(self.errorLabel)
default:
self.errorLabel.setAlpha(1)
self.errorLabel.setText(self.unexpectedText)
self.isRequestingLocation = false
self.requestLocationButton.setTitle(self.requestLocationTitle)
self.restartTimers()
self.simulateFadeOut(self.errorLabel)
}
}
}
@ -206,46 +199,20 @@ class RequestLocationInterfaceController: WKInterfaceController, CLLocationManag
/// MARK - Resetting
/**
Resets the text labels in the interface to empty labels.
This method is useful for cleaning the interface to ensure that data
displayed to the user is not stale.
Simulates fading out animation by setting the alpha of the given label to
progressively smaller numbers.
*/
func resetInterface() {
dispatch_async(dispatch_get_main_queue()) {
self.stopDisplayTimer()
func simulateFadeOut(label: WKInterfaceLabel) {
let mainQueue = dispatch_get_main_queue()
for index in 1...10 {
let time = dispatch_time(DISPATCH_TIME_NOW, Int64(Double(index) / 10.0 * Double(NSEC_PER_SEC)))
self.latitudeLabel.setText(self.latitudeResetText)
self.longitudeLabel.setText(self.longitudeResetText)
self.errorLabel.setText(self.errorResetText)
dispatch_after(time, mainQueue) {
let alphaAmount = CGFloat(1 - (0.1 * Float(index)))
label.setAlpha(alphaAmount)
}
}
}
/**
Restarts the NSTimer and the WKInterface timer by stopping / invalidating
them, then starting them with a 5 second timeout.
*/
func restartTimers() {
stopDisplayTimer()
interfaceResetTimer.invalidate()
interfaceResetTimer = NSTimer.scheduledTimerWithTimeInterval(5, target: self, selector: "resetInterface", userInfo: [:], repeats: false)
let fiveSecondDelay = NSDate(timeIntervalSinceNow: 5)
displayTimer.setDate(fiveSecondDelay)
displayTimer.start()
}
/// Stops the display timer.
func stopDisplayTimer() {
let now = NSDate()
displayTimer.setDate(now)
displayTimer.stop()
}
}

View File

@ -1,5 +1,5 @@
/*
Copyright (C) 2015 Apple Inc. All Rights Reserved.
Copyright (C) 2016 Apple Inc. All Rights Reserved.
See LICENSE.txt for this samples licensing information
*/
@ -83,7 +83,7 @@ class StreamLocationInterfaceController: WKInterfaceController, WCSessionDelegat
override func awakeWithContext(context: AnyObject?) {
super.awakeWithContext(context)
self.setTitle(interfaceTitle)
setTitle(interfaceTitle)
locationsReeivedOnPhoneCountTitleLabel.setText(locationsReceivedText)
// Initialize the `WCSession`.

View File

@ -494,12 +494,14 @@
isa = XCBuildConfiguration;
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_IDENTITY = "iPhone Developer";
"CODE_SIGN_IDENTITY[sdk=watchos*]" = "iPhone Developer";
EMBEDDED_CONTENT_CONTAINS_SWIFT = YES;
IBSC_MODULE = Potloc_WatchKit_Extension;
INFOPLIST_FILE = "Potloc WatchKit App/Info.plist";
PRODUCT_BUNDLE_IDENTIFIER = "com.example.apple-samplecode.Potloc.nativewatchkitapp";
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE = "";
SDKROOT = watchos;
SKIP_INSTALL = YES;
TARGETED_DEVICE_FAMILY = 4;
@ -511,12 +513,14 @@
isa = XCBuildConfiguration;
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_IDENTITY = "iPhone Developer";
"CODE_SIGN_IDENTITY[sdk=watchos*]" = "iPhone Developer";
EMBEDDED_CONTENT_CONTAINS_SWIFT = YES;
IBSC_MODULE = Potloc_WatchKit_Extension;
INFOPLIST_FILE = "Potloc WatchKit App/Info.plist";
PRODUCT_BUNDLE_IDENTIFIER = "com.example.apple-samplecode.Potloc.nativewatchkitapp";
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE = "";
SDKROOT = watchos;
SKIP_INSTALL = YES;
TARGETED_DEVICE_FAMILY = 4;
@ -528,6 +532,7 @@
isa = XCBuildConfiguration;
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_IDENTITY = "iPhone Developer";
INFOPLIST_FILE = Potloc/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "com.example.apple-samplecode.Potloc";
@ -539,6 +544,7 @@
isa = XCBuildConfiguration;
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_IDENTITY = "iPhone Developer";
INFOPLIST_FILE = Potloc/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "com.example.apple-samplecode.Potloc";

View File

@ -1,5 +1,5 @@
/*
Copyright (C) 2015 Apple Inc. All Rights Reserved.
Copyright (C) 2016 Apple Inc. All Rights Reserved.
See LICENSE.txt for this samples licensing information
Abstract:

View File

@ -71,6 +71,12 @@
"idiom" : "ipad",
"filename" : "Potloc76x2.png",
"scale" : "2x"
},
{
"size" : "83.5x83.5",
"idiom" : "ipad",
"filename" : "Potloc83.5x2.png",
"scale" : "2x"
}
],
"info" : {

Binary file not shown.

After

Width:  |  Height:  |  Size: 19 KiB

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="8121.17" systemVersion="15A177" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" useTraitCollections="YES" initialViewController="01J-lp-oVM">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="8121.20" systemVersion="15A210a" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" useTraitCollections="YES" initialViewController="01J-lp-oVM">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="8101.13"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="8101.16"/>
</dependencies>
<scenes>
<!--View Controller-->

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="8121.17" systemVersion="15A178r" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="BYZ-38-t0r">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="8121.20" systemVersion="15A214" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="BYZ-38-t0r">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="8101.14"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="8101.16"/>
<capability name="Constraints to layout margins" minToolsVersion="6.0"/>
</dependencies>
<scenes>
@ -18,74 +18,107 @@
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Location manager not updating locations" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="eQd-yF-GPh">
<rect key="frame" x="20" y="40" width="560" height="20.5"/>
<rect key="frame" x="20" y="40" width="560" height="21"/>
<animations/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<color key="textColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="calibratedRGB"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Location batch size:" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="Br9-eS-VMs">
<rect key="frame" x="20" y="68.5" width="470" height="20.5"/>
<animations/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<color key="textColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="calibratedRGB"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="0" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="eRy-84-XZk">
<rect key="frame" x="490" y="68.5" width="90" height="20.5"/>
<animations/>
<constraints>
<constraint firstAttribute="width" constant="90" id="Muu-Ew-vid"/>
</constraints>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<color key="textColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="calibratedRGB"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="0" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="1Hf-4J-5Qk">
<rect key="frame" x="490" y="97" width="90" height="20.5"/>
<animations/>
<constraints>
<constraint firstAttribute="width" constant="90" id="32b-IX-obI"/>
</constraints>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<color key="textColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="calibratedRGB"/>
<color key="textColor" red="0.95911175270000004" green="0.95911175270000004" blue="0.95911175270000004" alpha="1" colorSpace="calibratedRGB"/>
<nil key="highlightedColor"/>
</label>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="foq-1x-DAR">
<rect key="frame" x="20" y="285" width="560" height="30"/>
<rect key="frame" x="20" y="275" width="560" height="50"/>
<animations/>
<state key="normal" title="Start updating location"/>
<color key="backgroundColor" red="0.10196078431372549" green="0.10196078431372549" blue="0.10196078431372549" alpha="1" colorSpace="calibratedRGB"/>
<constraints>
<constraint firstAttribute="height" constant="50" id="bQ6-hu-q00"/>
</constraints>
<state key="normal" title="Start updating location">
<color key="titleColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
</state>
<userDefinedRuntimeAttributes>
<userDefinedRuntimeAttribute type="number" keyPath="layer.cornerRadius">
<integer key="value" value="4"/>
</userDefinedRuntimeAttribute>
</userDefinedRuntimeAttributes>
<connections>
<action selector="startStopUpdatingLocation:" destination="BYZ-38-t0r" eventType="touchUpInside" id="NTM-oh-TLP"/>
</connections>
</button>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Total locations received:" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="tqL-ZZ-qXM">
<rect key="frame" x="20" y="97" width="470" height="20.5"/>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Locations received since last context update" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="Br9-eS-VMs">
<rect key="frame" x="20" y="139" width="560" height="21"/>
<animations/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<color key="textColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="calibratedRGB"/>
<color key="textColor" red="0.95911175270000004" green="0.95911175270000004" blue="0.95911175270000004" alpha="1" colorSpace="calibratedRGB"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="0" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="1Hf-4J-5Qk">
<rect key="frame" x="20" y="187" width="560" height="43"/>
<animations/>
<constraints>
<constraint firstAttribute="width" constant="90" id="32b-IX-obI"/>
</constraints>
<fontDescription key="fontDescription" type="system" pointSize="36"/>
<color key="textColor" red="0.95911175270000004" green="0.95911175270000004" blue="0.95911175270000004" alpha="1" colorSpace="calibratedRGB"/>
<nil key="highlightedColor"/>
<variation key="default">
<mask key="constraints">
<exclude reference="32b-IX-obI"/>
</mask>
</variation>
</label>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Total locations received" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="tqL-ZZ-qXM">
<rect key="frame" x="20" y="238" width="560" height="21"/>
<animations/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<color key="textColor" red="0.95911175270000004" green="0.95911175270000004" blue="0.95911175270000004" alpha="1" colorSpace="calibratedRGB"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="0" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="eRy-84-XZk">
<rect key="frame" x="20" y="88" width="560" height="43"/>
<animations/>
<constraints>
<constraint firstAttribute="width" constant="90" id="Muu-Ew-vid"/>
</constraints>
<fontDescription key="fontDescription" type="system" pointSize="36"/>
<color key="textColor" red="0.95911175270000004" green="0.95911175270000004" blue="0.95911175270000004" alpha="1" colorSpace="calibratedRGB"/>
<nil key="highlightedColor"/>
<variation key="default">
<mask key="constraints">
<exclude reference="Muu-Ew-vid"/>
</mask>
</variation>
</label>
</subviews>
<animations/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
<color key="backgroundColor" white="0.0" alpha="1" colorSpace="calibratedWhite"/>
<constraints>
<constraint firstAttribute="trailingMargin" secondItem="eRy-84-XZk" secondAttribute="trailing" id="1iL-Ce-egP"/>
<constraint firstAttribute="trailingMargin" secondItem="1Hf-4J-5Qk" secondAttribute="trailing" id="2Jr-u9-Rux"/>
<constraint firstItem="1Hf-4J-5Qk" firstAttribute="leading" secondItem="8bC-Xf-vdC" secondAttribute="leadingMargin" id="3LE-6C-jm2"/>
<constraint firstAttribute="trailingMargin" secondItem="Br9-eS-VMs" secondAttribute="trailing" id="3jW-OV-qd1"/>
<constraint firstItem="eQd-yF-GPh" firstAttribute="centerX" secondItem="8bC-Xf-vdC" secondAttribute="centerX" id="4na-Sv-FqO"/>
<constraint firstAttribute="trailingMargin" secondItem="tqL-ZZ-qXM" secondAttribute="trailing" id="5Vv-fR-HMQ"/>
<constraint firstItem="eRy-84-XZk" firstAttribute="top" secondItem="Br9-eS-VMs" secondAttribute="bottom" constant="8" id="7At-mw-kwV"/>
<constraint firstItem="eQd-yF-GPh" firstAttribute="top" secondItem="y3c-jy-aDJ" secondAttribute="bottom" constant="20" id="ANL-sR-6WH"/>
<constraint firstItem="eRy-84-XZk" firstAttribute="trailing" secondItem="8bC-Xf-vdC" secondAttribute="trailingMargin" id="ATi-yi-UaL"/>
<constraint firstItem="Br9-eS-VMs" firstAttribute="leading" secondItem="8bC-Xf-vdC" secondAttribute="leadingMargin" id="AZG-4j-IAW"/>
<constraint firstAttribute="trailingMargin" secondItem="eQd-yF-GPh" secondAttribute="trailing" id="EWS-PS-LVu"/>
<constraint firstItem="eRy-84-XZk" firstAttribute="top" secondItem="eQd-yF-GPh" secondAttribute="bottom" constant="27" id="Gxk-mz-OAc"/>
<constraint firstItem="1Hf-4J-5Qk" firstAttribute="top" secondItem="eRy-84-XZk" secondAttribute="bottom" constant="8" id="KY2-Zx-0Vk"/>
<constraint firstItem="tqL-ZZ-qXM" firstAttribute="leading" secondItem="8bC-Xf-vdC" secondAttribute="leadingMargin" id="LVY-hx-QcH"/>
<constraint firstItem="foq-1x-DAR" firstAttribute="centerX" secondItem="8bC-Xf-vdC" secondAttribute="centerX" id="M1K-7n-hkj"/>
<constraint firstItem="1Hf-4J-5Qk" firstAttribute="top" secondItem="Br9-eS-VMs" secondAttribute="bottom" constant="27" id="Rhx-nc-beL"/>
<constraint firstItem="tqL-ZZ-qXM" firstAttribute="top" secondItem="1Hf-4J-5Qk" secondAttribute="bottom" constant="8" id="TSO-kd-kLN"/>
<constraint firstAttribute="trailingMargin" secondItem="1Hf-4J-5Qk" secondAttribute="trailing" id="ZTq-TT-mhz"/>
<constraint firstItem="Br9-eS-VMs" firstAttribute="top" secondItem="eQd-yF-GPh" secondAttribute="bottom" constant="8" id="a7R-S9-Zty"/>
<constraint firstItem="eQd-yF-GPh" firstAttribute="centerY" secondItem="8bC-Xf-vdC" secondAttribute="centerY" id="eNu-qy-qNe"/>
<constraint firstItem="eRy-84-XZk" firstAttribute="leading" secondItem="8bC-Xf-vdC" secondAttribute="leadingMargin" id="ebc-8s-bEQ"/>
<constraint firstItem="Br9-eS-VMs" firstAttribute="top" secondItem="eRy-84-XZk" secondAttribute="bottom" constant="8" id="foY-yd-57n"/>
<constraint firstAttribute="trailingMargin" secondItem="foq-1x-DAR" secondAttribute="trailing" id="hYc-6e-hmC"/>
<constraint firstAttribute="trailingMargin" secondItem="eRy-84-XZk" secondAttribute="trailing" id="kmX-EK-53g"/>
<constraint firstItem="tqL-ZZ-qXM" firstAttribute="top" secondItem="Br9-eS-VMs" secondAttribute="bottom" constant="8" id="kql-1b-xTH"/>
<constraint firstItem="eRy-84-XZk" firstAttribute="leading" secondItem="8bC-Xf-vdC" secondAttribute="leadingMargin" id="nWc-nU-3Nr"/>
<constraint firstItem="foq-1x-DAR" firstAttribute="centerY" secondItem="8bC-Xf-vdC" secondAttribute="centerY" id="oxC-7I-3Rb"/>
<constraint firstItem="tqL-ZZ-qXM" firstAttribute="leading" secondItem="8bC-Xf-vdC" secondAttribute="leadingMargin" id="rj9-Na-pmv"/>
<constraint firstItem="eRy-84-XZk" firstAttribute="leading" secondItem="Br9-eS-VMs" secondAttribute="trailing" id="sDK-Qn-dyC"/>
<constraint firstItem="eRy-84-XZk" firstAttribute="top" secondItem="eQd-yF-GPh" secondAttribute="bottom" constant="8" id="tY1-fx-NfY"/>
<constraint firstAttribute="trailingMargin" secondItem="Br9-eS-VMs" secondAttribute="trailing" id="w2S-NS-vDJ"/>
@ -98,10 +131,20 @@
<mask key="constraints">
<exclude reference="4na-Sv-FqO"/>
<exclude reference="eNu-qy-qNe"/>
<exclude reference="w2S-NS-vDJ"/>
<exclude reference="1iL-Ce-egP"/>
<exclude reference="7At-mw-kwV"/>
<exclude reference="ATi-yi-UaL"/>
<exclude reference="nWc-nU-3Nr"/>
<exclude reference="sDK-Qn-dyC"/>
<exclude reference="tY1-fx-NfY"/>
<exclude reference="a7R-S9-Zty"/>
<exclude reference="w2S-NS-vDJ"/>
<exclude reference="zSB-IY-JOh"/>
<exclude reference="KY2-Zx-0Vk"/>
<exclude reference="ZTq-TT-mhz"/>
<exclude reference="ywp-n9-6M3"/>
<exclude reference="LVY-hx-QcH"/>
<exclude reference="kql-1b-xTH"/>
</mask>
</variation>
</view>

View File

@ -1,5 +1,5 @@
/*
Copyright (C) 2015 Apple Inc. All Rights Reserved.
Copyright (C) 2016 Apple Inc. All Rights Reserved.
See LICENSE.txt for this samples licensing information
Abstract:
@ -90,16 +90,16 @@ class PotlocViewController: UIViewController, WCSessionDelegate, CLLocationManag
}
var locationBatchSizeTitleText: String {
return NSLocalizedString("Location batch size:", comment: "Informs the user how many locations have been received since last batch push to the watch")
return NSLocalizedString("Locations received since last context update", comment: "Informs the user how many locations have been received since last batch push to the watch")
}
var receivedLocationCountTitleText: String {
return NSLocalizedString("Total locations received:", comment: "Informs the user how many locations have been received since starting the app")
return NSLocalizedString("Total locations received", comment: "Informs the user how many locations have been received since starting the app")
}
// MARK: Initialization
required init(coder aDecoder: NSCoder) {
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
commonInit()
@ -163,7 +163,8 @@ class PotlocViewController: UIViewController, WCSessionDelegate, CLLocationManag
do {
try session.updateApplicationContext([
MessageKey.StateUpdate.rawValue: isUpdatingLocation
MessageKey.StateUpdate.rawValue: isUpdatingLocation,
MessageKey.LocationCount.rawValue: String(receivedLocationCount)
])
}
catch let error as NSError {
@ -175,7 +176,7 @@ class PotlocViewController: UIViewController, WCSessionDelegate, CLLocationManag
manager.startUpdatingLocation()
sessionMessageTimer = NSTimer.scheduledTimerWithTimeInterval(5, target: self, selector: "sendLocationCount", userInfo: nil, repeats: true)
sessionMessageTimer = NSTimer.scheduledTimerWithTimeInterval(5, target: self, selector: #selector(PotlocViewController.sendLocationCount), userInfo: nil, repeats: true)
managerStatusLabel.text = updatingLocationText
@ -198,7 +199,8 @@ class PotlocViewController: UIViewController, WCSessionDelegate, CLLocationManag
if commandedFromPhone {
do {
try session.updateApplicationContext([
MessageKey.StateUpdate.rawValue: isUpdatingLocation
MessageKey.StateUpdate.rawValue: isUpdatingLocation,
MessageKey.LocationCount.rawValue: String(receivedLocationCount)
])
}
catch let error as NSError {
@ -278,8 +280,9 @@ class PotlocViewController: UIViewController, WCSessionDelegate, CLLocationManag
*/
func sendLocationCount() {
do {
try self.session.updateApplicationContext([
MessageKey.LocationCount.rawValue: String(self.receivedLocationCount)
try session.updateApplicationContext([
MessageKey.StateUpdate.rawValue: isUpdatingLocation,
MessageKey.LocationCount.rawValue: String(receivedLocationCount)
])
locationBatchCount = 0
@ -295,7 +298,7 @@ class PotlocViewController: UIViewController, WCSessionDelegate, CLLocationManag
Increases that location count by the number of locations received by the
manager. Updates the batch count with the added locations.
*/
func locationManager(manager: CLLocationManager, didUpdateLocations locations: [AnyObject]) {
func locationManager(manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
receivedLocationCount = receivedLocationCount + locations.count
locationBatchCount = locationBatchCount + locations.count

View File

@ -6,7 +6,7 @@ This sample demonstrates what you can do with CoreLocation, Apple Watch, and iPh
1.0
## Build Requirements
+ Xcode 7.0 or later
+ Xcode 7.3 or later
+ iOS 9.0 SDK or later
+ Watch OS 2.0 SDK or later
+ Valid provisioning profile
@ -24,4 +24,4 @@ Potloc demonstrates how to:
+ Start and stop updating location on iPhone using the WatchConnectivity framework
+ Start location updates on iPhone from Apple Watch while iPhone's app is in the background
Copyright (C) 2015 Apple Inc. All rights reserved.
Copyright (C) 2016 Apple Inc. All rights reserved.