Skip to content

Commit 9922af4

Browse files
committed
README updates in relation to PusherDelegate
1 parent 2f7f8c4 commit 9922af4

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

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)