Skip to content

Commit

Permalink
Adds user identifier usage to demo app
Browse files Browse the repository at this point in the history
  • Loading branch information
César Pinto Castillo committed Dec 3, 2016
1 parent 43f2bae commit 6d5e653
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 4 deletions.
1 change: 1 addition & 0 deletions CloudKitCurrentUser/CurrentUser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ public class CurrentUser {
isLoadingUserIdentifier = true
CKContainer.default().fetchUserRecordID { recordID, error in
self.userIdentifier = recordID?.recordName
self.isLoadingUserIdentifier = false
for completionBlock in self.userIdentifierCompletionBlocks {
DispatchQueue.main.async {
completionBlock(self.userIdentifier, error)
Expand Down
19 changes: 15 additions & 4 deletions Demo/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
<adaptation id="fullscreen"/>
</device>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="11524"/>
<capability name="Constraints to layout margins" minToolsVersion="6.0"/>
<capability name="Constraints with non-1.0 multipliers" minToolsVersion="5.1"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
Expand All @@ -23,11 +23,11 @@
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="u8I-ip-LCC">
<rect key="frame" x="0.0" y="436" width="320" height="44"/>
<rect key="frame" x="0.0" y="436" width="160" height="44"/>
<constraints>
<constraint firstAttribute="height" constant="44" id="y2E-3N-kZc"/>
</constraints>
<state key="normal" title="Force reload of user status"/>
<state key="normal" title="User Status"/>
<connections>
<action selector="forceReloadUserStatus" destination="BYZ-38-t0r" eventType="touchUpInside" id="1S7-Yi-Snk"/>
</connections>
Expand All @@ -42,16 +42,27 @@
<userDefinedRuntimeAttribute type="string" keyPath="text" value=""/>
</userDefinedRuntimeAttributes>
</textView>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="rBe-OC-DX5">
<rect key="frame" x="160" y="436" width="160" height="44"/>
<state key="normal" title="User Identifier"/>
<connections>
<action selector="logUserIdentifier" destination="BYZ-38-t0r" eventType="touchUpInside" id="SAL-D5-VN2"/>
</connections>
</button>
</subviews>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<constraints>
<constraint firstItem="qIt-X5-3N0" firstAttribute="leading" secondItem="8bC-Xf-vdC" secondAttribute="leading" id="4Lv-dZ-BYd"/>
<constraint firstAttribute="trailing" secondItem="qIt-X5-3N0" secondAttribute="trailing" id="IPI-WO-s0v"/>
<constraint firstAttribute="trailing" secondItem="rBe-OC-DX5" secondAttribute="trailing" id="LkL-Ia-cy2"/>
<constraint firstItem="u8I-ip-LCC" firstAttribute="leading" secondItem="8bC-Xf-vdC" secondAttribute="leading" id="Vbe-Qs-QUr"/>
<constraint firstAttribute="trailing" secondItem="u8I-ip-LCC" secondAttribute="trailing" id="Wjo-ZE-Gv2"/>
<constraint firstItem="wfy-db-euE" firstAttribute="top" secondItem="rBe-OC-DX5" secondAttribute="bottom" id="cYl-L6-2Ff"/>
<constraint firstItem="u8I-ip-LCC" firstAttribute="width" secondItem="8bC-Xf-vdC" secondAttribute="width" multiplier="0.5" id="dty-Pv-hBC"/>
<constraint firstItem="rBe-OC-DX5" firstAttribute="top" secondItem="qIt-X5-3N0" secondAttribute="bottom" id="ev8-qT-ulj"/>
<constraint firstItem="u8I-ip-LCC" firstAttribute="top" secondItem="qIt-X5-3N0" secondAttribute="bottom" id="n7h-1Z-3tP"/>
<constraint firstItem="wfy-db-euE" firstAttribute="top" secondItem="u8I-ip-LCC" secondAttribute="bottom" id="oN3-o4-F84"/>
<constraint firstAttribute="topMargin" secondItem="qIt-X5-3N0" secondAttribute="top" id="wQh-Rv-eTl"/>
<constraint firstItem="rBe-OC-DX5" firstAttribute="leading" secondItem="u8I-ip-LCC" secondAttribute="trailing" id="yYb-hQ-TQo"/>
</constraints>
</view>
<connections>
Expand Down
11 changes: 11 additions & 0 deletions Demo/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,17 @@ class ViewController: UIViewController {
}
}

@IBAction func logUserIdentifier() {
logStatusChange(string: "Log user identifier")
CurrentUser.sharedInstance.userIdentifier { userIdentifier, error in
if let userIdentifier = userIdentifier {
self.logStatusChange(string: "User identifier: \(userIdentifier)")
} else {
self.logStatusChange(string: "Unable to get user identifier")
}
}
}

@objc private func getUserStatus() {
CurrentUser.sharedInstance.currentStatus { status in
self.logStatusChange(status: status)
Expand Down

0 comments on commit 6d5e653

Please sign in to comment.