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      

Hacking with Swift is sponsored by Superwall

SPONSORED Superwall lets you build & test paywalls without shipping updates. Run experiments, offer sales, segment users, update locked features and more at the click of button. Best part? It's FREE for up to 250 conversions / mo and the Superwall team builds out 100% custom paywalls – free of charge.

Learn More

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.