Skip to content

Commit

Permalink
Improved logging around push notifications
Browse files Browse the repository at this point in the history
  • Loading branch information
kober32 committed Nov 20, 2024
1 parent 7ee8a01 commit 6fb1e9c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
4 changes: 3 additions & 1 deletion WultraMobileTokenSDK/Common/WMTProvisioningUtils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ import Foundation
class WMTProvisioningUtils {

static func getMainProvisioningProfile() -> WMTProvision? {
D.debug("Retrieving embedded provisioning profile from the main bundle.")
guard let filePath = Bundle.main.path(forResource: "embedded", ofType: "mobileprovision") else {
D.debug("Missing embedded provisioning profile in the main bundle.")
D.error("Missing embedded provisioning profile in the main bundle.")
return nil
}
let url = URL(fileURLWithPath: filePath)
Expand Down Expand Up @@ -60,6 +61,7 @@ class WMTProvisioningUtils {
static func parseProvisioningProfilePlist(_ plist: Data) -> WMTProvision? {
do {
let provision = try PropertyListDecoder().decode(WMTProvision.self, from: plist)
D.debug("Successfully parsed provisioning profile (apns env: \(provision.entitlements.apsEnvironment?.rawValue ?? "nil")).")
return provision
} catch let e {
D.error("Failed to parse provisioning profile: \(e)")
Expand Down
19 changes: 16 additions & 3 deletions WultraMobileTokenSDK/Push/Service/WMTPushImpl.swift
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ class WMTPushImpl: WMTPush, WMTService {
payloadEnvironment = nil // no env for FCM
}

D.info("Registering push for \(payloadPlatform.rawValue) platform.")

return registerPush(platform: payloadPlatform, token: payloadToken, environment: payloadEnvironment, completion: completion)
}

Expand Down Expand Up @@ -122,9 +124,20 @@ class WMTPushImpl: WMTPush, WMTService {

private func getPushEnvironment(environment: WMTPushAPNSEnvironment) -> WMTPushRegistrationEnvironment? {
switch environment {
case .development: return .development
case .production: return .production
case .automatic: return WMTProvisioningUtils.getMainProvisioningProfile()?.apnsEnvironment
case .development:
D.info("Using APNS development environment for push notifications.")
return .development
case .production:
D.info("Using APNS production environment for push notifications.")
return .production
case .automatic:
let env = WMTProvisioningUtils.getMainProvisioningProfile()?.apnsEnvironment
if let env {
D.info("Using \(env) environment for push notifications (automatic resolution).")
} else {
D.warning("No APNS environment found in provisioning profile. Server configuration will be used.")
}
return env
}
}
}
Expand Down

0 comments on commit 6fb1e9c

Please sign in to comment.