Skip to content

Commit 5bd9ef3

Browse files
authored
Merge pull request #7 from messagebird/feat/example-add-subscribedPush
example: add subscribedPush
2 parents 7cc9c20 + 0dd6c0e commit 5bd9ef3

File tree

3 files changed

+33
-24
lines changed

3 files changed

+33
-24
lines changed

Examples/PushNotificationsExample/PushNotificationsExample/AppDelegate.swift

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,31 +5,34 @@
55
// Created by Meena Alfons on 13/12/2023.
66
//
77

8-
import os
8+
import BirdKit
99
import Foundation
1010
import UIKit
11-
12-
import BirdKit
11+
import os
1312

1413
class AppDelegate: NSObject, UIApplicationDelegate {
15-
14+
1615
static var bird: Bird!
1716
static let logger = Logger(subsystem: Bundle.main.bundleIdentifier!, category: "AppDelegate")
18-
19-
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {
17+
18+
func application(
19+
_ application: UIApplication,
20+
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? = nil
21+
) -> Bool {
2022
do {
2123
Self.bird = try Bird()
2224
} catch {
2325
Self.logger.info("failed to create bird \(error)")
2426
}
25-
27+
2628
UNUserNotificationCenter.current().delegate = self
2729
return true
2830
}
29-
31+
3032
// This method will be called from Button "Ask for notifications permission"
3133
static func requestNotificationsPermission() {
32-
UNUserNotificationCenter.current().requestAuthorization(options:[.badge, .alert, .sound]) { granted, error in
34+
UNUserNotificationCenter.current().requestAuthorization(options: [.badge, .alert, .sound]) {
35+
granted, error in
3336
guard granted else {
3437
self.logger.log("Notification permission is not gratned")
3538
return
@@ -40,35 +43,38 @@ class AppDelegate: NSObject, UIApplicationDelegate {
4043
}
4144

4245
}
43-
46+
4447
func application(
4548
_ application: UIApplication,
4649
didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data
4750
) {
4851
Self.bird.notifications.registerDevice(deviceToken: deviceToken)
49-
52+
5053
Self.logger.log("APNS token: \(deviceToken.map { String(format: "%02x", $0) }.joined())")
5154
}
52-
53-
func application(_ application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: Error) {
55+
56+
func application(
57+
_ application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: Error
58+
) {
5459
Self.logger.log(#function)
5560
}
56-
57-
61+
5862
func application(
5963
_ application: UIApplication,
6064
didReceiveRemoteNotification userInfo: [AnyHashable: Any],
6165
fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void
6266
) {
63-
Self.bird.notifications.handleBackgroundNotification(userInfo: userInfo, completionHandler: completionHandler)
67+
Self.bird.notifications.handleBackgroundNotification(
68+
userInfo: userInfo, completionHandler: completionHandler)
6469
}
6570
}
6671

6772
extension AppDelegate: UNUserNotificationCenterDelegate {
6873
func userNotificationCenter(
6974
_ center: UNUserNotificationCenter,
7075
willPresent notification: UNNotification,
71-
withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void
76+
withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) ->
77+
Void
7278
) {
7379
Self.logger.log(#function)
7480
let options = Self.bird.notifications.willPresentNotification(notification)

Examples/PushNotificationsExample/PushNotificationsExample/ContentView.swift

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
// Created by Meena Alfons on 12/12/2023.
66
//
77

8-
import SwiftUI
98
import BirdKit
9+
import SwiftUI
1010

1111
struct ContentView: View {
1212
@State var sourceUrl = ""
@@ -16,7 +16,7 @@ struct ContentView: View {
1616
if sourceUrl != "" {
1717
Text("Opened from \(sourceUrl)")
1818
}
19-
19+
2020
let signedIdentity = "change-me-with-sample-signed-identity"
2121
Text("Push notifications")
2222
Button("Ask for notifications permission") {
@@ -29,7 +29,8 @@ struct ContentView: View {
2929
)
3030
}
3131
Button("Set Signed Identity") {
32-
let signedIdentity = "change-me-with-sample-signed-identity"
32+
let signedIdentity =
33+
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCIsImtpZCI6Im1ybjp2MTphcHBsaWNhdGlvbjppZGVudGl0eS1jbGFpbXMtaXNzdWVyOjAxZWNlODAxLWVmNTctNGQwNC1hZGFlLWJjN2U0YWQwOGFmZS8yZmQ5NTdlOS1jNTQwLTRhM2UtYjA5My0wZWE5NmU3NDY1ZjY6MSJ9.eyJpZGVudGlmaWVycyI6W3sia2V5IjoiZW1haWxhZGRyZXNzIiwidmFsdWUiOiJtZWVuYS50ZXN0MkBlbWFpbC5jb20ifV19.in94rLJe1X_7MejgnmV8f284Z8YPxRZcJV8LG5cTbVk"
3334
AppDelegate.bird?.contact.identify(
3435
signedIdentity: signedIdentity
3536
)
@@ -40,10 +41,12 @@ struct ContentView: View {
4041
}
4142
Text("Contact")
4243
Button("Put Attributes") {
43-
let attributes = BirdKit.Attributes().put("displayName", "iOS: push notifications example")
44-
AppDelegate.bird?.contact.putAttributes(attributes: attributes )
44+
let attributes = BirdKit.Attributes()
45+
.put("displayName", "iOS: push notifications example")
46+
.put("subscribedPush", true)
47+
AppDelegate.bird?.contact.putAttributes(attributes: attributes)
4548
}
46-
49+
4750
}
4851
.padding()
4952
.onOpenURL(perform: { url in

Examples/PushNotificationsExample/PushNotificationsExample/PushNotificationsExampleApp.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import SwiftUI
1010
@main
1111
struct PushNotificationsExampleApp: App {
1212
@UIApplicationDelegateAdaptor(AppDelegate.self) var appDelegate
13-
13+
1414
var body: some Scene {
1515
WindowGroup {
1616
ContentView()

0 commit comments

Comments
 (0)