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

Updated Content #699

Open
majidsaleem105 opened this issue Jun 20, 2023 · 16 comments
Open

Updated Content #699

majidsaleem105 opened this issue Jun 20, 2023 · 16 comments

Comments

@majidsaleem105
Copy link

Hi @gavirawson-apple,

We're using the CareKit 2.0 version and facing a strange issue. If we open the app, use it for a while to complete some of the tasks, and leave it open in the background. Now, suppose we do not open the app until midnight, and the date changes. If we open the app the next morning, it shows the events from the previous date instead of today's event. It shows the completed event from yesterday instead of incomplete events for today.

We have implemented the pull-down refresh feature to sync the tasks with the server and reload the screen, but it doesn't help to bring the events of the current day. We have to swipe out of the app and open it again to see today's events/tasks.

Can you please advise us on this?
How can we resolve this problem?

Thank You,

  • Majid S.
@gavirawson-apple
Copy link
Collaborator

Hey @majidsaleem105, I'll ask a few questions to get a better sense of the setup in your app -

  • How and when are you generating the event query?
  • Are you using a pre-packaged CareKit view controller or custom code?
  • Can you share the code you're using to fetch and display the tasks?

@majidsaleem105
Copy link
Author

Hey @gavirawson-apple,

Q: How and when are you generating the event query?
A: The function override func dailyPageViewController is used to build the home screen. Here is the query that fetches data:

var query = OCKTaskQuery(for: date)
query.excludesTasksWithNoEvents = true
storeManager.store.fetchAnyTasks(query: query, callbackQueue: .main) { [self] result in
// Custom logic
}

Q: Are you using a pre-packaged CareKit view controller or custom code?
A: We are using pre-packed with custom code.

Q: Can you share the code you're using to fetch and display the tasks?
A: You can find the code here. https://gist.github.com/majidsaleem105/588ee96e0fa373ad49ddcb38ac63c302

Please let me know if you any additional information.

Thanks,

  • Majid S.

@majidsaleem105
Copy link
Author

Hey @gavirawson-apple,

Any suggestions?
Would you happen to need any more information?

Thanks,

  • Majid S.

@majidsaleem105
Copy link
Author

Hey @gavirawson-apple,

Please guide us on how we can resolve this issue.

Thanks,

  • Majid S.

@gavirawson-apple
Copy link
Collaborator

@majidsaleem105 thanks for the additional info. It looks to me like the pull to refresh feature implemented in the OCKDailyPageViewController will reload the tasks for the currently selected date. I don't think it will select a new date once midnight passes, and then load the tasks for that new date. Are you expecting that behavior?

You can likely confirm if that's the underlying issue by looking at the calendar on the top of the OCKDailyPageViewController. After midnight passes, is the old day still selected?

@majidsaleem105
Copy link
Author

Thanks, @gavirawson-apple, for your reply.

That's correct. We want to use the new date after the midnight passes.

Also, the calendar shows the old day selected after midnight if we don't swipe out of the app and bring it from the opened apps from the background.

I'll go ahead and confirm the selected day again and let you know.

Thank You.

  • Majid S.

@gavirawson-apple
Copy link
Collaborator

As long as the correct tasks for the selected day are shown, there might not be a bug lurking here. If the displayed tasks do not correspond to the selected day, there's certainly a bug.

If you'd like to refresh the selected date after midnight passes, I'd recommend hooking into this notification. A notification will get published around when midnight passes, and you can then go and refresh the selected date to match the current date.

@majidsaleem105
Copy link
Author

Hey @gavirawson-apple,

I've verified that the top calendar shows yesterday as selected after midnight passes.
Also, I used the significantTimeChangeNotification notification to get the updated date, but it didn't help. I might have used it inaccurately.

I used the following line of code in the viewDidLoad function in the CareViewController:
NotificationCenter.default.addObserver(self, selector: #selector(dayChanged), name: UIApplication.significantTimeChangeNotification, object: nil)

then @objc func dayChanged(_ notification: Notification) to reload the table content.

This way, it simply refreshes the screen with the old date instead of the new date.

Can you guide me if I'm using it inaccurately?

Kind Regards,

  • Majid S.

@gavirawson-apple
Copy link
Collaborator

What does you implementation of dayChanged(notification:) look like? I imagine inside of it you're going to need to call OCKDailyPageViewController.selectDate(date:animated:)

@majidsaleem105
Copy link
Author

@gavirawson-apple

After making your suggested changes, dayChanged function will look like this:

@objc func dayChanged(_ notification: Notification) {
OCKDailyPageViewController(storeManager: self.storeManager).selectDate(Date(), animated: false)
}

Am I using it in the correct way?

@gavirawson-apple
Copy link
Collaborator

Looks right to me! Does that fix your issue?

@majidsaleem105
Copy link
Author

majidsaleem105 commented Aug 1, 2023

Thanks, @gavirawson-apple but it didn't fix my problem. It still shows content from the last day.

@gavirawson-apple
Copy link
Collaborator

I've tried this out in the CareKitSample app and it seems to be working. Try cloning that project and opening CareViewController. Add this new code to refresh the view controller when midnight passes:

override func viewDidLoad() {
    super.viewDidLoad()

    let changeNotificationName = UIApplication.significantTimeChangeNotification
    NotificationCenter.default.addObserver(self, selector: #selector(selectCurrentDate), name: changeNotificationName, object: nil)

    // ...
}

@objc private func selectCurrentDate() {
    selectDate(Date(), animated: true)
}

I'm not exactly sure why it's not working in your app. Is the code set up in a similar way as the snippet above? Are there any major differences that may be interfering here?

@gavirawson-apple
Copy link
Collaborator

Hey @majidsaleem105, did this solve your issue or are you still hitting a problem?

@majidsaleem105
Copy link
Author

Hey @gavirawson-apple,

I am sorry for the delayed reply. I was super busy with other stuff and couldn't spare time to validate this yet. I'll try this and keep you posted.

Thanks a lot for your time and for sharing this sample.
Kind Regards,

  • Majid S.

@gavirawson-apple
Copy link
Collaborator

No problem at all! Take your time, just wanted to check in. We're here if you need us.

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

No branches or pull requests

2 participants