Skip to content

Commit

Permalink
fix: add unsubscribed status, remove clearing device token on change …
Browse files Browse the repository at this point in the history
…events logic, add badge clearing on app open (#9)

Co-authored-by: Alan Charles <acharles@twilio.com>
  • Loading branch information
alanjcharles and alanjcharles authored Aug 17, 2023
1 parent 58bafe9 commit 5c832a6
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Example/BasicExample/BasicExample/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD

func applicationWillEnterForeground(_ application: UIApplication) {

UserDefaults(suiteName: "group.com.segment.twiliopush")?.set(1, forKey: "count"); UIApplication.shared.applicationIconBadgeNumber = 0
UserDefaults(suiteName: "group.com.segment.twiliopush")?.set(1, forKey: "Count"); UIApplication.shared.applicationIconBadgeNumber = 0
}

// MARK: UISceneSession Lifecycle
Expand Down
1 change: 1 addition & 0 deletions Example/BasicExample/BasicExample/SceneDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate {
func sceneWillEnterForeground(_ scene: UIScene) {
// Called as the scene transitions from the background to the foreground.
// Use this method to undo the changes made on entering the background.
UserDefaults(suiteName: "group.com.segment.twiliopush")?.set(1, forKey: "Count"); UIApplication.shared.applicationIconBadgeNumber = 0
}

func sceneDidEnterBackground(_ scene: UIScene) {
Expand Down
13 changes: 7 additions & 6 deletions Sources/TwilioEngage/TwilioEngage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,12 @@ public class TwilioEngage: EventPlugin {
case .notDetermined:
newStatus = .didNotSubscribe
case .denied:
newStatus = .didNotSubscribe
// accounts for user disabling notifications in settings
if currentStatus == .subscribed {
newStatus = .unsubscribed
} else {
newStatus = .didNotSubscribe
}
default:
// These cases are all some version of subscribed.
//case .authorized:
Expand All @@ -97,6 +102,7 @@ public class TwilioEngage: EventPlugin {
UIApplication.shared.registerForRemoteNotifications()
}
}

print("Push Status Changed, old=\(currentStatus), new=\(newStatus)")
self.analytics?.track(name: Events.changed.rawValue)
}
Expand All @@ -111,11 +117,6 @@ public class TwilioEngage: EventPlugin {
// this will succeed if the event name can be used to generate a push event case.
guard Events(rawValue: event.event) != nil else { return event as? T }

// we don't need the device token for status changed events
if Events(rawValue: event.event) == Events.changed {
deviceToken = nil
}

// `messaging_subscription` data type is an array of objects
context[keyPath: KeyPath(Self.contextKey)] = [[
"key": deviceToken,
Expand Down

0 comments on commit 5c832a6

Please sign in to comment.