Skip to content

Commit 1947969

Browse files
committed
Readme updates in light of NativePusher and delegate changes
1 parent f20b6f4 commit 1947969

File tree

1 file changed

+35
-35
lines changed

1 file changed

+35
-35
lines changed

README.md

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -300,27 +300,27 @@ pusher.connection.userDataFetcher = ^PusherPresenceChannelMember* () {
300300
301301
### Connection delegate
302302
303-
There is a `PusherConnectionDelegate` that you can use to get access to connection-related information. These are the functions that you can optionally implement when conforming to the `PusherConnectionDelegate` protocol:
303+
There is a `PusherDelegate` that you can use to get notified of connection-related information. These are the functions that you can optionally implement when conforming to the `PusherDelegate` protocol:
304304
305305
```swift
306-
@objc optional func connectionStateDidChange(from old: ConnectionState, to new: ConnectionState)
306+
@objc optional func changedConnectionState(from old: ConnectionState, to new: ConnectionState)
307+
@objc optional func subscribedToChannel(name: String)
308+
@objc optional func failedToSubscribeToChannel(name: String, response: URLResponse?, data: String?, error: NSError?)
307309
@objc optional func debugLog(message: String)
308-
@objc optional func subscriptionDidSucceed(channelName: String)
309-
@objc optional func subscriptionDidFail(channelName: String, response: URLResponse?, data: String?, error: NSError?)
310310
```
311311

312312
The names of the functions largely give away what their purpose is but just for completeness:
313313

314-
- `connectionStateDidChange` - use this if you want to use connection state changes to perform different actions / UI updates
314+
- `changedConnectionState` - use this if you want to use connection state changes to perform different actions / UI updates
315+
- `subscribedToChannel` - use this if you want to be informed of when a channel has successfully been subscribed to, which is useful if you want to perform actions that are only relevant after a subscription has succeeded, e.g. logging out the members of a presence channel
316+
- `failedToSubscribeToChannel` - use this if you want to be informed of a failed subscription attempt, which you could use, for exampple, to then attempt another subscription or make a call to a service you use to track errors
315317
- `debugLog` - use this if you want to log Pusher-related events, e.g. the underlying websocket receiving a message
316-
- `subscriptionDidSucceed` - use this if you want to be informed of when a channel has successfully been subscribed to, which is useful if you want to perform actions that are only relevant after a subscription has succeeded, e.g. logging out the members of a presence channel
317-
- `subscriptionDidFail` - use this if you want to be informed of a failed subscription attempt, which you could use, for exampple, to then attempt another subscription or make a call to a service you use to track errors
318318

319319
Setting up a delegate looks like this:
320320

321321
#### Swift
322322
```swift
323-
class ViewController: UIViewController, PusherConnectionDelegate {
323+
class ViewController: UIViewController, PusherDelegate {
324324

325325
override func viewDidLoad() {
326326
super.viewDidLoad()
@@ -349,51 +349,51 @@ Here are examples of setting up a class with functions for each of the optional
349349
350350
#### Swift
351351
```swift
352-
class DummyDelegate: PusherConnectionDelegate {
353-
func connectionStateDidChange(from old: ConnectionState, to new: ConnectionState) {
352+
class DummyDelegate: PusherDelegate {
353+
func changedConnectionState(from old: ConnectionState, to new: ConnectionState) {
354354
// ...
355355
}
356356
357357
func debugLog(message: String) {
358358
// ...
359359
}
360360
361-
func subscriptionDidSucceed(channelName: String) {
361+
func subscribedToChannel(name: String) {
362362
// ...
363363
}
364364
365-
func subscriptionDidFail(channelName: String, response: URLResponse?, data: String?, error: NSError?) {
365+
func failedToSubscribeToChannel(name: String, response: URLResponse?, data: String?, error: NSError?) {
366366
// ...
367367
}
368368
}
369369
```
370370

371371
#### Objective-C
372372
```objc
373-
@interface DummyDelegate : NSObject <PusherConnectionDelegate>
373+
@interface DummyDelegate : NSObject <PusherDelegate>
374374

375-
- (void)connectionStateDidChangeFrom:(enum ConnectionState)old to:(enum ConnectionState)new_
375+
- (void)changedConnectionState:(enum ConnectionState)old to:(enum ConnectionState)new_
376376
- (void)debugLogWithMessage:(NSString *)message
377-
- (void)subscriptionDidSucceedWithChannelName:(NSString *)channelName
378-
- (void)subscriptionDidFailWithChannelName:(NSString *)channelName response:(NSURLResponse *)response data:(NSString *)data error:(NSError *)error
377+
- (void)subscribedToChannelWithName:(NSString *)name
378+
- (void)failedToSubscribeToChannelWithName:(NSString *)name response:(NSURLResponse *)response data:(NSString *)data error:(NSError *)error
379379

380380
@end
381381

382382
@implementation DummyDelegate
383383

384-
- (void)connectionStateDidChangeFrom:(enum ConnectionState)old to:(enum ConnectionState)new_ {
384+
- (void)changedConnectionState:(enum ConnectionState)old to:(enum ConnectionState)new_ {
385385
// ...
386386
}
387387

388388
- (void)debugLogWithMessage:(NSString *)message {
389389
// ...
390390
}
391391

392-
- (void)subscriptionDidSucceedWithChannelName:(NSString *)channelName {
392+
- (void)subscribedToChannelWithName:(NSString *)name {
393393
// ...
394394
}
395395

396-
- (void)subscriptionDidFailWithChannelName:(NSString *)channelName response:(NSURLResponse *)response data:(NSString *)data error:(NSError *)error {
396+
- (void)failedToSubscribeToChannelWithName:(NSString *)name response:(NSURLResponse *)response data:(NSString *)data error:(NSError *)error {
397397
// ...
398398
}
399399

@@ -546,14 +546,14 @@ PusherPresenceChannel *chan = [pusher subscribeToPresenceChannelWithChannelName:
546546
}];
547547
```
548548
549-
You can also be notified of a successfull subscription by using the `subscriptionDidSucceed` delegate method on the `PusherConnection` object.
549+
You can also be notified of a successfull subscription by using the `subscriptionDidSucceed` delegate method that is part of the `PusherDelegate` protocol.
550550
551-
Here is an example of using the connection delegate:
551+
Here is an example of using the delegate:
552552
553553
#### Swift
554554
```swift
555-
class DummyDelegate: PusherConnectionDelegate {
556-
func subscriptionDidSucceed(channelName: String) {
555+
class DummyDelegate: PusherDelegate {
556+
func subscribedToChannel(name: String) {
557557
if channelName == "presence-channel" {
558558
if let presChan = pusher.connection.channels.findPresence(channelName) {
559559
// in here you can now have access to the channel's members and myId properties
@@ -573,7 +573,7 @@ let chan = pusher.subscribeToPresenceChannel("presence-channel")
573573
```objc
574574
@implementation DummyDelegate
575575

576-
- (void)subscriptionDidSucceedWithChannelName:(NSString *)channelName {
576+
- (void)subscribedToChannelWithName:(NSString *)name {
577577
if ([channelName isEqual: @"presence-channel"]) {
578578
PusherPresenceChannel *presChan = [self.client.connection.channels findPresenceWithName:@"presence-channel"];
579579
NSLog(@"%@", [presChan members]);
@@ -813,8 +813,8 @@ Your app can now subscribe to interests. The following registers and subscribes
813813
#### Swift
814814
```swift
815815
func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
816-
pusher.nativePusher().register(deviceToken: deviceToken)
817-
pusher.nativePusher().subscribe(interestName: "donuts")
816+
pusher.nativePusher.register(deviceToken: deviceToken)
817+
pusher.nativePusher.subscribe(interestName: "donuts")
818818
}
819819
```
820820

@@ -848,7 +848,7 @@ If at a later point you wish to unsubscribe from an interest, this works in the
848848

849849
#### Swift
850850
```swift
851-
pusher.nativePusher().unsubscribe(interestName: "donuts")
851+
pusher.nativePusher.unsubscribe(interestName: "donuts")
852852
```
853853

854854
#### Objective-C
@@ -861,19 +861,19 @@ For a complete example of a working app, see the [Example/](https://github.com/p
861861
862862
### Pusher delegate
863863
864-
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:
864+
You can also implement some of the `PusherDelegate` functions 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:
865865
866866
```swift
867-
@objc optional func didRegisterForPushNotifications(clientId: String)
868-
@objc optional func didSubscribeToInterest(named name: String)
869-
@objc optional func didUnsubscribeFromInterest(named name: String)
867+
@objc optional func registeredForPushNotifications(clientId: String)
868+
@objc optional func subscribedToInterest(name: String)
869+
@objc optional func unsubscribedFromInterest(name: String)
870870
```
871871

872872
Again, the names of the functions largely give away what their purpose is but just for completeness:
873873

874-
- `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
875-
- `didSubscribeToInterest` - use this if you want keep track of interests that are successfully subscribed to
876-
- `didUnsubscribeFromInterest` - use this if you want keep track of interests that are successfully unsubscribed from
874+
- `registeredForPushNotifications` - 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
875+
- `subscribedToInterest` - use this if you want keep track of interests that are successfully subscribed to
876+
- `unsubscribedFromInterest` - use this if you want keep track of interests that are successfully unsubscribed from
877877

878878
Setting up a delegate looks like this:
879879

@@ -904,7 +904,7 @@ class ViewController: UIViewController, PusherDelegate {
904904
}
905905
```
906906
907-
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.
907+
The process is identical to that of setting up the `PusherDelegate` to receive notifications of connection-based events.
908908
909909
910910
## Testing

0 commit comments

Comments
 (0)