You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Supports iOS, macOS (OS X) and tvOS! (Hopefully watchOS soon!)
12
+
11
13
12
14
## I just want to copy and paste some code to get me started
13
15
14
-
What else would you want? Head over to the example app [ViewController.swift](https://github.com/pusher/pusher-websocket-swift/blob/master/iOS%20Example%20Swift/iOS%20Example%20Swift/ViewController.swift) to get some code you can drop in to get started. Or if you're using Objective-C, check out [ViewController.m](https://github.com/pusher/pusher-websocket-swift/blob/master/iOS%20Example%20Obj-C/iOS%20Example%20Obj-C/ViewController.m).
16
+
What else would you want? Head over to one of our example apps:
17
+
18
+
* For iOS with Swift, see [ViewController.swift](https://github.com/pusher/pusher-websocket-swift/blob/master/iOS%20Example%20Swift/iOS%20Example%20Swift/ViewController.swift)
19
+
* For iOS with Objective-C, see [ViewController.m](https://github.com/pusher/pusher-websocket-swift/blob/master/iOS%20Example%20Obj-C/iOS%20Example%20Obj-C/ViewController.m)
20
+
* For macOS with Swift, see [ViewController.swift](https://github.com/pusher/pusher-websocket-swift/blob/master/macOS%20Example%20Swift/macOS%20Example%20Swift/ViewController.swift)
15
21
16
22
17
23
## Table of Contents
@@ -748,11 +754,13 @@ You can unbind from events at both the global and per channel level. For both ob
748
754
749
755
## Push notifications
750
756
751
-
Pusher also supports push notifications. Instances of your application can register for push notifications and subscribe to "interests". Your server can then publish to those interests, which will be delivered to your application as push notifications. See [our guide to setting up push notifications for iOS](https://pusher.com/docs/push_notifications/ios) for a friendly introduction.
757
+
Pusher also supports push notifications. Instances of your application can register for push notifications and subscribe to "interests". Your server can then publish to those interests, which will be delivered to your application as push notifications. See [our guide to setting up APNs push notifications](https://pusher.com/docs/push_notifications/ios) for a friendly introduction.
752
758
753
-
You should set up your app for push notifications in your `AppDelegate`. Start off your app in the usual way:
759
+
### Initializing the Pusher object
754
760
755
-
#### Swift
761
+
You should set up your app for push notifications in your `AppDelegate`. The setup varies slightly depending on whether you're using Swift or Objective-C, and whether you're using iOS or macOS (OS X):
762
+
763
+
#### Swift on iOS
756
764
```swift
757
765
import PusherSwift
758
766
import UserNotifications
@@ -763,7 +771,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
763
771
...
764
772
```
765
773
766
-
#### Objective-C
774
+
#### Objective-C on iOS
767
775
```objc
768
776
#import"AppDelegate.h"
769
777
@import UserNotifications;
@@ -776,9 +784,23 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
776
784
...
777
785
```
778
786
787
+
#### Swift on macOS
788
+
789
+
```swift
790
+
import Cocoa
791
+
import PusherSwift
792
+
793
+
@NSApplicationMain
794
+
class AppDelegate: NSObject, NSApplicationDelegate, PusherDelegate {
795
+
let pusher = Pusher(key: "YOUR_APP_KEY")
796
+
// ...
797
+
```
798
+
799
+
### Registering with APNs
800
+
779
801
For your app to receive push notifications, it must first register with APNs. You should do this when the application finishes launching. Your app should register for all types of notification, like so:
When your server publishes a notification to the interest "donuts", it will get passed to your app. This happens as a call in your `AppDelegate` which you should listen to:
0 commit comments