diff --git a/Example/BasicExample/BasicExample/AppDelegate.swift b/Example/BasicExample/BasicExample/AppDelegate.swift index f6fd77f..ed9991d 100644 --- a/Example/BasicExample/BasicExample/AppDelegate.swift +++ b/Example/BasicExample/BasicExample/AppDelegate.swift @@ -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 diff --git a/Example/BasicExample/BasicExample/SceneDelegate.swift b/Example/BasicExample/BasicExample/SceneDelegate.swift index b80cbcf..dbf0be5 100644 --- a/Example/BasicExample/BasicExample/SceneDelegate.swift +++ b/Example/BasicExample/BasicExample/SceneDelegate.swift @@ -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) { diff --git a/Sources/TwilioEngage/TwilioEngage.swift b/Sources/TwilioEngage/TwilioEngage.swift index 4c9f7bd..70bfec0 100644 --- a/Sources/TwilioEngage/TwilioEngage.swift +++ b/Sources/TwilioEngage/TwilioEngage.swift @@ -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: @@ -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) } @@ -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,