Skip to content

Commit ff0ee65

Browse files
authored
Merge pull request #90 from pusher/remove-tryflushoutbox
Remove tryFlushOutbox and replace with a TaskQueue
2 parents 5c5fdd5 + 9922af4 commit ff0ee65

File tree

8 files changed

+546
-83
lines changed

8 files changed

+546
-83
lines changed

PusherSwift/PusherSwift.xcodeproj/project.pbxproj

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
/* Begin PBXBuildFile section */
1010
330D7A6A1CAEDA6C0032FF2C /* PusherSwift.swift in Sources */ = {isa = PBXBuildFile; fileRef = 33831CD31A9CFFD900B124F1 /* PusherSwift.swift */; };
1111
330D7A6D1CAEDA750032FF2C /* PusherChannel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3384C1B81CAECD9C00F10796 /* PusherChannel.swift */; };
12+
33160A001D8FE15B002EC524 /* TaskQueue.swift in Sources */ = {isa = PBXBuildFile; fileRef = 331609FF1D8FE15B002EC524 /* TaskQueue.swift */; };
1213
3341A33A1D819FBC007191AD /* NativePusher.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3341A3391D819FBC007191AD /* NativePusher.swift */; };
1314
3342F3BD1D808AC900C0296E /* ClientEventTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3342F3BB1D808AC500C0296E /* ClientEventTests.swift */; };
1415
335BCA0D1C38ABF000B47A66 /* PusherSwift.h in Headers */ = {isa = PBXBuildFile; fileRef = 33831CD61A9CFFF200B124F1 /* PusherSwift.h */; settings = {ATTRIBUTES = (Public, ); }; };
@@ -20,6 +21,8 @@
2021
3389F57A1CAEDEC800563F49 /* PusherClientOptions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3389F5791CAEDEC800563F49 /* PusherClientOptions.swift */; };
2122
33A962741D88A9C900DA421E /* PusherConnectionDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 33A962731D88A9C800DA421E /* PusherConnectionDelegate.swift */; };
2223
33A962771D89483600DA421E /* PusherConnectionDelegateTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 33A962751D8943CA00DA421E /* PusherConnectionDelegateTests.swift */; };
24+
33BA541E1D90351B00CD853B /* NativePusherTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 33BA541D1D90351B00CD853B /* NativePusherTests.swift */; };
25+
33BA54201D9035BD00CD853B /* PusherDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 33BA541F1D9035BD00CD853B /* PusherDelegate.swift */; };
2326
33BB99731D21230100B25C2A /* AuthenticationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 33BB995D1D21226C00B25C2A /* AuthenticationTests.swift */; };
2427
33BB99751D21230100B25C2A /* Helpers.swift in Sources */ = {isa = PBXBuildFile; fileRef = 33BB995F1D21226C00B25C2A /* Helpers.swift */; };
2528
33BB99761D21230100B25C2A /* Mocks.swift in Sources */ = {isa = PBXBuildFile; fileRef = 33BB99601D21226C00B25C2A /* Mocks.swift */; };
@@ -47,6 +50,7 @@
4750
/* End PBXContainerItemProxy section */
4851

4952
/* Begin PBXFileReference section */
53+
331609FF1D8FE15B002EC524 /* TaskQueue.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TaskQueue.swift; sourceTree = "<group>"; };
5054
3341A3391D819FBC007191AD /* NativePusher.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NativePusher.swift; sourceTree = "<group>"; };
5155
3342F3BB1D808AC500C0296E /* ClientEventTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = ClientEventTests.swift; path = ../Tests/ClientEventTests.swift; sourceTree = "<group>"; };
5256
337C9EE01C38B708006CC757 /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = System/Library/Frameworks/UIKit.framework; sourceTree = SDKROOT; };
@@ -64,6 +68,8 @@
6468
3389F5791CAEDEC800563F49 /* PusherClientOptions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PusherClientOptions.swift; sourceTree = "<group>"; };
6569
33A962731D88A9C800DA421E /* PusherConnectionDelegate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PusherConnectionDelegate.swift; sourceTree = "<group>"; };
6670
33A962751D8943CA00DA421E /* PusherConnectionDelegateTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = PusherConnectionDelegateTests.swift; path = ../Tests/PusherConnectionDelegateTests.swift; sourceTree = "<group>"; };
71+
33BA541D1D90351B00CD853B /* NativePusherTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = NativePusherTests.swift; path = ../Tests/NativePusherTests.swift; sourceTree = "<group>"; };
72+
33BA541F1D9035BD00CD853B /* PusherDelegate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PusherDelegate.swift; sourceTree = "<group>"; };
6773
33BB995D1D21226C00B25C2A /* AuthenticationTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = AuthenticationTests.swift; path = ../Tests/AuthenticationTests.swift; sourceTree = "<group>"; };
6874
33BB995F1D21226C00B25C2A /* Helpers.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = Helpers.swift; path = ../Tests/Helpers.swift; sourceTree = "<group>"; };
6975
33BB99601D21226C00B25C2A /* Mocks.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = Mocks.swift; path = ../Tests/Mocks.swift; sourceTree = "<group>"; };
@@ -122,6 +128,7 @@
122128
children = (
123129
33831CD31A9CFFD900B124F1 /* PusherSwift.swift */,
124130
3389F5791CAEDEC800563F49 /* PusherClientOptions.swift */,
131+
33BA541F1D9035BD00CD853B /* PusherDelegate.swift */,
125132
3389F5651CAEDD5F00563F49 /* PusherConnection.swift */,
126133
33A962731D88A9C800DA421E /* PusherConnectionDelegate.swift */,
127134
3389F5691CAEDD9100563F49 /* PusherWebsocketDelegate.swift */,
@@ -161,6 +168,7 @@
161168
33A962751D8943CA00DA421E /* PusherConnectionDelegateTests.swift */,
162169
33BB99651D21226C00B25C2A /* PusherIncomingEventHandlingTests.swift */,
163170
33BB99661D21226C00B25C2A /* PusherTopLevelAPITests.swift */,
171+
33BA541D1D90351B00CD853B /* NativePusherTests.swift */,
164172
33BB99671D21226C00B25C2A /* Info.plist */,
165173
);
166174
name = Tests;
@@ -172,6 +180,7 @@
172180
33C0D2D41CB5C1F2003FE13E /* CryptoSwiftHMACModule.swift */,
173181
33C0D2DA1CB5C364003FE13E /* Starscream.swift */,
174182
33C0D2E31CB5C539003FE13E /* Reachability.swift */,
183+
331609FF1D8FE15B002EC524 /* TaskQueue.swift */,
175184
);
176185
name = Dependencies;
177186
sourceTree = "<group>";
@@ -320,12 +329,14 @@
320329
buildActionMask = 2147483647;
321330
files = (
322331
3389F5661CAEDD5F00563F49 /* PusherConnection.swift in Sources */,
332+
33BA54201D9035BD00CD853B /* PusherDelegate.swift in Sources */,
323333
3389F56A1CAEDD9100563F49 /* PusherWebsocketDelegate.swift in Sources */,
324334
330D7A6D1CAEDA750032FF2C /* PusherChannel.swift in Sources */,
325335
33A962741D88A9C900DA421E /* PusherConnectionDelegate.swift in Sources */,
326336
3389F5721CAEDDF300563F49 /* PusherChannels.swift in Sources */,
327337
3389F5761CAEDE2800563F49 /* PusherGlobalChannel.swift in Sources */,
328338
3389F57A1CAEDEC800563F49 /* PusherClientOptions.swift in Sources */,
339+
33160A001D8FE15B002EC524 /* TaskQueue.swift in Sources */,
329340
3389F56E1CAEDDD800563F49 /* PusherPresenceChannel.swift in Sources */,
330341
3341A33A1D819FBC007191AD /* NativePusher.swift in Sources */,
331342
33C0D2E41CB5C539003FE13E /* Reachability.swift in Sources */,
@@ -347,6 +358,7 @@
347358
33BB997B1D21230100B25C2A /* PusherIncomingEventHandlingTests.swift in Sources */,
348359
3342F3BD1D808AC900C0296E /* ClientEventTests.swift in Sources */,
349360
33BB99751D21230100B25C2A /* Helpers.swift in Sources */,
361+
33BA541E1D90351B00CD853B /* NativePusherTests.swift in Sources */,
350362
33BB99731D21230100B25C2A /* AuthenticationTests.swift in Sources */,
351363
33BB99781D21230100B25C2A /* PusherChannelTests.swift in Sources */,
352364
33BB99761D21230100B25C2A /* Mocks.swift in Sources */,

README.md

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ What else would you want? Head over to the example app [ViewController.swift](ht
2828
* [Receiving errors](#receiving-errors)
2929
* [Presence channel specifics](#presence-channel-specifics)
3030
* [Push notifications](#push-notifications)
31+
* [Pusher delegate](#pusher-delegate)
3132
* [Testing](#testing)
3233
* [Extensions](#extensions)
3334
* [Communication](#communication)
@@ -824,6 +825,54 @@ pusher.nativePusher().unsubscribe(interestName: "donuts")
824825
For a complete example of a working app, see the [Example/](https://github.com/pusher/pusher-websocket-swift/tree/push-notifications/Example) directory in this repository. Specifically for push notifications code, see the [Example/AppDelegate.swift](https://github.com/pusher/pusher-websocket-swift/blob/master/iOS%20Example%20Swift/iOS%20Example%20Swift/AppDelegate.swift) file.
825826
826827
828+
### Pusher delegate
829+
830+
There is a `PusherDelegate` that you can use to get access to events that occur in relation to push notifications interactions. These are the functions that you can optionally implement when conforming to the `PusherDelegate` protocol:
831+
832+
```swift
833+
@objc optional func didRegisterForPushNotifications(clientId: String)
834+
@objc optional func didSubscribeToInterest(named name: String)
835+
@objc optional func didUnsubscribeFromInterest(named name: String)
836+
```
837+
838+
Again, the names of the functions largely give away what their purpose is but just for completeness:
839+
840+
- `didRegisterForPushNotifications` - use this if you want to know when a client has successfully registered with the Pusher Push Notifications service, or if you want access to the `clientId` that is returned upon successful registration
841+
- `didSubscribeToInterest` - use this if you want keep track of interests that are successfully subscribed to
842+
- `didUnsubscribeFromInterest` - use this if you want keep track of interests that are successfully unsubscribed from
843+
844+
Setting up a delegate looks like this:
845+
846+
#### Swift
847+
```swift
848+
class ViewController: UIViewController, PusherDelegate {
849+
850+
override func viewDidLoad() {
851+
super.viewDidLoad()
852+
let pusher = Pusher(key: "APP_KEY")
853+
pusher.delegate = self
854+
// ...
855+
}
856+
}
857+
```
858+
859+
#### Objective-C
860+
```objc
861+
@implementation ViewController
862+
863+
- (void)viewDidLoad {
864+
[super viewDidLoad];
865+
866+
self.client = [[Pusher alloc] initWithAppKey:@"YOUR_APP_KEY"];
867+
868+
self.client.delegate = self;
869+
// ...
870+
}
871+
```
872+
873+
The process is identical to that of setting up a `PusherConnectionDelegate`. At some point in the future the `PusherDelegate` and `PusherConnectionDelegate` will likely be merged into the `PusherDelegate` in order to provide one unified delegate that can be used to get notified of Pusher-related events.
874+
875+
827876
## Testing
828877
829878
There are a set of tests for the library that can be run using the standard method (Command-U in Xcode).

0 commit comments

Comments
 (0)