Skip to content
This repository was archived by the owner on Aug 10, 2026. It is now read-only.

Commit 030675b

Browse files
maratalclaude
andcommitted
fix(push-guides): update APNs guide UI and logic to match other guides
- Show device ID after activation instead of APNs device token - Add subscribeToRealtime method and call it on launch - Remove getDeviceDetails method and button - Simplify ChannelSection to single channel, remove picker - Match button titles and colors (purple subscribe, orange unsubscribe) - Add location push screenshot Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 63cf7cc commit 030675b

3 files changed

Lines changed: 37 additions & 87 deletions

File tree

67.9 KB
Loading
-12.6 KB
Loading

src/pages/docs/push/getting-started/apns.mdx

Lines changed: 37 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,9 @@ class AppDelegate: NSObject, UIApplicationDelegate, ARTPushRegistererDelegate, U
116116
locationManager.delegate = self
117117
locationManager.desiredAccuracy = kCLLocationAccuracyBest
118118

119+
// Subscribe to realtime messages on the channel
120+
subscribeToRealtime("my-first-push-channel")
121+
119122
return true
120123
}
121124
}
@@ -182,19 +185,12 @@ func deactivatePush() {
182185
print("Deactivating push notifications...")
183186
}
184187

185-
/// Get current device registration details
186-
func getDeviceDetails(_ callback: @escaping (ARTDeviceDetails?, ARTErrorInfo?) -> ()) {
187-
realtime.push.admin.deviceRegistrations.get(realtime.device.id, callback: callback)
188-
}
189-
190188
// MARK: - ARTPushRegistererDelegate Methods
191189

192190
func didActivateAblyPush(_ error: ARTErrorInfo?) {
193191
print("Push activation: \(error?.localizedDescription ?? "Success")")
194-
if let defaultDeviceToken {
195-
// Notify UI about activation result
196-
activatePushCallback?(defaultDeviceToken, error)
197-
}
192+
// Notify UI about activation result
193+
activatePushCallback?(realtime.device.id, error)
198194
}
199195

200196
func didDeactivateAblyPush(_ error: ARTErrorInfo?) {
@@ -247,6 +243,14 @@ To subscribe your device to a channel so it can receive channel-based push notif
247243
```swift
248244
// MARK: - Subscribe to Channels
249245

246+
/// Subscribe to realtime messages on a channel
247+
func subscribeToRealtime(_ channelName: String) {
248+
let channel = realtime.channels.get(channelName)
249+
channel.subscribe { message in
250+
print("Received message: \(message.name ?? "") - \(String(describing: message.data))")
251+
}
252+
}
253+
250254
/// Subscribe to a channel for push notifications
251255
func subscribeToChannel(_ channelName: String) {
252256
let channel = realtime.channels.get(channelName)
@@ -308,7 +312,6 @@ struct ContentView: View {
308312
let appDelegate: AppDelegate
309313

310314
@State private var statusMessage = "Ready to start"
311-
@State private var selectedChannel = "my-first-push-channel"
312315

313316
var body: some View {
314317
NavigationStack {
@@ -324,7 +327,7 @@ struct ContentView: View {
324327
SetupPushSection(appDelegate: appDelegate, statusMessage: $statusMessage)
325328

326329
// Subscribe to Channel Section
327-
ChannelSection(appDelegate: appDelegate, statusMessage: $statusMessage, selectedChannel: $selectedChannel)
330+
ChannelSection(appDelegate: appDelegate, statusMessage: $statusMessage)
328331
}
329332
.padding()
330333
}
@@ -378,11 +381,11 @@ struct SetupPushSection: View {
378381

379382
VStack(spacing: 10) {
380383
Button(action: {
381-
appDelegate.activatePushNotifications { deviceToken, error in
384+
appDelegate.activatePushNotifications { deviceId, error in
382385
if let error = error {
383386
statusMessage = "Push activation failed: \(error.localizedDescription)"
384387
} else {
385-
statusMessage = "Push notifications activated with device token: \(deviceToken)"
388+
statusMessage = "Push activated. Device ID: \(deviceId)"
386389
}
387390
}
388391
statusMessage = "Activating push notifications..."
@@ -412,32 +415,6 @@ struct SetupPushSection: View {
412415
.foregroundStyle(.white)
413416
.cornerRadius(8)
414417
}
415-
416-
Button(action: {
417-
appDelegate.getDeviceDetails { details, error in
418-
if let details = details {
419-
print("Device details: \(details)")
420-
statusMessage = """
421-
Device ID: \(details.id)
422-
Client ID: \(details.clientId ?? "n/a")
423-
Platform: \(details.platform)
424-
Form Factor: \(details.formFactor)
425-
"""
426-
} else {
427-
statusMessage = "Failed to retrieve device details: \(error?.localizedDescription ?? "Unknown error")"
428-
}
429-
}
430-
}) {
431-
HStack {
432-
Image(systemName: "info.circle.fill")
433-
Text("Get Device Details")
434-
}
435-
.frame(maxWidth: .infinity)
436-
.padding()
437-
.background(Color.blue)
438-
.foregroundStyle(.white)
439-
.cornerRadius(8)
440-
}
441418
}
442419
}
443420
.padding()
@@ -449,72 +426,43 @@ struct SetupPushSection: View {
449426

450427
// MARK: - Channel Section
451428

452-
// Helper to get a user-friendly title for a channel
453-
func titleForChannel(_ name: String) -> String {
454-
let titles = [
455-
"my-first-push-channel": "Channel 1",
456-
"my-first-push-channel-2": "Channel 2"
457-
]
458-
return titles[name] ?? name
459-
}
460-
461429
struct ChannelSection: View {
462430
let appDelegate: AppDelegate
463431
@Binding var statusMessage: String
464-
@Binding var selectedChannel: String
432+
private let channelName = "my-first-push-channel"
465433

466434
var body: some View {
467435
VStack(alignment: .leading, spacing: 12) {
468436
Text("Channel Subscription")
469437
.font(.headline)
470438

471439
VStack(spacing: 10) {
472-
HStack(spacing: 8) {
473-
Menu {
474-
Button(titleForChannel("my-first-push-channel")) {
475-
selectedChannel = "my-first-push-channel"
476-
}
477-
Button(titleForChannel("my-first-push-channel-2")) {
478-
selectedChannel = "my-first-push-channel-2"
479-
}
480-
} label: {
481-
HStack {
482-
Image(systemName: "line.3.horizontal.decrease.circle")
483-
Text(titleForChannel(selectedChannel))
484-
}
485-
.frame(maxWidth: .infinity)
486-
.padding()
487-
.background(Color.gray.opacity(0.2))
488-
.cornerRadius(8)
489-
}
490-
491-
Button(action: {
492-
appDelegate.subscribeToChannel(selectedChannel)
493-
statusMessage = "Subscribed to: \(titleForChannel(selectedChannel))"
494-
}) {
495-
HStack {
496-
Image(systemName: "checkmark.circle.fill")
497-
Text("Subscribe")
498-
}
499-
.frame(maxWidth: .infinity)
500-
.padding()
501-
.background(Color.indigo)
502-
.foregroundStyle(.white)
503-
.cornerRadius(8)
440+
Button(action: {
441+
appDelegate.subscribeToChannel(channelName)
442+
statusMessage = "Subscribed to: \(channelName)"
443+
}) {
444+
HStack {
445+
Image(systemName: "checkmark.circle.fill")
446+
Text("Subscribe to Channel")
504447
}
448+
.frame(maxWidth: .infinity)
449+
.padding()
450+
.background(Color.purple)
451+
.foregroundStyle(.white)
452+
.cornerRadius(8)
505453
}
506454

507455
Button(action: {
508-
appDelegate.unsubscribeFromChannel(selectedChannel)
509-
statusMessage = "Unsubscribed from: \(titleForChannel(selectedChannel))"
456+
appDelegate.unsubscribeFromChannel(channelName)
457+
statusMessage = "Unsubscribed from: \(channelName)"
510458
}) {
511459
HStack {
512460
Image(systemName: "xmark.circle.fill")
513-
Text("Unsubscribe from \(titleForChannel(selectedChannel))")
461+
Text("Unsubscribe from Channel")
514462
}
515463
.frame(maxWidth: .infinity)
516464
.padding()
517-
.background(Color.gray)
465+
.background(Color.orange)
518466
.foregroundStyle(.white)
519467
.cornerRadius(8)
520468
}
@@ -534,7 +482,7 @@ push notifications and subscribe to channels.
534482

535483
## Step 5: Publish a push notification <a id="step-5"/>
536484

537-
Tap **Activate Push** and wait until the status message displays the received device token. You can get your device ID from the **Get Device Details** button (don't confuse it with the device token).
485+
Tap **Activate Push** and wait until the status message displays your device ID.
538486

539487
### Publish directly to your device <a id="step-5-direct"/>
540488

@@ -551,7 +499,7 @@ ably push publish --client-id push-tutorial-client \
551499

552500
### Publish via a channel <a id="step-5-channel"/>
553501

554-
Subscribe to "Channel 1" in the UI, then publish a push notification to the channel using the [Ably CLI](/docs/platform/tools/cli):
502+
Tap **Subscribe to Channel** in the UI, then publish a push notification to the channel using the [Ably CLI](/docs/platform/tools/cli):
555503

556504
<Code fixed="true">
557505
```shell
@@ -793,6 +741,8 @@ Read how to obtain the `AUTHENTICATION_TOKEN` on [Apple Developer Portal](https:
793741

794742
Verify that your app receives and handles location push notifications correctly in the `LocationPushService` class.
795743

744+
![Screenshot of the Swift push tutorial application with location pushes](../../../../images/content/screenshots/getting-started/apns-swift-getting-started-guide-2.png)
745+
796746
## Next steps <a id="next-steps"/>
797747

798748
* Check the [push example](https://github.com/ably/ably-cocoa/tree/main/Examples/AblyPush)

0 commit comments

Comments
 (0)