UPGRADE YOUR SKILLS: Learn advanced Swift and SwiftUI on Hacking with Swift+! >>

Day 73 - Project21 - Challenge - Triggering Local Reminder 24hrs later

Forums > 100 Days of Swift

Hi,

I am currently on Day 73 and trying to complete the challenge relating to Project21 - Local Notifications.

I am wondering how i ca change the trigger to cause the notification to occur 24hrs later. The scheduleLocal() function does not take a parameter that i could pass to it to tell it i want the trigger timeInterval to be 86400, so i cannot call it like that from the didReceive funnction.

If i attempt to add a parrameter to do this it then causes the UIBarButton initialiser to present an error that i cannot pass a parameter in the #️⃣selector call as it is a objectiveC fuction.

Any help would be greatly appreciated.

Thanks,

Simon.

4      

I used the stupid way to sort of "achieve" this, which is basically using DispatchQueue.main.asyncAfter() and setting the deadline as .now()+x (with x being whatever seconds needed to pass between the time right now converted in seconds and 86400, which is how many seconds in a day on average..)

Exp: if my alarm was set at 4pm everyday, that pretty much equals to 57600 seconds from midnight. Then i will set the delay in GCD at .now + 28800 ( basically 8 hours later to call scheduleLocal(), and the notification should pop up again at 4pm the next day, as it is 57600 seconds away from midnight)...

But I would love to see if somebody came up with the smarter way LOL. i am stuck on this too.

4      

BUILD THE ULTIMATE PORTFOLIO APP Most Swift tutorials help you solve one specific problem, but in my Ultimate Portfolio App series I show you how to get all the best practices into a single app: architecture, testing, performance, accessibility, localization, project organization, and so much more, all while building a SwiftUI app that works on iOS, macOS and watchOS.

Get it on Hacking with Swift+

Sponsor Hacking with Swift and reach the world's largest Swift community!

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.