Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions Modules/Sources/Networking/Remote/DevicesRemote.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,11 @@ public class DevicesRemote: Remote {
/// - device: APNS Device to be registered.
/// - applicationId: App ID.
/// - applicationVersion: App Version.
/// - defaultStoreID: Active Store ID.
/// - completion: Closure to be executed on completion.
///
public func registerDevice(device: APNSDevice,
applicationId: String,
applicationVersion: String,
defaultStoreID: Int64,
completion: @escaping (DotcomDevice?, Error?) -> Void) {
var parameters = [
ParameterKeys.applicationId: applicationId,
Expand All @@ -27,7 +25,6 @@ public class DevicesRemote: Remote {
ParameterKeys.deviceModel: device.model,
ParameterKeys.deviceName: device.name,
ParameterKeys.deviceOSVersion: device.iOSVersion,
ParameterKeys.defaultStoreID: ""
]

if let deviceUUID = device.identifierForVendor {
Expand Down Expand Up @@ -84,6 +81,5 @@ private extension DevicesRemote {
static let deviceName = "device_name"
static let deviceOSVersion = "os_version"
static let deviceUUID = "device_uuid"
static let defaultStoreID = "selected_blog_id"
}
}
1 change: 0 additions & 1 deletion Modules/Sources/Yosemite/Actions/NotificationAction.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ public enum NotificationAction: Action {
case registerDevice(device: APNSDevice,
applicationId: String,
applicationVersion: String,
defaultStoreID: Int64,
onCompletion: (DotcomDevice?, Error?) -> Void)

/// Unregisters a device for Push Notifications Delivery.
Expand Down
4 changes: 0 additions & 4 deletions Modules/Sources/Yosemite/Stores/NotificationStore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,10 @@ public class NotificationStore: Store {
case .registerDevice(let device,
let applicationId,
let applicationVersion,
let defaultStoreID,
let onCompletion):
registerDevice(device: device,
applicationId: applicationId,
applicationVersion: applicationVersion,
defaultStoreID: defaultStoreID,
onCompletion: onCompletion)
case .synchronizeNotifications(let onCompletion):
synchronizeNotifications(onCompletion: onCompletion)
Expand Down Expand Up @@ -72,12 +70,10 @@ private extension NotificationStore {
func registerDevice(device: APNSDevice,
applicationId: String,
applicationVersion: String,
defaultStoreID: Int64,
onCompletion: @escaping (DotcomDevice?, Error?) -> Void) {
devicesRemote.registerDevice(device: device,
applicationId: applicationId,
applicationVersion: applicationVersion,
defaultStoreID: defaultStoreID,
completion: onCompletion)
}

Expand Down
25 changes: 2 additions & 23 deletions Modules/Tests/NetworkingTests/Remote/DevicesRemoteTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ final class DevicesRemoteTests: XCTestCase {

remote.registerDevice(device: Parameters.appleDevice,
applicationId: Parameters.applicationId,
applicationVersion: Parameters.applicationVersion,
defaultStoreID: Parameters.defaultStoreID) { (settings, error) in
applicationVersion: Parameters.applicationVersion) { (settings, error) in

XCTAssertNil(error)
XCTAssertNotNil(settings)
Expand All @@ -41,24 +40,6 @@ final class DevicesRemoteTests: XCTestCase {
wait(for: [expectation], timeout: Constants.expectationTimeout)
}

/// Verifies that registerDevice sets the `selected_blog_id` parameter to empty string.
///
func test_registerDevice_sets_selected_blog_id_to_empty_string() throws {
// Given
let remote = DevicesRemote(network: network)

// When
remote.registerDevice(device: Parameters.appleDevice,
applicationId: Parameters.applicationId,
applicationVersion: Parameters.applicationVersion,
defaultStoreID: Parameters.defaultStoreID) { (_, _) in }

// Then
let queryParameters = try XCTUnwrap(network.queryParameters)
let expectedParam = "selected_blog_id="
XCTAssertTrue(queryParameters.contains(expectedParam), "Expected to have param: \(expectedParam)")
}

/// Verifies that registerDevice parses a "Failure" Backend Response.
///
func test_registerDevice_parses_general_failure_response() {
Expand All @@ -69,8 +50,7 @@ final class DevicesRemoteTests: XCTestCase {

remote.registerDevice(device: Parameters.appleDevice,
applicationId: Parameters.applicationId,
applicationVersion: Parameters.applicationVersion,
defaultStoreID: Parameters.defaultStoreID) { (settings, error) in
applicationVersion: Parameters.applicationVersion) { (settings, error) in

XCTAssertNotNil(error)
XCTAssertNil(settings)
Expand Down Expand Up @@ -124,6 +104,5 @@ private enum Parameters {
identifierForVendor: "1234")
static let applicationId = "9"
static let applicationVersion = "99"
static let defaultStoreID: Int64 = 1234
static let dotcomDeviceID = "1234"
}
12 changes: 2 additions & 10 deletions Modules/Tests/YosemiteTests/Stores/NotificationStoreTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -364,8 +364,7 @@ class NotificationStoreTests: XCTestCase {
let (device, error): (DotcomDevice?, Error?) = waitFor { promise in
let action = NotificationAction.registerDevice(device: self.sampleAPNSDevice(),
applicationId: self.sampleApplicationID,
applicationVersion: self.sampleApplicationVersion,
defaultStoreID: self.sampleDefaultStoreID) { (device, error) in
applicationVersion: self.sampleApplicationVersion) { (device, error) in
promise((device, error))
}
noteStore.onAction(action)
Expand All @@ -389,8 +388,7 @@ class NotificationStoreTests: XCTestCase {
let (device, error): (DotcomDevice?, Error?) = waitFor { promise in
let action = NotificationAction.registerDevice(device: self.sampleAPNSDevice(),
applicationId: self.sampleApplicationID,
applicationVersion: self.sampleApplicationVersion,
defaultStoreID: self.sampleDefaultStoreID) { (device, error) in
applicationVersion: self.sampleApplicationVersion) { (device, error) in
promise((device, error))
}
noteStore.onAction(action)
Expand Down Expand Up @@ -490,12 +488,6 @@ private extension NotificationStoreTests {
return "1234"
}

/// Returns a sample Default Store ID
///
var sampleDefaultStoreID: Int64 {
return 1234
}

/// Returns a sample Apple Device
///
func sampleAPNSDevice() -> APNSDevice {
Expand Down
1 change: 1 addition & 0 deletions RELEASE-NOTES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
23.9
-----
- [Internal] Moved the request for push notification authorization after login [https://github.com/woocommerce/woocommerce-ios/pull/16428]
- [Internal] Cleaned up logic for push notification token registration [https://github.com/woocommerce/woocommerce-ios/pull/16434]
- [*] Fixed possible sync issue in POS (https://github.com/woocommerce/woocommerce-ios/pull/16423)

23.8
Expand Down
6 changes: 1 addition & 5 deletions WooCommerce/Classes/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
}

func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
guard let defaultStoreID = ServiceLocator.stores.sessionManager.defaultStoreID else {
return
}

ServiceLocator.pushNotesManager.registerDeviceToken(with: deviceToken, defaultStoreID: defaultStoreID)
ServiceLocator.pushNotesManager.registerDeviceToken(with: deviceToken)
}

func application(_ application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: Error) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ extension PushNotificationsManager {
/// - tokenData: APNS's Token Data
/// - defaultStoreID: Default WooCommerce Store ID
///
func registerDeviceToken(with tokenData: Data, defaultStoreID: Int64) {
func registerDeviceToken(with tokenData: Data) {
let newToken = tokenData.hexString

if let _ = deviceToken, deviceToken != newToken {
Expand All @@ -231,7 +231,7 @@ extension PushNotificationsManager {
deviceToken = newToken

// Register in the Dotcom's Infrastructure
registerDotcomDevice(with: newToken, defaultStoreID: defaultStoreID) { (device, error) in
registerDotcomDevice(with: newToken) { (device, error) in
guard let deviceID = device?.deviceID else {
DDLogError("⛔️ Dotcom Push Notifications Registration Failure: \(error.debugDescription)")
return
Expand Down Expand Up @@ -556,12 +556,11 @@ private extension PushNotificationsManager {

/// Registers an APNS DeviceToken in the WordPress.com backend.
///
func registerDotcomDevice(with deviceToken: String, defaultStoreID: Int64, onCompletion: @escaping (DotcomDevice?, Error?) -> Void) {
func registerDotcomDevice(with deviceToken: String, onCompletion: @escaping (DotcomDevice?, Error?) -> Void) {
let device = APNSDevice(deviceToken: deviceToken)
let action = NotificationAction.registerDevice(device: device,
applicationId: WooConstants.pushApplicationID,
applicationVersion: Bundle.main.version,
defaultStoreID: defaultStoreID,
onCompletion: onCompletion)
stores.dispatch(action)
}
Expand Down
3 changes: 1 addition & 2 deletions WooCommerce/Classes/ServiceLocator/PushNotesManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,8 @@ protocol PushNotesManager {
///
/// - Parameters:
/// - tokenData: APNS's Token Data
/// - defaultStoreID: Default WooCommerce Store ID
///
func registerDeviceToken(with tokenData: Data, defaultStoreID: Int64)
func registerDeviceToken(with tokenData: Data)

/// Handles a remote push notification payload when the app is in the background.
/// - Parameter userInfo: Push notification payload.
Expand Down
1 change: 0 additions & 1 deletion WooCommerce/Classes/Yosemite/DefaultStoresManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,6 @@ class DefaultStoresManager: StoresManager {
sessionManager.deleteApplicationPassword(locally: true)
ServiceLocator.analytics.refreshUserData()
ZendeskProvider.shared.reset()
ServiceLocator.pushNotesManager.unregisterForRemoteNotifications {}
}

/// Fully deauthenticates the user, if needed.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ final class MockPushNotificationsManager: PushNotesManager {

}

func registerDeviceToken(with tokenData: Data, defaultStoreID: Int64) {
func registerDeviceToken(with tokenData: Data) {

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,24 +174,6 @@ final class PushNotificationsManagerTests: XCTestCase {
XCTAssertFalse(defaults.containsObject(forKey: .deviceToken))
}

/// Verifies that `registerDevice` effectively dispatches a `registerDevice` Action.
///
func testRegisterForRemoteNotificationsDispatchesRegisterDeviceAction() {
guard let tokenAsData = Sample.deviceToken.data(using: .utf8) else {
XCTFail()
return
}

manager.registerDeviceToken(with: tokenAsData, defaultStoreID: Sample.defaultStoreID)

guard case let .registerDevice(_, _, _, storeID, _) = storesManager.receivedActions.first as! NotificationAction else {
XCTFail()
return
}

XCTAssertEqual(storeID, Sample.defaultStoreID)
}


/// Verifies that `registerDeviceToken` effectively stores the Device Token.
///
Expand All @@ -202,7 +184,7 @@ final class PushNotificationsManagerTests: XCTestCase {
}

XCTAssertFalse(defaults.containsObject(forKey: .deviceToken))
manager.registerDeviceToken(with: tokenAsData, defaultStoreID: Sample.defaultStoreID)
manager.registerDeviceToken(with: tokenAsData)
XCTAssertTrue(defaults.containsObject(forKey: .deviceToken))
}

Expand Down Expand Up @@ -708,10 +690,6 @@ private struct Sample {
///
static let deviceToken = "4fa963db2cfc824b0d67740ed2b1c0b472cce8eafcb82184905361eb88be55b9"

/// Sample StoreID
///
static let defaultStoreID: Int64 = 9999

/// UserDefaults Suite Name
///
static let defaultSuiteName = "PushNotificationsTests"
Expand Down