Skip to content

Commit 89cc402

Browse files
committed
README updates
1 parent 0ac843f commit 89cc402

File tree

1 file changed

+18
-17
lines changed

1 file changed

+18
-17
lines changed

README.md

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -407,57 +407,58 @@ print(me)
407407

408408
## Push notifications
409409

410-
Pusher also supports push notifications. Instances of your Swift application can register for push notifications and subscribe to "interests". Your server can then publish to those interests, which will be delivered to your Swift application as push notifications.
410+
Pusher also supports push notifications. Instances of your Swift application can register for push notifications and subscribe to "interests". Your server can then publish to those interests, which will be delivered to your Swift application as push notifications.
411411

412412
You should set up your app for push notifications in your `AppDelegate`. Start off your app in the usual way:
413413

414414
```swift
415415
import PusherSwift
416+
416417
@UIApplicationMain
417418
class AppDelegate: UIResponder, UIApplicationDelegate {
418419
let pusher = Pusher(key: "YOUR_APP_KEY")
420+
...
419421
```
420422

421423
For your Swift 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:
422424

423425
```swift
424-
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
425-
let notificationTypes : UIUserNotificationType = [UIUserNotificationType.Alert, UIUserNotificationType.Badge, UIUserNotificationType.Sound]
426-
let pushNotificationSettings = UIUserNotificationSettings(forTypes: notificationTypes, categories: nil)
427-
application.registerUserNotificationSettings(pushNotificationSettings)
428-
application.registerForRemoteNotifications()
426+
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject : AnyObject]?) -> Bool {
427+
let notificationTypes: UIUserNotificationType = [UIUserNotificationType.Alert, UIUserNotificationType.Badge, UIUserNotificationType.Sound]
428+
let pushNotificationSettings = UIUserNotificationSettings(forTypes: notificationTypes, categories: nil)
429+
application.registerUserNotificationSettings(pushNotificationSettings)
430+
application.registerForRemoteNotifications()
429431

430-
return true
431-
}
432+
return true
433+
}
432434
```
433435

434436
Next, APNs will respond with a device token identifying your app instance. Your app should then register with Pusher, passing along its device token.
435437

436438
Your app can now subscribe to interests. The following registers and subscribes the app to the interest "donuts":
437439

438440
```swift
439-
func application(application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken : NSData) {
440-
pusher.nativePush().register(deviceToken)
441-
pusher.nativePush().subscribe("donuts")
442-
}
441+
func application(application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: NSData) {
442+
pusher.nativePusher().register(deviceToken)
443+
pusher.nativePusher().subscribe("donuts")
444+
}
443445
```
444446

445447
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:
446448

447449
```swift
448-
func application(application : UIApplication, didReceiveRemoteNotification notification : [NSObject : AnyObject]) {
449-
print(notification)
450-
}
450+
func application(application: UIApplication, didReceiveRemoteNotification notification: [NSObject : AnyObject]) {
451+
print(notification)
451452
}
452453
```
453454

454455
If at a later point you wish to unsubscribe from an interest, this works in the same way:
455456

456457
```swift
457-
pusher.nativePush().unsubscribe("donuts")
458+
pusher.nativePusher().unsubscribe("donuts")
458459
```
459460

460-
For a complete example of a working app, see the `Example/` directory in this repository.
461+
For a complete example of a working app, see the [Example/](https://github.com/pusher/pusher-websocket-swift/tree/master/Example) directory in this repository. Specifically for push notifications code, see the [Example/AppDelegate.swift file](https://github.com/pusher/pusher-websocket-swift/blob/master/Example/AppDelegate.swift).
461462

462463

463464
## Testing

0 commit comments

Comments
 (0)