Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: sdk wrappers not having device token registered because of application lifecycle #285

Merged
merged 27 commits into from May 12, 2023

Conversation

Shahroz16
Copy link
Contributor

@Shahroz16 Shahroz16 commented Apr 13, 2023

closes: https://github.com/customerio/issues/issues/9641

Complete each step to get your pull request merged in. Learn more about the workflow this project uses.

  • Assign members of your team to review the pull request.
  • Wait for pull request status checks to complete. If there are problems, fix them until you see that all status checks are passing.
  • Wait until the pull request has been reviewed and approved by a teammate
  • After code reviews are approved and you determine this PR is ready to merge, select Squash and Merge button on this screen, leave the title and description to the default values, then merge the PR.

@github-actions
Copy link

github-actions bot commented Apr 13, 2023

Pull request title looks good 👍!

If this pull request gets merged, it will cause a new release of the software. Example: If this project's latest release version is 1.0.0. If this pull request gets merged in, the next release of this project will be 1.0.1. This pull request is not a breaking change.

All merged pull requests will eventually get deployed. But some types of pull requests will trigger a deployment (such as features and bug fixes) while some pull requests will wait to get deployed until a later time.

This project uses a special format for pull requests titles. Expand this section to learn more (expand by clicking the ᐅ symbol on the left side of this sentence)...

This project uses a special format for pull requests titles. Don't worry, it's easy!

This pull request title should be in this format:

<type>: short description of change being made

If your pull request introduces breaking changes to the code, use this format:

<type>!: short description of breaking change

where <type> is one of the following:

  • feat: - A feature is being added or modified by this pull request. Use this if you made any changes to any of the features of the project.

  • fix: - A bug is being fixed by this pull request. Use this if you made any fixes to bugs in the project.

  • docs: - This pull request is making documentation changes, only.

  • refactor: - A change was made that doesn't fix a bug or add a feature.

  • test: - Adds missing tests or fixes broken tests.

  • style: - Changes that do not effect the code (whitespace, linting, formatting, semi-colons, etc)

  • perf: - Changes improve performance of the code.

  • build: - Changes to the build system (maven, npm, gulp, etc)

  • ci: - Changes to the CI build system (Travis, GitHub Actions, Circle, etc)

  • chore: - Other changes to project that don't modify source code or test files.

  • revert: - Reverts a previous commit that was made.

Examples:

feat: edit profile photo
refactor!: remove deprecated v1 endpoints
build: update npm dependencies
style: run formatter 

Need more examples? Want to learn more about this format? Check out the official docs.

Note: If your pull request does multiple things such as adding a feature and makes changes to the CI server and fixes some bugs then you might want to consider splitting this pull request up into multiple smaller pull requests.

@github-actions
Copy link

github-actions bot commented Apr 13, 2023

Hey, there @Shahroz16 👋🤖. I'm a bot here to help you.

⚠️ Pull requests into the branch main typically only allows changes with the types: fix. From the pull request title, the type of change this pull request is trying to complete is: feat. ⚠️

This pull request might still be allowed to be merged. However, you might want to consider make this pull request merge into a different branch other then main.

This project uses a special format for pull requests titles. Expand this section to learn more (expand by clicking the ᐅ symbol on the left side of this sentence)...

This project uses a special format for pull requests titles. Don't worry, it's easy!

This pull request title should be in this format:

<type>: short description of change being made

If your pull request introduces breaking changes to the code, use this format:

<type>!: short description of breaking change

where <type> is one of the following:

  • feat: - A feature is being added or modified by this pull request. Use this if you made any changes to any of the features of the project.

  • fix: - A bug is being fixed by this pull request. Use this if you made any fixes to bugs in the project.

  • docs: - This pull request is making documentation changes, only.

  • refactor: - A change was made that doesn't fix a bug or add a feature.

  • test: - Adds missing tests or fixes broken tests.

  • style: - Changes that do not effect the code (whitespace, linting, formatting, semi-colons, etc)

  • perf: - Changes improve performance of the code.

  • build: - Changes to the build system (maven, npm, gulp, etc)

  • ci: - Changes to the CI build system (Travis, GitHub Actions, Circle, etc)

  • chore: - Other changes to project that don't modify source code or test files.

  • revert: - Reverts a previous commit that was made.

Examples:

feat: edit profile photo
refactor!: remove deprecated v1 endpoints
build: update npm dependencies
style: run formatter 

Need more examples? Want to learn more about this format? Check out the official docs.

Note: If your pull request does multiple things such as adding a feature and makes changes to the CI server and fixes some bugs then you might want to consider splitting this pull request up into multiple smaller pull requests.

@codecov
Copy link

codecov bot commented Apr 13, 2023

Codecov Report

Merging #285 (1a5bffb) into main (8b96ba0) will increase coverage by 57.22%.
The diff coverage is 90.90%.

❗ Current head 1a5bffb differs from pull request most recent head 2cfd1ba. Consider uploading reports for the commit 2cfd1ba to get more accurate results

@@            Coverage Diff            @@
##           main     #285       +/-   ##
=========================================
+ Coverage      0   57.22%   +57.22%     
=========================================
  Files         0      105      +105     
  Lines         0     1225     +1225     
=========================================
+ Hits          0      701      +701     
- Misses        0      524      +524     
Impacted Files Coverage Δ
Sources/MessagingPush/MessagingPush.swift 44.44% <0.00%> (ø)
...ogenerated/AutoDependencyInjection.generated.swift 0.00% <0.00%> (ø)
...ogenerated/AutoDependencyInjection.generated.swift 42.85% <50.00%> (ø)
Sources/Common/DIGraph.swift 85.71% <66.66%> (ø)
Sources/Common/Store/GlobalDataStore.swift 85.71% <100.00%> (ø)
Sources/Common/Util/KeyValueStorage.swift 100.00% <100.00%> (ø)
...ogenerated/AutoDependencyInjection.generated.swift 100.00% <100.00%> (ø)
Sources/Tracking/CustomerIO.swift 72.72% <100.00%> (ø)
...ogenerated/AutoDependencyInjection.generated.swift 90.00% <100.00%> (ø)

... and 96 files with indirect coverage changes

Copy link
Member

@levibostian levibostian left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Assuming that this comment I left is correct, then I approve of this PR.

That comment is important to make sure that FCM behavior is what I am expecting.

public static func initialize() {
MessagingPush.shared.initializeModuleIfSdkInitialized()
}

@available(iOSApplicationExtension, unavailable)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a lot less work in the long-term of putting these functions as top-level in the stacktrace as possible. Example: It's better to put this annotation over initialize() function instead of over all the functions that initialize() calls.

With this in mind, I suggest we move this annotation over the static func initialize() function and see if it works. The Xcode compiler might complain and require us to put it over both functions. But, I think it's worth the time to see if moving it works.

override public func inititlizeModule(diGraph: DIGraph) {
let logger = diGraph.logger
logger.debug("Setting up MessagingPush module...")

logger.info("MessagingPush module setup with SDK")

#if canImport(UIKit)
UIApplication.shared.registerForRemoteNotifications()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest we put a comment over this to specify why this we decided to add this function call.

@levibostian
Copy link
Member

Adding labels to not merge this PR until all CI status checks on this PR runs successfully. This is especially important for the CocoaPods FCM app compiling to run successful for us to test the @available(iOSApplicationExtension, unavailable) annotation use.

@levibostian
Copy link
Member

Update: This PR is still blocked and should not be merged. Shahroz is changing the implementation as the previous solution did not work for FCM.

@Shahroz16 Shahroz16 requested review from levibostian and a team April 19, 2023 10:29
@Shahroz16
Copy link
Contributor Author

@levibostian would appreciate another review here.

Sources/Common/DIGraph.swift Outdated Show resolved Hide resolved
Sources/MessagingPush/MessagingPush.swift Show resolved Hide resolved
private let sdkInitializedUtil: SdkInitializedUtil

// for writing tests
// provide a nil implementation if you want `sdkInitializedUtil` logic to run and real instance of implementation to run in tests
public init(implementation: ImplementationClass?, sdkInitializedUtil: SdkInitializedUtil) {
public init(implementation: ImplementationClass?, globalDataStore: GlobalDataStore, sdkInitializedUtil: SdkInitializedUtil) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does globalDataStore need to be part of this init function and class?

Since I don't see this class using this dependency, I would prefer we don't keep an instance of it in the class.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MessagingPush is a singleton class. So to make it injectable, and testable I think this was the ideal way. But I might not be fully integrated with the iOS structure. So if there is any other way I can make it injectable in MessagingPush class?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe if you modify the constructor of MessagingPush to something like this:

public class MessagingPush: ModuleTopLevelObject<MessagingPushInstance>, MessagingPushInstance {
    @Atomic public private(set) static var shared = MessagingPush()
	private let globalDataStore: GlobalDataStore

    // testing constructor
    override internal init(implementation: MessagingPushInstance?, globalDataStore: GlobalDataStore, sdkInitializedUtil: SdkInitializedUtil) {
        super.init(implementation: implementation, sdkInitializedUtil: sdkInitializedUtil)
		self.globalDataStore = globalDataStore
    }

Then you wouldn't need to include globalDataStore in this ModuleTopLevelObject class.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think that will work, a subclass constructor cannot have more parameters than its superclass constructor.
It will return Initializer does not override a designated initializer from its superclass

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am trying something out in Xcode right now. I'll update this comment or push a commit if I find something that will work.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Found a solution.

As always, we can revert this commit if we don't like the solution.

Otherwise, let's resolve this conversation.

@levibostian levibostian changed the title feat: fetch token on SDK reinitialization fix: SDK wrappers not having device token registered because of application lifecycle Apr 19, 2023
@levibostian
Copy link
Member

Changed title of PR because I believe this is a bug fix and not a feature.

Of course, if anyone believes this is not a bug fix, change the title to suggest something different.

@Shahroz16 Shahroz16 changed the title fix: SDK wrappers not having device token registered because of application lifecycle fix: sdk wrappers not having device token registered because of application lifecycle Apr 19, 2023
@Shahroz16
Copy link
Contributor Author

@levibostian could use a re-review here after the merge. I don't like the fact we are using sdkConfig for the KeyValueStorage and internally just using siteID. But i didn't make the change here, because you specifically removed it so wanted to have your opinion first. Would do it in a separate PR.

@Shahroz16 Shahroz16 merged commit da7fc51 into main May 12, 2023
6 of 7 checks passed
@Shahroz16 Shahroz16 deleted the shahroz-old-token-fix branch May 12, 2023 07:03
github-actions bot pushed a commit that referenced this pull request May 12, 2023
### [2.5.1](2.5.0...2.5.1) (2023-05-12)

### Bug Fixes

* sdk wrappers not having device token registered because of application lifecycle ([#285](#285)) ([da7fc51](da7fc51))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants