Skip to content

Commit a25baca

Browse files
committed
Update example app to have reconnect and disconnect buttons
1 parent 91744c6 commit a25baca

File tree

3 files changed

+42
-9
lines changed

3 files changed

+42
-9
lines changed

Example/Main.storyboard

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
2-
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="7702" systemVersion="14D136" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="yEm-Wa-8Rj">
2+
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="10117" systemVersion="15F34" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="yEm-Wa-8Rj">
33
<dependencies>
4-
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="7701"/>
4+
<deployment identifier="iOS"/>
5+
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="10085"/>
56
</dependencies>
67
<scenes>
78
<!--View Controller-->
@@ -13,14 +14,39 @@
1314
<viewControllerLayoutGuide type="bottom" id="r12-OR-bkP"/>
1415
</layoutGuides>
1516
<view key="view" contentMode="scaleToFill" id="y96-ws-RaM">
16-
<rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
17+
<rect key="frame" x="0.0" y="0.0" width="320" height="568"/>
1718
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
19+
<subviews>
20+
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="pak-HB-Rmg">
21+
<rect key="frame" x="122" y="132" width="78" height="30"/>
22+
<state key="normal" title="Disconnect"/>
23+
<connections>
24+
<action selector="disconnectButton:" destination="yEm-Wa-8Rj" eventType="touchUpInside" id="DIg-Tc-6e2"/>
25+
</connections>
26+
</button>
27+
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="zrh-9X-Fym">
28+
<rect key="frame" x="122" y="38" width="78" height="30"/>
29+
<state key="normal" title="Connect"/>
30+
<connections>
31+
<action selector="connectButton:" destination="yEm-Wa-8Rj" eventType="touchUpInside" id="Hla-Ru-KoR"/>
32+
</connections>
33+
</button>
34+
</subviews>
1835
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
36+
<constraints>
37+
<constraint firstItem="pak-HB-Rmg" firstAttribute="width" secondItem="zrh-9X-Fym" secondAttribute="width" id="4lR-eK-ZIZ"/>
38+
<constraint firstItem="pak-HB-Rmg" firstAttribute="centerX" secondItem="y96-ws-RaM" secondAttribute="centerX" constant="1" id="55L-vA-Tvc"/>
39+
<constraint firstItem="zrh-9X-Fym" firstAttribute="centerX" secondItem="y96-ws-RaM" secondAttribute="centerX" constant="1" id="BgE-CD-tkr"/>
40+
<constraint firstItem="pak-HB-Rmg" firstAttribute="height" secondItem="zrh-9X-Fym" secondAttribute="height" id="VhG-sC-yO0"/>
41+
<constraint firstItem="pak-HB-Rmg" firstAttribute="top" secondItem="fji-4t-sKP" secondAttribute="bottom" constant="112" id="aX3-md-844"/>
42+
<constraint firstItem="zrh-9X-Fym" firstAttribute="top" secondItem="fji-4t-sKP" secondAttribute="bottom" constant="18" id="goe-io-Zww"/>
43+
</constraints>
1944
</view>
45+
<simulatedScreenMetrics key="simulatedDestinationMetrics" type="retina4"/>
2046
</viewController>
2147
<placeholder placeholderIdentifier="IBFirstResponder" id="weS-V8-jg5" userLabel="First Responder" sceneMemberID="firstResponder"/>
2248
</objects>
23-
<point key="canvasLocation" x="3746" y="98"/>
49+
<point key="canvasLocation" x="3745.5" y="97.5"/>
2450
</scene>
2551
</scenes>
2652
</document>

Example/ViewController.swift

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,15 @@ import UIKit
1010
import PusherSwift
1111

1212
class ViewController: UIViewController, ConnectionStateChangeDelegate {
13+
var pusher: Pusher! = nil
14+
15+
@IBAction func connectButton(sender: AnyObject) {
16+
pusher.connect()
17+
}
18+
19+
@IBAction func disconnectButton(sender: AnyObject) {
20+
pusher.disconnect()
21+
}
1322

1423
override func viewDidLoad() {
1524
super.viewDidLoad()
@@ -44,7 +53,7 @@ class ViewController: UIViewController, ConnectionStateChangeDelegate {
4453

4554
chan.bind("test-event", callback: { (data: AnyObject?) -> Void in
4655
print(data)
47-
pusher.subscribe("presence-channel", onMemberAdded: onMemberAdded)
56+
self.pusher.subscribe("presence-channel", onMemberAdded: onMemberAdded)
4857

4958
if let data = data as? [String : AnyObject] {
5059
if let testVal = data["test"] as? String {

Source/PusherConnection.swift

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,13 @@ public class PusherConnection {
3030
public lazy var reachability: Reachability? = {
3131
let reachability = try? Reachability.reachabilityForInternetConnection()
3232
reachability?.whenReachable = { [unowned self] reachability in
33-
self.debugLogger?("[PUSHER DEBUG] WE ARE REACHABLE AGAIN")
33+
self.debugLogger?("[PUSHER DEBUG] Network reachable")
3434
if self.connectionState == .Disconnected {
3535
self.attemptReconnect()
3636
}
3737
}
3838
reachability?.whenUnreachable = { [unowned self] reachability in
39-
print("Network unreachable")
39+
self.debugLogger?("[PUSHER DEBUG] Network unreachable")
4040
}
4141
return reachability
4242
}()
@@ -285,9 +285,7 @@ public class PusherConnection {
285285
self.reconnectTimer?.invalidate()
286286

287287
for (_, channel) in self.channels.channels {
288-
print("Here's my channel \(channel.name)")
289288
if !channel.subscribed {
290-
print("And we aren't subbed")
291289
if !self.authorize(channel) {
292290
print("Unable to subscribe to channel: \(channel.name)")
293291
}

0 commit comments

Comments
 (0)